Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wishlist: Negative map keys #8

Open
chrysn opened this issue Jan 17, 2025 · 0 comments · May be fixed by #9
Open

wishlist: Negative map keys #8

chrysn opened this issue Jan 17, 2025 · 0 comments · May be fixed by #9

Comments

@chrysn
Copy link

chrysn commented Jan 17, 2025

Deriving minicbor traits fails on this:

/// Decodes a COSE key such as
/// ```
/// {1: 1, -1: 7}
/// ```
#[derive(minicbor::Decode)]
#[cbor(map)]
pub struct CoseKeyOkpEc2<'a> {
    #[n(1)]
    pub kty: i32,
    #[n(-1)]
    pub crv: Option<i32>,
}
error: expected `u32` value
  --> /home/chrysn/git/crates/ariel-os/src/lib/coapcore/src/ace.rs:97:9
   |
97 |     #[n(-1)]

Having negative keys in CBOR maps is a bit more rare than positive keys, but not completely unheard of: it is present in COSE but also in SenML.

Negative values to b() and n(), when used with the cbor(array) container encoding, make no sense, but I don't think it hurts to raise the error then rather than when processing the n()/b().

I'll try to work on a patch; if it is easier than the workaround, that will come soon; otherwise, whenever I next have a bit of spare time. (Such a patch may even prepare support for mixed integer and text string keys, as also COSE and SenML have it, but so far I haven't needed any of the text keys).

@chrysn chrysn linked a pull request Jan 17, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant