Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trailofbits/rfc8785.py
A pure-Python implementation of RFC8785 (JSON Canonicalization Scheme)
https://github.com/trailofbits/rfc8785.py
canonicalization cryptography json python serialization
Last synced: 10 days ago
JSON representation
A pure-Python implementation of RFC8785 (JSON Canonicalization Scheme)
- Host: GitHub
- URL: https://github.com/trailofbits/rfc8785.py
- Owner: trailofbits
- License: apache-2.0
- Created: 2024-03-06T17:15:05.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-09-27T16:43:48.000Z (about 2 months ago)
- Last Synced: 2024-09-27T16:48:20.531Z (about 2 months ago)
- Topics: canonicalization, cryptography, json, python, serialization
- Language: Python
- Homepage: https://trailofbits.github.io/rfc8785.py/
- Size: 37.1 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rfc8785.py
[![CI](https://github.com/trailofbits/rfc8785.py/actions/workflows/tests.yml/badge.svg)](https://github.com/trailofbits/rfc8785.py/actions/workflows/tests.yml)
[![PyPI version](https://badge.fury.io/py/rfc8785.svg)](https://pypi.org/project/rfc8785)
[![Packaging status](https://repology.org/badge/tiny-repos/python:rfc8785.svg)](https://repology.org/project/python:rfc8785/versions)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:1. This implementation does not transparently convert non-`str` dictionary keys into
strings. Users must explicitly perform this conversion.
1. No support for indentation, pretty-printing, etc. is provided. The output is always
minimally encoded.
2. All APIs produce UTF-8-encoded `bytes` objects or `bytes` I/O.## Installation
```bash
python -m pip install rfc8785
```## Usage
See the full API documentation [here].
```python
import rfc8785foo = {
"key": "value",
"another-key": 2,
"a-third": [1, 2, 3, [4], (5, 6, "this works too")],
"more": [None, True, False],
}rfc8785.dumps(foo)
```yields:
```python
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:
```python
import rfc8785with 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.
[RFC 8785]: https://datatracker.ietf.org/doc/html/rfc8785
[Andrew Rundgren's reference implementation]: https://github.com/cyberphone/json-canonicalization/tree/master/python3
[here]: https://trailofbits.github.io/rfc8785.py