A pure-Python implementation of RFC 8785 (JSON Canonicalization Scheme)
Project Links
Meta
Author: Trail of Bits
Requires Python: >=3.8
Classifiers
Development Status
- 4 - Beta
License
- OSI Approved :: Apache Software License
Programming Language
- Python :: 3
Topic
- File Formats :: JSON
- Security :: Cryptography
rfc8785.py
A pure-Python, no-dependency implementation of RFC 8785, a.k.a. JSON Canonicalization Scheme or JCS.
This implementation should be behaviorally comparable to Andrew Rundgren's reference implementation, with the following added constraints:
- This implementation does not transparently convert non-
strdictionary keys into strings. Users must explicitly perform this conversion. - No support for indentation, pretty-printing, etc. is provided. The output is always minimally encoded.
- All APIs produce UTF-8-encoded
bytesobjects orbytesI/O.
Installation
python -m pip install rfc8785
Usage
See the full API documentation here.
import rfc8785
foo = {
"key": "value",
"another-key": 2,
"a-third": [1, 2, 3, [4], (5, 6, "this works too")],
"more": [None, True, False],
}
rfc8785.dumps(foo)
yields:
b'{"a-third":[1,2,3,[4],[5,6,"this works too"]],"another-key":2,"key":"value","more":[null,true,false]}'
For direct serialization to an I/O sink, use rfc8785.dump instead:
import rfc8785
with open("/some/file", mode="wb") as io:
rfc8785.dump([1, 2, 3, 4], io)
All APIs raise rfc8785.CanonicalizationError or a subclass on serialization failures.
Licensing
Apache License, Version 2.0.
Where noted, parts of this implementation are adapted from Andrew Rundgren's reference implementation, which is also licensed under the Apache License, Version 2.0.
0.1.4
Sep 27, 2024
0.1.3
Jun 07, 2024
0.1.2
Mar 19, 2024
0.1.1
Mar 19, 2024
0.1.0
Mar 19, 2024
0.0.3
Mar 07, 2024
0.0.2
Mar 06, 2024
0.0.1
Mar 06, 2024