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
|
||||
|
||||
+10
-8
@@ -57,7 +57,16 @@ const CHUID_TMPL: &[u8] = &[
|
||||
|
||||
/// Cardholder Unique Identifier (CHUID) Card UUID/GUID value
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct ChuidUuid(pub [u8; YKPIV_CARDID_SIZE]);
|
||||
pub struct Uuid(pub [u8; YKPIV_CARDID_SIZE]);
|
||||
|
||||
impl Uuid {
|
||||
/// Generate a random Cardholder Unique Identifier (CHUID)
|
||||
pub fn generate() -> Result<Self, Error> {
|
||||
let mut id = [0u8; YKPIV_CARDID_SIZE];
|
||||
getrandom(&mut id).map_err(|_| Error::RandomnessError)?;
|
||||
Ok(Self(id))
|
||||
}
|
||||
}
|
||||
|
||||
/// Cardholder Unique Identifier (CHUID)
|
||||
#[derive(Copy, Clone)]
|
||||
@@ -87,13 +96,6 @@ impl CHUID {
|
||||
Ok(expiration)
|
||||
}
|
||||
|
||||
/// Generate a random Cardholder Unique Identifier (CHUID)
|
||||
pub fn generate() -> Result<ChuidUuid, Error> {
|
||||
let mut id = [0u8; YKPIV_CARDID_SIZE];
|
||||
getrandom(&mut id).map_err(|_| Error::RandomnessError)?;
|
||||
Ok(ChuidUuid(id))
|
||||
}
|
||||
|
||||
/// Get Cardholder Unique Identifier (CHUID)
|
||||
pub fn get(yubikey: &mut YubiKey) -> Result<CHUID, Error> {
|
||||
let txn = yubikey.begin_transaction()?;
|
||||
|
||||
@@ -155,6 +155,9 @@ impl YubiKey {
|
||||
Err(Error::GenericError)
|
||||
}
|
||||
|
||||
/// Open a connection to a YubiKey with the given serial number.
|
||||
|
||||
|
||||
/// Reconnect to a YubiKey
|
||||
#[cfg(feature = "untested")]
|
||||
pub fn reconnect(&mut self) -> Result<(), Error> {
|
||||
|
||||
Reference in New Issue
Block a user