libcbor
libcbor copied to clipboard
cbor_map_get and cbor_equal
Add two functions in the library:
-
cbor_equal
: compare two cbor items content and return true if type, metadata and data are the same -
cbor_map_get
: return the value corresponding to the specified key in a CBOR map structure
Hello @PJK ,
Thanks for your feedback, I know libcbor
and the cbor format for only a few weeks now, so I'm not familiar with all the subtle use cases :-)
My real goal is to have cbor_map_get
to facilitate parsing webauthn cbor attestations and assertions, for example:
https://github.com/babelouest/glewlwyd/blob/2.0b/src/scheme/webauthn.c#L1128
https://github.com/babelouest/glewlwyd/blob/2.0b/src/scheme/webauthn.c#L879
In my opinion, a cbor_equal
should test strict equality, both data and metadata. Because cbor is a binary format, used by machines rather than humans, so, a machine is more intended to know which format it needs.
But we could create a cbor_equiv
in addition to cbor_equal
, that would test equivalent cbor data.
The problem would be to set the rules on what is equivalent and what isn't.
For example, is a bytestring of size 4 containning "hello"
equivalent to a string containing "hello"
? Is a negative int equivalent to a unsigned int? etc.
But you're the maintainer so it's your call.
I will address your comments soon.
@PJK , I've made some adjustments, and now Travis CI fails, I don't understand why. I may have missed a cbor_decref
somewhere but I don't know where...
valgrind says there's no memory leak.
Do you have an idea?
@PJK , any update?
Thanks for changes and sorry about the delay, I'm somewhat overloaded these days.
Looking at the Travis failure, I see
+./clang-format.sh
/usr/bin/clang-format-8
+git status
+grep 'nothing to commit, working tree clean'
This means that the code is not formatted according to clang-format's liking -- you can just run the script yourself and commit the changes, that should fix it. Also filed #104 to make this part better.
If I run the clang-format
by myself, I don't see any error:
nico@localhost:~/workspace/libcbor$ clang-format-8 --verbose -style=file -i **/*.c **/*.h **/*.cpp
Formatting demo/hello_cbor.c
Formatting examples/cjson2cbor.c
Formatting examples/create_items.c
Formatting examples/hello.c
Formatting examples/readfile.c
Formatting examples/sort.c
Formatting examples/streaming_parser.c
Formatting src/allocators.c
Formatting src/cbor.c
Formatting test/assertions.c
Formatting test/bad_inputs_test.c
Formatting test/callbacks_test.c
Formatting test/cbor_serialize_test.c
Formatting test/cbor_stream_decode_test.c
Formatting test/copy_test.c
Formatting test/equal_test.c
Formatting test/fuzz_test.c
Formatting test/memory_allocation_test.c
Formatting test/pretty_printer_test.c
Formatting test/stream_expectations.c
Formatting test/type_0_encoders_test.c
Formatting test/type_0_test.c
Formatting test/type_1_encoders_test.c
Formatting test/type_1_test.c
Formatting test/type_2_encoders_test.c
Formatting test/type_2_test.c
Formatting test/type_3_encoders_test.c
Formatting test/type_3_test.c
Formatting test/type_4_encoders_test.c
Formatting test/type_4_test.c
Formatting test/type_5_encoders_test.c
Formatting test/type_5_test.c
Formatting test/type_6_encoders_test.c
Formatting test/type_6_test.c
Formatting test/type_7_encoders_test.c
Formatting test/type_7_test.c
Formatting test/unicode_test.c
Formatting src/cbor.h
Formatting test/assertions.h
Formatting test/stream_expectations.h
Formatting test/cpp_linkage_test.cpp
nico@localhost:~/workspace/libcbor$ echo $?
0
Would there be some environment difference between travis-ci and my Ubuntu?
Hmm, could be, that is unfortunate. I will try to take a look later this week
After further investigation, it seems the problem comes from the following command in .travis-qemu.sh:
git status | grep "nothing to commit, working tree clean"
I just provided a PR to make some small improvements to the CI script: #105 This should do
All checks have passed
Nailed it! :-)