Skip to main content

Module rdf

Module rdf 

Source
Expand description

RDF, and its canonical form: what a Linked Data Signature signs.

A Linked Data Signature (RsaSignature2017, which Mastodon makes and checks) does not sign the JSON. It signs the RDF dataset the JSON-LD means, written out in the canonical N-Quads that the URDNA2015 algorithm gives — so two documents that say the same thing in different words carry the same signature, and verifying one means turning it into RDF exactly as its signer did.

canonize does that, from expansion in this crate, through the JSON-LD 1.1 “Deserialize JSON-LD to RDF” algorithm, to the “Universal RDF Dataset Normalization Algorithm 2015” (URDNA2015, which RDFC-1.0 standardised without changing its output).

Two things make it stricter than a general processor, both deliberate:

  • A context the registry does not hold is an error here, not ActivityStreams. A signer resolved it to something; without it, the dataset cannot be rebuilt, and guessing would only make the signature fail later. A caller that fetches contexts asks unresolved_contexts which ones to add first.
  • The work is bounded. Expansion is held to Limits; the blank-node labelling, whose worst case is factorial in the number of blank nodes that look alike, is held to a budget of its own and gives up with Error::CanonicalizationBudgetExceeded rather than run away.

Structs§

Quad
One RDF statement, in the default graph or a named one.

Enums§

Term
A node or value in an RDF statement.

Functions§

canonicalize
URDNA2015: the dataset’s canonical N-Quads, one statement a line, sorted.
canonize
The canonical N-Quads of document: what an RsaSignature2017 hashes.
canonize_with
canonize, with limits of the caller’s choosing.
expand_for_rdf
Expand document the way RDF needs it, refusing a context ojak does not ship.
to_rdf
The JSON-LD “Deserialize JSON-LD to RDF” algorithm, over a document expand_for_rdf expanded.
unresolved_contexts
Every context document names, directly or through a context it names, that registry does not hold: what a caller that fetches contexts has to fetch before canonize can succeed.