cb0r
cb0r copied to clipboard
`cb0r_write` with simple types (true, false, undef, null) returns wrong values
Writing simple types is not in line with the CBOR standard.
Trying to write the array [false,true,null,undefined] results in 84 38 54 75 96 which cannot be decoded e.g. with https://cbor.me.
The output as expected by https://cbor.me is 84 f4 f5 f6 f7, which would adhere to the values specified in the CBOR RFC 7049 Examples.
The following code can be used to reproduce this issue by replacing the bin/cb0r.c with it. Then run make and bin/cb0r afterward.
#include <stdio.h>
#include "cb0r.h"
int main(int argc, char **argv) {
uint8_t my_cbor[8] = {0};
uint8_t *writer = my_cbor;
cb0r_write(writer++, CB0R_ARRAY, 4);
cb0r_write(writer++, CB0R_FALSE, 0);
cb0r_write(writer++, CB0R_TRUE, 0);
cb0r_write(writer++, CB0R_NULL, 0);
cb0r_write(writer++, CB0R_UNDEF, 0);
for (size_t i = 0; i < sizeof(my_cbor); i++) {
printf("%02x ", my_cbor[i]);
}
printf("\n");
return 0;
}