CCCID/CHUID refactoring
- Move generate methods to the appropriate static types - Remove redundant name prefixes (Rust [RFC#356]) [RFC#356]: https://github.com/rust-lang/rfcs/pull/356
This commit is contained in:
+15
-13
@@ -48,27 +48,29 @@ const CCC_TMPL: &[u8] = &[
|
||||
0x00, 0xfe, 0x00,
|
||||
];
|
||||
|
||||
/// Cardholder Capability Container (CCC) Identifier card ID
|
||||
/// Cardholder Capability Container (CCC) Identifier Card ID
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct CccCardId(pub [u8; YKPIV_CCCID_SIZE]);
|
||||
pub struct CardId(pub [u8; YKPIV_CCCID_SIZE]);
|
||||
|
||||
impl CardId {
|
||||
/// Generate a random CCC Card ID
|
||||
pub fn generate() -> Result<Self, Error> {
|
||||
let mut id = [0u8; YKPIV_CCCID_SIZE];
|
||||
getrandom(&mut id).map_err(|_| Error::RandomnessError)?;
|
||||
Ok(Self(id))
|
||||
}
|
||||
}
|
||||
|
||||
/// Cardholder Capability Container (CCC) Identifier
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct CCC(pub [u8; YKPIV_CCC_SIZE]);
|
||||
|
||||
impl CCC {
|
||||
/// Return CardId component of CHUID
|
||||
pub fn cccid(&self) -> Result<CccCardId, Error> {
|
||||
/// Return CardId component of CCC
|
||||
pub fn cccid(&self) -> Result<CardId, Error> {
|
||||
let mut cccid = [0u8; YKPIV_CCCID_SIZE];
|
||||
cccid.copy_from_slice(&self.0[CCC_ID_OFFS..(CCC_ID_OFFS + YKPIV_CCCID_SIZE)]);
|
||||
Ok(CccCardId(cccid))
|
||||
}
|
||||
|
||||
/// Generate a random CCCID
|
||||
pub fn generate() -> Result<CccCardId, Error> {
|
||||
let mut id = [0u8; YKPIV_CCCID_SIZE];
|
||||
getrandom(&mut id).map_err(|_| Error::RandomnessError)?;
|
||||
Ok(CccCardId(id))
|
||||
Ok(CardId(cccid))
|
||||
}
|
||||
|
||||
/// Get Cardholder Capability Container (CCC) ID
|
||||
@@ -82,7 +84,7 @@ impl CCC {
|
||||
|
||||
let mut ccc = [0u8; YKPIV_CCC_SIZE];
|
||||
ccc.copy_from_slice(&response[0..YKPIV_CCC_SIZE]);
|
||||
Ok(CCC { 0: ccc })
|
||||
Ok(Self(ccc))
|
||||
}
|
||||
|
||||
/// Get Cardholder Capability Container (CCC) ID
|
||||
|
||||
Reference in New Issue
Block a user