Documentation
¶
Overview ¶
Package jcs writes the JSON Canonicalization Scheme of RFC 8785: one byte form for a JSON document — members sorted, no whitespace, numbers and strings spelled one way — so it can be signed or hashed, and checked by anyone who canonicalizes the same document.
canonical, err := jcs.Canonicalize(document) digest := sha256.Sum256(canonical)
Marshal canonicalizes a Go value's encoding/json/v2 encoding. The document must be one I-JSON value (RFC 7493) — valid UTF-8, no duplicated member name — or Canonicalize returns NotJSON, naming the offset and never a byte of the document; a number past the largest finite double is NumberInvalid. It is not a codec Format: a canonical form is a policy over JSON, as strictjson is a policy over decoding.
Index ¶
Constants ¶
const ( // CodeNotJSON is the code of [NotJSON] (0.3.102.1), for errs.HasCode. CodeNotJSON errs.Code = corejcs.CodeJCSNotJSON // CodeNumberInvalid is the code of [NumberInvalid] (0.3.102.2). CodeNumberInvalid errs.Code = corejcs.CodeJCSNumberInvalid // CodeMarshalFailed is the code of [MarshalFailed] (0.3.102.3). CodeMarshalFailed errs.Code = corejcs.CodeJCSMarshalFailed )
The error codes, range 0.3.102.*, declared in the core (ADR 0160).
Variables ¶
var ( // NotJSON refuses a document that is not exactly one I-JSON value; its field // names the offset, never its content. NotJSON = corejcs.NotJSON // NumberInvalid refuses a number past the largest finite double. NumberInvalid = corejcs.NumberInvalid // MarshalFailed wraps encoding/json/v2's refusal of a value. MarshalFailed = corejcs.MarshalFailed )
The sentinels, for errors.Is: each carries the code of the same name.
Functions ¶
func Canonicalize ¶
Canonicalize returns the RFC 8785 canonical form of the JSON document doc, or NotJSON, or NumberInvalid.
Types ¶
This section is empty.