Skip to content

Commit

Permalink
Change API for EAD items to support large numbers
Browse files Browse the repository at this point in the history
The set of supported values is not changed, but the API is changed so
that the implementation can be fixed without an extra breaking change.
  • Loading branch information
chrysn committed Feb 3, 2025
1 parent 8949331 commit 1a58410
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ead/lakers-ead-authz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use device::{ZeroTouchDevice, ZeroTouchDeviceDone, ZeroTouchDeviceWaitEAD2};
pub use server::{ZeroTouchServer, ZeroTouchServerUserAcl};

pub mod consts {
pub const EAD_AUTHZ_LABEL: u8 = 0x1; // NOTE: in lake-authz-draft-01 it is still TBD1
pub const EAD_AUTHZ_LABEL: u16 = 0x1; // NOTE: in lake-authz-draft-01 it is still TBD1
pub const EAD_AUTHZ_INFO_K_1_LABEL: u8 = 0x0;
pub const EAD_AUTHZ_INFO_IV_1_LABEL: u8 = 0x1;
pub const EAD_AUTHZ_ENC_STRUCTURE_LEN: usize = 2 + 8 + 3;
Expand Down
11 changes: 6 additions & 5 deletions lib/src/edhoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,15 @@ fn encode_ead_item(ead_1: &EADItem) -> Result<EdhocMessageBuffer, EDHOCError> {
let mut output = EdhocMessageBuffer::new();

// encode label
// FIXME: This only works for values up to 23
let res = if ead_1.is_critical {
// ensure it won't overflow
ead_1
.label
.checked_add(CBOR_NEG_INT_1BYTE_START)
u8::try_from(ead_1.label)
.ok()
.and_then(|x| x.checked_add(CBOR_NEG_INT_1BYTE_START))
.and_then(|x| x.checked_sub(1))
} else {
Some(ead_1.label)
ead_1.label.try_into().ok()
};

if let Some(label) = res {
Expand Down Expand Up @@ -1201,7 +1202,7 @@ mod tests {
const MESSAGE_1_TV_SUITE_ONLY_C: &str = "0382021819";
// message with an array having too many cipher suites (more than 9)
const MESSAGE_1_TV_SUITE_ONLY_ERR: &str = "038A02020202020202020202";
const EAD_DUMMY_LABEL_TV: u8 = 0x01;
const EAD_DUMMY_LABEL_TV: u16 = 0x01;
const EAD_DUMMY_VALUE_TV: &str = "cccccc";
const EAD_DUMMY_CRITICAL_TV: &str = "20cccccc";
const MESSAGE_1_WITH_DUMMY_EAD_NO_VALUE_TV: &str =
Expand Down
9 changes: 7 additions & 2 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,12 @@ impl TryInto<EdhocMessageBuffer> for &[u8] {
#[cfg_attr(feature = "python-bindings", pyclass)]
#[derive(Clone, Debug)]
pub struct EADItem {
pub label: u8,
/// EAD label of the item
///
/// # Caveats
///
/// Currently, only values up to 23 are supported.
pub label: u16,
pub is_critical: bool,
// TODO[ead]: have adjustable (smaller) length for this buffer
pub value: Option<EdhocMessageBuffer>,
Expand Down Expand Up @@ -717,7 +722,7 @@ mod edhoc_parser {
None
};
let ead_item = Some(EADItem {
label,
label: label.into(),
is_critical,
value: ead_value,
});
Expand Down

0 comments on commit 1a58410

Please sign in to comment.