Skip to content

Commit

Permalink
Merge pull request #333 from chrysn-pull-requests/ead-api-16
Browse files Browse the repository at this point in the history
Change API for EAD items to support large numbers
  • Loading branch information
chrysn authored Feb 3, 2025
2 parents 30fdd30 + ddc20e1 commit 747368a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 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
2 changes: 1 addition & 1 deletion lakers-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static HEAP: Heap = Heap::empty();
#[derive(Default, Clone, Debug)]
#[repr(C)]
pub struct EADItemC {
pub label: u8,
pub label: u16,
pub is_critical: bool,
pub value: EdhocMessageBuffer,
}
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 @@ -668,7 +668,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 @@ -750,7 +755,7 @@ mod edhoc_parser {
None
};
let ead_item = Some(EADItem {
label,
label: label.into(),
is_critical,
value: ead_value,
});
Expand Down
4 changes: 2 additions & 2 deletions shared/src/python_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<EdhocBufferError> for PyErr {
#[pymethods]
impl EADItem {
#[new]
fn new_py(label: u8, is_critical: bool, value: Vec<u8>) -> Self {
fn new_py(label: u16, is_critical: bool, value: Vec<u8>) -> Self {
Self {
label,
is_critical,
Expand All @@ -63,7 +63,7 @@ impl EADItem {
.map(|v| PyBytes::new_bound(py, v.as_slice()))
}

fn label(&self) -> u8 {
fn label(&self) -> u16 {
self.label
}

Expand Down

0 comments on commit 747368a

Please sign in to comment.