jcs

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jcs writes JCS(x), the JSON Canonicalization Scheme of RFC 8785 (SPEC.md sections 2.2 and 2.5), and the canonical form of SPEC.md section 9.

Encode and CanonicalForm (encode.go and canonical_form.go) take a value that internal/strictjson read under the parsing rules of SPEC.md section 10.1, whose numbers rule J5 has already read as binary64 values. Transform takes bytes: it reads them with that same reader and writes the value with Encode, so a text the rules refuse is refused, an integer of magnitude above MAX_INTEGER and below 10^21 among them, and every other number is written as its nearest binary64 value is. It is what `truestamp jcs` and `truestamp hash --jcs` canonicalize with.

Everything else of RFC 8785, UTF-16 code-unit key ordering, string escaping and ES6 number formatting, is github.com/gowebpki/jcs's, which this package wraps and which no other package imports.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutsideProfile = errors.New("jcs: the value is not within the value profile")

ErrOutsideProfile marks a value Encode or CanonicalForm refuses: one that is not a value the strict reader can give.

Functions

func CanonicalForm added in v0.17.0

func CanonicalForm(v any) ([]byte, error)

CanonicalForm returns v in the canonical form of SPEC.md section 9, with its final newline: members in JCS order, two-space indentation and LF line ends. A member is its name, a colon, one space and its value; an object or array that is not empty puts each member or element on a line of its own, one level deeper and followed by a comma unless it is the last, and closes on a line of its own at the indentation of the line that opens it, while an empty one is {} or []; and every name and scalar is written as Encode writes it.

v is a value as Encode takes it, and CanonicalForm refuses what Encode refuses, with ErrOutsideProfile.

func Encode added in v0.17.0

func Encode(v any) ([]byte, error)

Encode returns JCS(v), the RFC 8785 canonical form of v: no whitespace, object members sorted by the UTF-16 code units of their names, strings escaped as RFC 8785 section 3.2.2.2 says, and numbers written as ECMAScript's Number.prototype.toString writes them (section 3.2.2.3).

v is a value as strictjson.Parse gives it: nil, a bool, a strictjson.Number, a string, a []any or a map[string]any of such values. Encode refuses, with ErrOutsideProfile, any other Go type, a string or member name that is not UTF-8, a Number that is not finite, and a Number that is integral, of magnitude above MAX_INTEGER and below 10^21. It checks nothing else of the profile: a Number of -0 is written "0", as RFC 8785 writes it, and the depth of a value is not checked. No parsed value is refused, so a value that is comes from a defect in the caller.

func Transform

func Transform(data []byte) ([]byte, error)

Transform returns JCS of the JSON text data: data read with strictjson.Parse (rules J2 to J6 of SPEC.md section 10.1) and written with Encode. A text the rules refuse gives the reader's *strictjson.Rejection: a repeated member name, invalid UTF-8, a lone surrogate, a depth above MAX_DEPTH, anything after the value, or a number J5 refuses, such as 9007199254740992, 9007199254740992.0 or 1e16. Every other number is written as its nearest binary64 value is, so 1 followed by 800 zeros and e-800 is written 1.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL