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.12.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
Envelope::newCreates an envelope with asubject.Envelope::new_assertionCreates an assertion envelope with apredicateandobject.
Adding Assertions
Adding Assertions with a Predicate and Object
Envelope::add_assertionAdds an assertion to an envelope.Envelope::add_assertion_saltedAdds an optionally salted assertion to an envelope.Envelope::add_optional_assertionOptionally adds an assertion to an envelope.
Adding Assertions with an Assertion Envelope
Envelope::add_assertion_envelopeAdds an assertion envelope to an envelope.Envelope::add_assertion_envelope_saltedAdds an optionally salted assertion envelope to an envelope.Envelope::add_assertion_envelopesAdds a vector of assertion envelopes to an envelope.Envelope::add_optional_assertion_envelope_saltedOptionally adds an assertion envelope to an envelope.
Removing and Replacing Assertions
Envelope::remove_assertionRemoves an assertion from an envelope.Envelope::replace_assertionReplaces an assertion in an envelope.Envelope::replace_subjectReplaces the subject of an envelope.
Queries
Getting the basic parts of an envelope
Envelope::subjectReturns the subject of an envelope.Envelope::predicateIf the envelope’s subject is an assertion return its predicate, else returnNone.Envelope::objectIf the envelope’s subject is an assertion return its object, else returnNone.
Getting assertions on an envelope
Envelope::assertionsReturns the assertions of an envelope.Envelope::has_assertionsReturns whether an envelope has assertions.Envelope::assertionIf the envelope’s subject is an assertion return it, else returnNone.
Getting the specific types of an envelope
Envelope::leafThe envelope’s leaf CBOR object, orNoneif the envelope is not a leaf.Envelope::known_valueThe envelope’s known value, orNoneif the envelope is not a known value.
Determining the type of an envelope
Envelope::is_leafReturns whether an envelope is a leaf.Envelope::is_nodeReturns whether an envelope is a node (whether it has at least one assertion).Envelope::is_wrappedReturns whether an envelope is wrapped.Envelope::is_known_valueReturns whether an envelope is a known value.Envelope::is_assertionReturns whether an envelope is an assertion.Envelope::is_encryptedReturns whether an envelope is encrypted.Envelope::is_compressedReturns whether an envelope is compressed.Envelope::is_elidedReturns whether an envelope is elided.
Determining the type of an envelope’s subject
Envelope::is_subject_assertionReturns whether an envelope’s subject is an assertion.Envelope::is_subject_encryptedReturns whether an envelope’s subject is encrypted.Envelope::is_subject_compressedReturns whether an envelope’s subject is compressed.Envelope::is_subject_elidedReturns whether an envelope’s subject is elided.Envelope::is_subject_obscuredReturns whether an envelope’s subject is obscured.
Getting assertions and parts of assertions
Envelope::assertion_with_predicateReturns the assertion with the given predicate.Envelope::assertions_with_predicateReturns all assertions with the given predicate.Envelope::object_for_predicateReturns the object of the assertion with the given predicate.Envelope::objects_for_predicateReturns the objects of all assertions with the matching predicate.Envelope::elements_countReturns the number of elements in the envelope.
Extracting parts of envelopes as specific types
Envelope::extract_subjectReturns the envelope’s subject, decoded as the given type.Envelope::extract_object_for_predicateReturns the object of the assertion with the given predicate, decoded as the given type.Envelope::extract_objects_for_predicateReturns the objects of all assertions with the matching predicate, decoded as the given type.
Other queries
Envelope::is_internalReturns whether an envelope is internal, that is, if it has child elements.Envelope::is_obscuredReturns whether an envelope is obscured (elided, encrypted, or compressed).
Wrapping and Unwrapping Envelopes
Envelope::wrap_envelopeWraps an envelope in a new envelope.Envelope::unwrap_envelopeUnwraps an envelope.
Formatting Envelopes
Envelope notation
Envelope::formatFormats an envelope in envelope notation.Envelope::format_optFormats an envelope in envelope notation, with optional annotations.
Tree notation
Envelope::tree_formatFormats an envelope in envelope tree notation.Envelope::tree_format_with_targetFormats an envelope in envelope tree notation, highlighting a target set of elements.
CBOR diagnostic notation
Envelope::diagnosticFormats an envelope in CBOR diagnostic notation.Envelope::diagnostic_optFormats an envelope in CBOR diagnostic notation, with optional annotations.
CBOR hexadecimal notation
Envelope::hexFormats an envelope in CBOR hexadecimal notation.Envelope::hex_optFormats an envelope in CBOR hexadecimal notation, with optional annotations.
Working with the Digest Tree
Semantic equivalence
bc_components::DigestProvider::digestReturns the digest of an envelope.Envelope::digestsReturns the set of digests contained in the envelope’s elements, down to the specified level.Envelope::deep_digestsReturns the set of all digests in the envelope.Envelope::shallow_digestsReturns the set of all digests in the envelope, down to its second level.Envelope::is_equivalent_toTests two envelopes for semantic equivalence.
Structural identicality
Envelope::structural_digestProduce a value that will necessarily be different if two envelopes differ structurally, even if they are semantically equivalent.Envelope::is_identical_toTests two envelopes for structural equality.
Signing and Verifying Signatures
Signing
Envelope::sign_withCreates a signature for the envelope’s subject and returns a new envelope with averifiedBy: Signatureassertion.Envelope::sign_with_optCreates a signature for the envelope’s subject and returns a new envelope with averifiedBy: Signatureassertion.Envelope::sign_with_keysCreates several signatures for the envelope’s subject and returns a new envelope with additionalverifiedBy: Signatureassertions.Envelope::sign_with_keys_optCreates several signatures for the envelope’s subject and returns a new envelope with additionalverifiedBy: Signatureassertions.Envelope::sign_with_uncovered_assertionsCreates a signature for the envelope’s subject and returns a new envelope with averifiedBy: Signatureassertion.
Verifying by returning a boolean
Envelope::is_verified_signatureReturns whether the given signature is valid.Envelope::has_signature_fromReturns whether the envelope’s subject has a valid signature from the given public key.Envelope::has_signatures_fromReturns whether the envelope’s subject has a set of signatures.Envelope::has_signatures_from_thresholdReturns whether the envelope’s subject has some threshold of signatures.
Verifying by returning a result
Envelope::verify_signatureChecks whether the given signature is valid for the given public key.Envelope::verify_signature_fromChecks whether the envelope’s subject has a valid signature from the given public key.Envelope::verify_signatures_fromChecks whether the envelope’s subject has a set of signatures.Envelope::verify_signatures_from_thresholdChecks whether the envelope’s subject has some threshold of signatures.
Helpers
Envelope::signaturesReturns an array ofSignatures from all of the envelope’sverifiedBypredicates.Envelope::make_verified_by_signatureConvenience constructor for averifiedBy: Signatureassertion envelope.
Splitting Envelopes with SSKR
Envelope::sskr_splitSplits the envelope into a set of SSKR shares.Envelope::sskr_joinCreates a new envelope resulting from the joining a set of envelopes split by SSKR.
Encryption
Envelope::encrypt_subjectReturns a new envelope with its subject encrypted.Envelope::decrypt_subjectReturns a new envelope with its subject decrypted.
Public Key Encryption
Envelope::add_recipientReturns a new envelope with an addedhasRecipient: SealedMessageassertion.Envelope::recipientsReturns an array ofSealedMessages from all of the envelope’shasRecipientassertions.Envelope::encrypt_subject_to_recipientsReturns an new envelope with its subject encrypted and ahasRecipientEnvelope::encrypt_subject_to_recipientReturns a new envelope with its subject encrypted and ahasRecipientassertion added for therecipient.Envelope::decrypt_to_recipientReturns a new envelope with its subject decrypted using the recipient’sPrivateKeyBase.
Compression
Envelope::compressReturns the compressed variant of this envelope.Envelope::uncompressReturns the uncompressed variant of this envelope.Envelope::compress_subjectReturns this envelope with its subject compressed.Envelope::uncompress_subjectReturns this envelope with its subject uncompressed.
Eliding, Encrypting, or Compressing Parts of an Envelope
-
Envelope::elideReturns the elided variant of this envelope. -
Returns a version of this envelope with the given element(s) elided:
-
Returns a version with all elements except the given element(s) elided:
-
As above, but takes a boolean to determine whether to remove or reveal:
-
Returns a version with the given element(s) elided, encrypted, or compressed:
-
Returns a version with all elements except the given element(s) elided, encrypted, or compressed:
-
As above, but takes a boolean to determine whether to remove or reveal:
-
Envelope::unelideReturns the unelided variant of this envelope, given the envelope that was elided.
Decorrelating Envelopes using Salt
Envelope::add_saltAdd a number of bytes of salt generally proportionate to the size of the object being salted.Envelope::add_salt_with_lenAdd a specified number of bytes of salt.Envelope::add_salt_in_rangeAdd a number of bytes of salt chosen randomly from the given range.
Walking an Envelope’s Hierarchy
Envelope::walkWalk the envelope, calling the visitor function for each element.
Envelope Expressions
Constructing Expressions, Requests, and Responses
Envelope::new_functionCreates an envelope with a«function»subject.Envelope::new_parameterCreates a new envelope containing a❰parameter❱: valueassertion.Envelope::new_optional_parameterOptionally adds a❰parameter❱: valueassertion to the envelope.Envelope::add_parameterAdds a❰parameter❱: valueassertion to the envelope.Envelope::add_optional_parameterOptionally adds a❰parameter❱: valueassertion to the envelope.Envelope::new_requestCreates an envelope with anARIDsubject and abody: «function»assertion.Envelope::new_responseCreates an envelope with anARIDsubject and aresult: valueassertion.Envelope::new_response_with_resultCreates an envelope with anARIDsubject and aresult: valueassertion for each provided result.- [
Envelope::new_error_response_with_id] Creates an envelope with anARIDsubject and aerror: valueassertion. Envelope::new_error_responseCreates an envelope with anunknownsubject and aerror: valueassertion.
Decoding Parameters and Results
Envelope::extract_object_for_parameterReturns the argument for the given parameter, decoded as the given type.Envelope::extract_objects_for_parameterReturns an array of arguments for the given parameter, decoded as the given type.Envelope::resultReturns the object of theresultpredicate.Envelope::resultsReturns the objects of everyresultpredicate.Envelope::extract_resultReturns the object of theresultpredicate, decoded as the given type.Envelope::extract_resultsReturns the objects of everyresultpredicate, decoded as the given type.Envelope::is_result_okReturns whether theresultpredicate has theKnownValue.ok.Envelope::errorReturns the error value, decoded as the given type.
Re-exports
pub use base::Assertion;pub use base::Envelope;pub use base::EnvelopeEncodable;pub use base::EnvelopeDecodable;pub use base::EnvelopeCodable;pub use base::EnvelopeError;pub use base::FormatContext;pub use base::GLOBAL_FORMAT_CONTEXT;pub use base::elide;pub use base::elide::ObscureAction;pub use extension::known_values;pub use extension::known_values::known_value;pub use extension::known_values::KnownValue;pub use extension::known_values::KNOWN_VALUES;pub use extension::known_values::KnownValuesStore;pub use extension::expression;pub use extension::expression::functions;pub use extension::expression::parameters;pub use extension::expression::Function;pub use extension::expression::Parameter;
Modules
Macros
- A macro that declares a function at compile time.
- A macro that implements EnvelopeEncodable for a type and its reference.
- A macro that declares a known value at compile time.
- A macro that declares a parameter at compile time.
- A macro to access the global format context.