#serde-json #json-format #scheme #canonicalization #rfc #cryptography #jcs

serde_json_canonicalizer

JSON Canonicalization Scheme (JCS - RFC 8785) implementation

2 unstable releases

0.3.0 Sep 17, 2024
0.2.0 Jun 29, 2023
0.1.0 May 22, 2023

#821 in Encoding

Download history 286/week @ 2024-08-21 269/week @ 2024-08-28 506/week @ 2024-09-04 448/week @ 2024-09-11 639/week @ 2024-09-18 289/week @ 2024-09-25 417/week @ 2024-10-02 257/week @ 2024-10-09 233/week @ 2024-10-16 149/week @ 2024-10-23 138/week @ 2024-10-30 378/week @ 2024-11-06 244/week @ 2024-11-13 212/week @ 2024-11-20 193/week @ 2024-11-27 221/week @ 2024-12-04

922 downloads per month
Used in golem-certificate

MIT license

30KB
591 lines

Crates.io Workflow Status Maintenance

serde_json_canonicalizer

An RFC 8785 compatible JSON Canonicalization Scheme output for serde_json.

JSON Canonicalization Scheme RFC-8785 defines a JSON serialization scheme to allow using JSON data in cryptographic operations that rely on byte level reproduction of data. It can be used instead of storing the serialized format as a BASE64 encoded string or similar packaging, allowing easier handling of JSON formatted data that can be canonicalized before feeding it to a cryptographic function.

Usage

use serde_json_canonicalizer::{to_string, to_vec};

#[derive(serde::Serialize)]
struct Data {
    c: isize,
    b: bool,
    a: String,
}

let data = Data { c: 120, b: false, a: "Hello!".to_string() };
let expected = r#"{"a":"Hello!","b":false,"c":120}"#;

// serlialize to string or bytes, drop-in replacement for serde_json
let json_string = to_string(&data).unwrap();
let json_bytes = to_vec(&data).unwrap();

assert_eq!(json_string, expected);
assert_eq!(json_bytes, expected.as_bytes());

License

Licensed under MIT license (LICENSE or https://opensource.org/licenses/MIT)

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.

Compare to serde_jcs

I created this crate because serde_jcs seems to be abandoned and the issues in that repository list a few things where it differs from the RFC. This crate aims to be 100% compatible with the RFC to be a suitable implementation in a multi-language environment.

Dependencies

~0.6–1.1MB
~23K SLoC