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

Decode does not work for CBOR produced by Kotlin serializer #20

Open
denisenkom opened this issue Nov 9, 2023 · 1 comment
Open

Decode does not work for CBOR produced by Kotlin serializer #20

denisenkom opened this issue Nov 9, 2023 · 1 comment

Comments

@denisenkom
Copy link

I used Kotlin's KotlinxSerializationCbor to generate following CBOR, encoding it in base64 urlsafe format:

v2dzdWNjZXNz9G5taXNzaW5nRmFjdG9yc5-fn2h3ZWJhdXRobr____-fn2d5dWJpb3Rwv_______

I can decode it using cbor2pretty.rb tool with the following command:

echo v2dzdWNjZXNz9G5taXNzaW5nRmFjdG9yc5-fn2h3ZWJhdXRobr____-fn2d5dWJpb3Rwv_______ \
  | basenc -d --base64url | cbor2pretty.rb

Here is the result:

bf                                 # map(*)
   67                              # text(7)
      73756363657373               # "success"
   f4                              # primitive(20)
   6e                              # text(14)
      6d697373696e67466163746f7273 # "missingFactors"
   9f                              # array(*)
      9f                           # array(*)
         9f                        # array(*)
            68                     # text(8)
               776562617574686e    # "webauthn"
            bf                     # map(*)
               ff                  # primitive(*)
            ff                     # primitive(*)
         ff                        # primitive(*)
      9f                           # array(*)
         9f                        # array(*)
            67                     # text(7)
               797562696f7470      # "yubiotp"
            bf                     # map(*)
               ff                  # primitive(*)
            ff                     # primitive(*)
         ff                        # primitive(*)
      ff                           # primitive(*)
   ff                              # primitive(*)

This indicates to me that this is a valid CBOR and that probably Kotlin serializer is not at fault.

When I try to decode this CBOR using this library using code snippet:

require 'cbor'
require 'base64'
CBOR.decode(Base64.urlsafe_decode64('v2dzdWNjZXNz9G5taXNzaW5nRmFjdG9yc5-fn2h3ZWJhdXRobr____-fn2d5dWJpb3Rwv_______'))

I get error:

in `decode': invalid byte (CBOR::MalformedFormatError)

Is this library not supporting map(*) and/or array(*) elements? If this is the case, is it possible to add support for such elements?

@cabo
Copy link
Owner

cabo commented Nov 9, 2023 via email

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

No branches or pull requests

2 participants