Skip to content

Commit

Permalink
Merge pull request #325 from chrysn-pull-requests/id-cred-docs
Browse files Browse the repository at this point in the history
IdCred enhancements
  • Loading branch information
geonnave authored Nov 25, 2024
2 parents 975010e + cc68d84 commit eb32a07
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions shared/src/cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ impl From<u8> for IdCredType {
}
}

/// A value of ID_CRED_x: a credential identifier
/// A value of ID_CRED_x: a credential identifier.
///
/// Possible values include key IDs, credentials by value and others.
///
/// ```rust
/// # use hexlit::hex;
/// # use lakers_shared::IdCred;
/// let short_kid = IdCred::from_encoded_value(&hex!("17")).unwrap(); // 23
/// assert_eq!(short_kid.as_full_value(), &hex!("a1044117")); // {4: h'17'}
/// let long_kid = IdCred::from_encoded_value(&hex!("4161")).unwrap(); // 'a'
/// assert_eq!(long_kid.as_full_value(), &hex!("a1044161")); // {4: 'a'}
/// ```
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[repr(C)]
pub struct IdCred {
Expand Down Expand Up @@ -74,7 +83,7 @@ impl IdCred {
.map_err(|_| EDHOCError::CredentialTooLongError)? // TODO: how to avoid map_err overuse?
}
// kid that has been encoded as CBOR byte string
&[0x41, x, ..] if !Self::bstr_representable_as_int(x) => {
&[0x41, x] if !Self::bstr_representable_as_int(x) => {
let mut bytes = BufferIdCred::new_from_slice(&[0xa1, KID_LABEL])
.map_err(|_| EDHOCError::CredentialTooLongError)?;
bytes
Expand All @@ -83,7 +92,7 @@ impl IdCred {
bytes
}
// CCS by value
&[0xa1, KCSS_LABEL, ..] => BufferIdCred::new_from_slice(value)
&[0xa1, KCCS_LABEL, ..] => BufferIdCred::new_from_slice(value)
.map_err(|_| EDHOCError::CredentialTooLongError)?,
_ => return Err(EDHOCError::ParsingError),
};
Expand Down Expand Up @@ -304,7 +313,7 @@ impl Credential {
let mut id_cred = IdCred::new();
id_cred
.bytes
.extend_from_slice(&[CBOR_MAJOR_MAP + 1, KCSS_LABEL])
.extend_from_slice(&[CBOR_MAJOR_MAP + 1, KCCS_LABEL])
.map_err(|_| EDHOCError::CredentialTooLongError)?;
id_cred
.bytes
Expand Down
4 changes: 3 additions & 1 deletion shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ pub const MAX_INFO_LEN: usize = 2 + SHA256_DIGEST_LEN + // 32-byte digest as bst
1 + MAX_KDF_CONTEXT_LEN + // context <24 bytes as bstr
1; // length as u8

pub const KCSS_LABEL: u8 = 14;
pub const KCCS_LABEL: u8 = 14;
#[deprecated(note = "Typo for KCCS_LABEL")]
pub const KCSS_LABEL: u8 = KCCS_LABEL;
pub const KID_LABEL: u8 = 4;

pub const ENC_STRUCTURE_LEN: usize = 8 + 5 + SHA256_DIGEST_LEN; // 8 for ENCRYPT0
Expand Down

0 comments on commit eb32a07

Please sign in to comment.