This project is archived. Its data is read-only.

Values in-range which are encoded under larger types cause decode-time "type errors"

https://gitlab.com/twittner/minicbor/-/blob/develop/minicbor/src/decode/decoder.rs#L91-98

CBOR does not require a number is encoded in its smallest form. I.e. One implementation might encode all integers as u32/i32. Even if the data we want to decode is strictly a u8.

// good
assert_eq!(minicbor::Decoder::new(&[27, 0, 0, 0, 0, 0, 0, 0, 123]).u64().ok(), Some(123));
// fails. Err(Error::TypeMismatch(Type::read(27), "expected u8"))
assert_eq!(minicbor::Decoder::new(&[27, 0, 0, 0, 0, 0, 0, 0, 123]).u8().ok(), Some(123));

Sidenote: there is no Eq implementation on Error, which is why the above ignores the error case with .ok().

Edited Nov 09, 2021 by Sofia
Assignee Loading
Time tracking Loading