From 4705a8bf9e6d1dab4aa53ee3379dd3a563458dfa Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 25 Nov 2024 16:53:40 +0100 Subject: [PATCH 1/4] doc/shared: Add IdCred usage examples --- shared/src/cred.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shared/src/cred.rs b/shared/src/cred.rs index 393816c9..1cf7c057 100644 --- a/shared/src/cred.rs +++ b/shared/src/cred.rs @@ -39,9 +39,18 @@ impl From 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" /* 23 */)).unwrap(); +/// assert_eq!(short_kid.as_full_value(), &hex!("a1044117" /* { 4: h'17' } */)); +/// let long_kid = IdCred::from_encoded_value(&hex!("4161" /* 'a' */)).unwrap(); +/// assert_eq!(long_kid.as_full_value(), &hex!("a1044161" /* { 4: 'a' } */)); +/// ``` #[derive(Clone, Copy, Debug, Default, PartialEq)] #[repr(C)] pub struct IdCred { From 41b712b91d0bac88916ceb987fda32f36135be36 Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 25 Nov 2024 16:57:39 +0100 Subject: [PATCH 2/4] shared: Compatibly rename KCSS_LABEL to KCCS_LABEL --- shared/src/cred.rs | 4 ++-- shared/src/lib.rs | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/shared/src/cred.rs b/shared/src/cred.rs index 1cf7c057..db70d6f0 100644 --- a/shared/src/cred.rs +++ b/shared/src/cred.rs @@ -92,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), }; @@ -313,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 diff --git a/shared/src/lib.rs b/shared/src/lib.rs index b7155f0f..556962bf 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -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 From 9d33d866cfabbaa83f85d3116609b8e00a8b3dbf Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 25 Nov 2024 16:59:39 +0100 Subject: [PATCH 3/4] shared: Don't accept inconsistent encoding lengths in IdCred KIDs --- shared/src/cred.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/src/cred.rs b/shared/src/cred.rs index db70d6f0..2d98c3d8 100644 --- a/shared/src/cred.rs +++ b/shared/src/cred.rs @@ -83,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 From cc68d847ace203afcaac5937c39f3d664e34f0d5 Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 25 Nov 2024 17:48:36 +0100 Subject: [PATCH 4/4] shared: Move comments that break cbindgen to end of line Workaround-For: https://github.com/mozilla/cbindgen/issues/1033 --- shared/src/cred.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/src/cred.rs b/shared/src/cred.rs index 2d98c3d8..c24b1178 100644 --- a/shared/src/cred.rs +++ b/shared/src/cred.rs @@ -46,10 +46,10 @@ impl From for IdCredType { /// ```rust /// # use hexlit::hex; /// # use lakers_shared::IdCred; -/// let short_kid = IdCred::from_encoded_value(&hex!("17" /* 23 */)).unwrap(); -/// assert_eq!(short_kid.as_full_value(), &hex!("a1044117" /* { 4: h'17' } */)); -/// let long_kid = IdCred::from_encoded_value(&hex!("4161" /* 'a' */)).unwrap(); -/// assert_eq!(long_kid.as_full_value(), &hex!("a1044161" /* { 4: 'a' } */)); +/// 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)]