Giter Club home page Giter Club logo

test-vectors's Introduction

test-vectors

This repo collects some simple test vectors in machine-processable form.

appendix_a.json

All examples in Appendix A of RFC 7049, encoded as a JSON array.

Each element of the test vector is a map (JSON object) with the keys:

  • cbor: a base-64 encoded CBOR data item
  • hex: the same CBOR data item in hex encoding
  • roundtrip: a boolean that indicates whether a generic CBOR encoder would typically produce identical CBOR on re-encoding the decoded data item (your mileage may vary)
  • decoded: the decoded data item if it can be represented in JSON
  • diagnostic: the representation of the data item in CBOR diagnostic notation, otherwise

To make use of the cases that need diagnostic notation, a diagnostic notation printer is usually all that is needed: decode the CBOR, print the decoded data item in diagnostic notation, and compare.

(Note that the diagnostic notation uses full decoration for the indefinite length byte string, while the decoded indefinite length text string represented in JSON necessarily doesn't.)

test-vectors's People

Contributors

cabo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

test-vectors's Issues

`1bffffffffffffffff` does not round-trip

1bffffffffffffffff has to turn into a BigInteger in JavaScript when decoded. When re-encoded, that turns into c248ffffffffffffffff:

  c2                -- Tag #2
    48              -- Bytes, length: 8
      ffffffffffffffff -- ffffffffffffffff

If I special-case the encoding for BigIntegers that fit into 8 byte normal integers, then c248ffffffffffffffff won't round-trip. My suggestion is to just set roundtrip to false for this case.

appendix_a.json is not I-JSON

appendix_a.json is not terribly interoperable; the big integers lose precision when parsed with ECMAscript's JSON.parse(). RFC 7493 specifies a set of interoperability constraints that would be useful here.

If backward-compatibility is desired, a new property code be added. Example:

  {
    "cbor": "O///////////",
    "hex": "3bffffffffffffffff",
    "roundtrip": true,
    "decoded": -18446744073709551616,
    "decoded2": {
       "type": "bigint",
       "value": "-18446744073709551616"
    }
  },

This still wouldn't be I-JSON compliant, but would allow systems that have the constraints noted there to use this without as many gyrations.

Tagged items

Hi,

Thank you for these test vectors. They are really helpful.
However I am facing a little problem with the tagged items: the decoded value is not only decoded but also modified according to the tag.

For example wkkBAAAAAAAAAAA= is the tagged (2=Positive bignum) byte string 010000000000000000.
It will be great if you could provide the decoded value as is and, if it is tagged, the resulting value.

One of the test vectors is not well formed.

f818 is not permitted by the RFC. Quoting:

An encoder MUST NOT issue two-byte sequences that start with 0xf8 (major type 7, additional information 24) and continue with a byte less than 0x20 (32 decimal). Such sequences are not well-formed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.