Skip to content

Commit bdc924d

Browse files
committed
Change API for EAD items to support large numbers
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.
1 parent a247d0b commit bdc924d

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

ead/lakers-ead-authz/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use device::{ZeroTouchDevice, ZeroTouchDeviceDone, ZeroTouchDeviceWaitEAD2};
1212
pub use server::{ZeroTouchServer, ZeroTouchServerUserAcl};
1313

1414
pub mod consts {
15-
pub const EAD_AUTHZ_LABEL: u8 = 0x1; // NOTE: in lake-authz-draft-01 it is still TBD1
15+
pub const EAD_AUTHZ_LABEL: u16 = 0x1; // NOTE: in lake-authz-draft-01 it is still TBD1
1616
pub const EAD_AUTHZ_INFO_K_1_LABEL: u8 = 0x0;
1717
pub const EAD_AUTHZ_INFO_IV_1_LABEL: u8 = 0x1;
1818
pub const EAD_AUTHZ_ENC_STRUCTURE_LEN: usize = 2 + 8 + 3;

lib/src/edhoc.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,15 @@ fn encode_ead_item(ead_1: &EADItem) -> Result<EdhocMessageBuffer, EDHOCError> {
497497
let mut output = EdhocMessageBuffer::new();
498498

499499
// encode label
500+
// FIXME: This only works for values up to 23
500501
let res = if ead_1.is_critical {
501502
// ensure it won't overflow
502-
ead_1
503-
.label
504-
.checked_add(CBOR_NEG_INT_1BYTE_START)
503+
u8::try_from(ead_1.label)
504+
.ok()
505+
.and_then(|x| x.checked_add(CBOR_NEG_INT_1BYTE_START))
505506
.and_then(|x| x.checked_sub(1))
506507
} else {
507-
Some(ead_1.label)
508+
ead_1.label.try_into().ok()
508509
};
509510

510511
if let Some(label) = res {
@@ -1201,7 +1202,7 @@ mod tests {
12011202
const MESSAGE_1_TV_SUITE_ONLY_C: &str = "0382021819";
12021203
// message with an array having too many cipher suites (more than 9)
12031204
const MESSAGE_1_TV_SUITE_ONLY_ERR: &str = "038A02020202020202020202";
1204-
const EAD_DUMMY_LABEL_TV: u8 = 0x01;
1205+
const EAD_DUMMY_LABEL_TV: u16 = 0x01;
12051206
const EAD_DUMMY_VALUE_TV: &str = "cccccc";
12061207
const EAD_DUMMY_CRITICAL_TV: &str = "20cccccc";
12071208
const MESSAGE_1_WITH_DUMMY_EAD_NO_VALUE_TV: &str =

shared/src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,12 @@ impl TryInto<EdhocMessageBuffer> for &[u8] {
635635
#[cfg_attr(feature = "python-bindings", pyclass)]
636636
#[derive(Clone, Debug)]
637637
pub struct EADItem {
638-
pub label: u8,
638+
/// EAD label of the item
639+
///
640+
/// # Caveats
641+
///
642+
/// Currently, only values up to 23 are supported.
643+
pub label: u16,
639644
pub is_critical: bool,
640645
// TODO[ead]: have adjustable (smaller) length for this buffer
641646
pub value: Option<EdhocMessageBuffer>,
@@ -717,7 +722,7 @@ mod edhoc_parser {
717722
None
718723
};
719724
let ead_item = Some(EADItem {
720-
label,
725+
label: label.into(),
721726
is_critical,
722727
value: ead_value,
723728
});

0 commit comments

Comments
 (0)