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

make sort_keys=True work #2

Open
brianolson opened this issue Apr 10, 2017 · 2 comments
Open

make sort_keys=True work #2

brianolson opened this issue Apr 10, 2017 · 2 comments

Comments

@brianolson
Copy link
Owner

brianolson commented Apr 10, 2017

So that people can have repeatable canonical binary serializations of a json/cbor object, add a sort_keys=True feature to dump()/dumps()
Follow "Canonical CBOR" section 3.9 rules for sorting

@chrysn
Copy link

chrysn commented Apr 10, 2017

The sorting rules in 3.9 of RFC7049 are rather explicit, relate to the encoded version of the key elements, and are most importantly not compatible with sorting unicode keys, because they specify that short representations come before long ones (something like len(a) < len(b) if len(a) != len(b) else a < b).

@brianolson
Copy link
Owner Author

ok, from section 3.9, "Canonical CBOR"

The keys in every map must be sorted lowest value to highest.
      Sorting is performed on the bytes of the representation of the key
      data items without paying attention to the 3/5 bit splitting for
      major types.  (Note that this rule allows maps that have keys of
      different types, even though that is probably a bad practice that
      could lead to errors in some canonicalization implementations.)
      The sorting rules are:

      *  If two keys have different lengths, the shorter one sorts
         earlier;

      *  If two keys have the same length, the one with the lower value
         in (byte-wise) lexical order sorts earlier.

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