Skip to content

Canonical json support (RFC 8785 / JCS) #715

Description

@lmussier

Describe the proposed feature
Hi,

For json document hash use cases, it is mandatory to always have the same json representation for a same set of data.
This is the purpose of https://www.rfc-editor.org/info/rfc8785/

What other libraries (C++ or other) have this feature?
Seen it https://github.com/mirkokiefer/canonical-json and https://github.com/rezn-project/rezn-jcsd - not tested

Include a code fragment with sample data that illustrates the use of this feature
Exemples from here https://connect2id.com/blog/how-to-secure-json-objects-with-hmac (not my production)

Given

{"key":"9cea8d2d","name":"Alice Adams","age":21}

{"key":"9cea8d2d","age":21,"name":"Alice Adams"}

and

{
  "key" : "9cea8d2d",
  "name" : "Alice Adams",
  "age" : 21
}

The canonical version of it is a deterministic string whatever is the order of the keys on the input document.

std::cout << normalize(data) << std::endl;

Would give

{"age":21,"key":"9cea8d2d","name":"Alice Adams"}

and this for every format of the same data set.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions