Crate bc_envelope

Source
Expand description

§Gordian Envelope: A Flexible Container for Structured Data

§Introduction

The Gordian Envelope protocol specifies a structured format for hierarchical binary data focused on the ability to transmit it in a privacy-focused way. Envelopes are designed to facilitate “smart documents” and have a number of unique features including: easy representation of a variety of semantic structures, a built-in Merkle-like digest tree, deterministic representation using CBOR, and the ability for the holder of a document to selectively encrypt or elide specific parts of a document without invalidating the document structure including the digest tree, or any cryptographic signatures that rely on it.

§Getting Started

[dependencies]
bc-envelope = "0.19.0"

§Specification

Gordian Envelope is currently specified in this IETF Internet Draft.

Envelopes are immutable. You create “mutations” by creating new envelopes from old envelopes.

§Basic Envelope Creation

§Adding Assertions

§Adding Assertions with a Predicate and Object

§Adding Assertions with an Assertion Envelope

§Removing and Replacing Assertions

§Queries

§Getting the basic parts of an envelope

  • Envelope::subject Returns the subject of an envelope.
  • [Envelope::predicate] If the envelope’s subject is an assertion return its predicate, else return None.
  • [Envelope::object] If the envelope’s subject is an assertion return its object, else return None.

§Getting assertions on an envelope

  • Envelope::assertions Returns the assertions of an envelope.
  • Envelope::has_assertions Returns whether an envelope has assertions.
  • [Envelope::assertion] If the envelope’s subject is an assertion return it, else return None.

§Getting the specific types of an envelope

  • [Envelope::leaf] The envelope’s leaf CBOR object, or None if the envelope is not a leaf.
  • [Envelope::known_value] The envelope’s known value, or None if the envelope is not a known value.

§Determining the type of an envelope

§Determining the type of an envelope’s subject

§Getting assertions and parts of assertions

§Extracting parts of envelopes as specific types

§Other queries

§Wrapping and Unwrapping Envelopes

§Formatting Envelopes

§Envelope notation

§Tree notation

§CBOR diagnostic notation

  • Envelope::diagnostic Formats an envelope in CBOR diagnostic notation.
  • [Envelope::diagnostic_opt] Formats an envelope in CBOR diagnostic notation, with optional annotations.

§CBOR hexadecimal notation

  • Envelope::hex Formats an envelope in CBOR hexadecimal notation.
  • Envelope::hex_opt Formats an envelope in CBOR hexadecimal notation, with optional annotations.

§Working with the Digest Tree

§Semantic equivalence

§Structural identicality

§Signing and Verifying Signatures

§Signing

  • [Envelope::sign_with] Creates a signature for the envelope’s subject and returns a new envelope with a 'signed': Signature assertion.
  • [Envelope::sign_with_opt] Creates a signature for the envelope’s subject and returns a new envelope with a 'signed': Signature assertion.
  • [Envelope::sign_with_keys] Creates several signatures for the envelope’s subject and returns a new envelope with additional 'signed': Signature assertions.
  • [Envelope::sign_with_keys_opt] Creates several signatures for the envelope’s subject and returns a new envelope with additional 'signed': Signature assertions.
  • [Envelope::sign_with_uncovered_assertions] Creates a signature for the envelope’s subject and returns a new envelope with a 'signed': Signature assertion.

§Verifying by returning a boolean

§Verifying by returning a result

§Helpers

  • [Envelope::signatures] Returns an array of Signatures from all of the envelope’s signed predicates.
  • Envelope::make_signed_assertion Convenience constructor for a signed: Signature assertion envelope.

§Splitting Envelopes with SSKR

§Encryption

§Public Key Encryption

§Compression

§Eliding, Encrypting, or Compressing Parts of an Envelope

§Decorrelating Envelopes using Salt

§Walking an Envelope’s Hierarchy

  • Envelope::walk Walk the envelope, calling the visitor function for each element.

§Envelope Expressions

§Constructing Expressions, Requests, and Responses

  • [Envelope::new_function] Creates an envelope with a «function» subject.
  • [Envelope::new_parameter] Creates a new envelope containing a ❰parameter❱: value assertion.
  • [Envelope::new_optional_parameter] Optionally adds a ❰parameter❱: value assertion to the envelope.
  • [Envelope::add_parameter] Adds a ❰parameter❱: value assertion to the envelope.
  • [Envelope::add_optional_parameter] Optionally adds a ❰parameter❱: value assertion to the envelope.
  • [Envelope::new_request] Creates an envelope with an ARID subject and a body: «function» assertion.
  • [Envelope::new_response] Creates an envelope with an ARID subject and a result: value assertion.
  • [Envelope::new_response_with_result] Creates an envelope with an ARID subject and a result: value assertion for each provided result.
  • [Envelope::new_error_response_with_id] Creates an envelope with an ARID subject and a error: value assertion.
  • [Envelope::new_error_response] Creates an envelope with an unknown subject and a error: value assertion.

§Decoding Parameters and Results

  • [Envelope::extract_object_for_parameter] Returns the argument for the given parameter, decoded as the given type.
  • [Envelope::extract_objects_for_parameter] Returns an array of arguments for the given parameter, decoded as the given type.
  • [Envelope::result] Returns the object of the result predicate.
  • [Envelope::results] Returns the objects of every result predicate.
  • [Envelope::extract_result] Returns the object of the result predicate, decoded as the given type.
  • [Envelope::extract_results] Returns the objects of every result predicate, decoded as the given type.
  • [Envelope::is_result_ok] Returns whether the result predicate has the KnownValue .ok.
  • [Envelope::error] Returns the error value, decoded as the given type.

Re-exports§

Modules§

Macros§

Structs§

  • Holds unique data from which keys for signing and encryption can be derived.
  • Holds information used to communicate cryptographically with a remote entity.

Traits§

Type Aliases§