bc_envelope::base::envelope

Struct Envelope

Source
pub struct Envelope(/* private fields */);
Expand description

A flexible container for structured data.

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

Implementations§

Source§

impl Envelope

Support for adding assertions.

Source

pub fn add_assertion( &self, predicate: impl EnvelopeEncodable, object: impl EnvelopeEncodable, ) -> Self

Returns the result of adding the given assertion to the envelope.

Source

pub fn add_assertion_envelope( &self, assertion_envelope: impl EnvelopeEncodable, ) -> Result<Self>

Returns the result of adding the given assertion to the envelope.

The assertion envelope must be a valid assertion envelope, or an obscured variant (elided, encrypted, compressed) of one.

Source

pub fn add_assertion_envelopes(&self, assertions: &[Self]) -> Result<Self>

Returns the result of adding the given array of assertions to the envelope.

Each assertion envelope must be a valid assertion envelope, or an obscured variant (elided, encrypted, compressed) of one.

Source

pub fn add_optional_assertion_envelope( &self, assertion: Option<Self>, ) -> Result<Self>

If the optional assertion is present, returns the result of adding it to the envelope. Otherwise, returns the envelope unchanged.

The assertion envelope must be a valid assertion envelope, or an obscured variant (elided, encrypted, compressed) of one.

Source

pub fn add_optional_assertion( &self, predicate: impl EnvelopeEncodable, object: Option<impl EnvelopeEncodable>, ) -> Self

If the optional object is present, returns the result of adding the assertion to the envelope. Otherwise, returns the envelope unchanged.

Source

pub fn add_assertions(&self, envelopes: &[Self]) -> Self

Returns a new Envelope with the given array of assertions added.

  • Parameter assertions: The assertions to add.
Source§

impl Envelope

Support for adding conditional assertions.

Source

pub fn add_assertion_if( &self, condition: bool, predicate: impl EnvelopeEncodable, object: impl EnvelopeEncodable, ) -> Self

If the condition is true, returns the result of adding the given assertion to the envelope. Otherwise, returns the envelope unchanged.

Source

pub fn add_assertion_envelope_if( &self, condition: bool, assertion_envelope: Self, ) -> Result<Self>

If the condition is true, returns the result of adding the given assertion to the envelope. Otherwise, returns the envelope unchanged.

Source§

impl Envelope

Support for adding assertions with salt.

Source

pub fn add_assertion_salted<P, O>( &self, predicate: P, object: O, salted: bool, ) -> Self

Returns the result of adding the given assertion to the envelope, optionally salting it.

Source

pub fn add_assertion_envelope_salted( &self, assertion_envelope: Self, salted: bool, ) -> Result<Self>

Returns the result of adding the given assertion to the envelope, optionally salting it.

The assertion envelope must be a valid assertion envelope, or an obscured variant (elided, encrypted, compressed) of one.

Source

pub fn add_optional_assertion_envelope_salted( &self, assertion: Option<Self>, salted: bool, ) -> Result<Self>

If the optional assertion is present, returns the result of adding it to the envelope, optionally salting it. Otherwise, returns the envelope unchanged.

The assertion envelope must be a valid assertion envelope, or an obscured variant (elided, encrypted, compressed) of one.

Source

pub fn add_assertions_salted(&self, assertions: &[Self], salted: bool) -> Self

Source§

impl Envelope

Support for removing or replacing assertions.

Source

pub fn remove_assertion(&self, target: Self) -> Self

Returns a new envelope with the given assertion removed. If the assertion does not exist, returns the same envelope.

Source

pub fn replace_assertion( &self, assertion: Self, new_assertion: Self, ) -> Result<Self>

Returns a new envelope with the given assertion replaced by the provided one. If the targeted assertion does not exist, returns the same envelope.

Source

pub fn replace_subject(&self, subject: Self) -> Self

Returns a new envelope with its subject replaced by the provided one.

Source§

impl Envelope

Support for working with the digest tree of an Envelope.

Source

pub fn digests(&self, level_limit: usize) -> HashSet<Digest>

Returns the set of digests contained in the envelope’s elements, down to the specified level.

The digest of the envelope is included as well as the digest of the envelope’s subject (if it is different).

If no levelLimit is provided, all digests in the envelope will be returned.

A levelLimit of zero will return no digests.

§Arguments
  • levelLimit - Return digests at levels below this value.
§Returns
  • A set of digests down to levelLimit.
Source

pub fn deep_digests(&self) -> HashSet<Digest>

Returns the set of all digests in the envelope.

Source

pub fn shallow_digests(&self) -> HashSet<Digest>

Returns the set of all digests in the envelope, down to its second level.

Source

pub fn structural_digest(&self) -> Digest

Produce a value that will necessarily be different if two envelopes differ structurally, even if they are semantically equivalent.

Comparing the digest field of two envelopes (or calling isEquivalent(to:)) tests whether two envelopes are semantically equivalent. This is accomplished by simply comparing the top level digests of the envelopes for equality, and has a complexity of O(1).

This means that two envelopes are considered equivalent if they contain identical information in their completely unencrypted and unelided form.

Some applications need to determine whether two envelopes are not only semantically equivalent, but also structurally identical. Two envelopes that are not semantically equivalent cannot be structurally identical, but two envelopes that are semantically equivalent may or may not be structurally identical.

The structural_digest attribute is used to produce a value that will necessarily be different if two envelopes differ structurally, even if they are semantically equivalent. It has a complexity of O(m + n) where m and n are the number of elements in each of the two envelopes when they are semantically equivalent. It is recommended that envelopes be compared for structural equality by calling isIdentical(to:) as this short-circuits to false in cases where the compared envelopes are not semantically equivalent.

Source

pub fn is_equivalent_to(&self, other: &Self) -> bool

Tests two envelopes for semantic equivalence.

Calling e1.is_equivalent_to(e2) has a complexity of O(1) and simply compares the two envelope’s digests. The means that two envelopes with certain structural differences (e.g., one envelope is partially elided and the other is not) will still test as equivalent.

Source

pub fn is_identical_to(&self, other: &Self) -> bool

Tests two envelopes for structural equality.

Calling e1.is_identical_to(e2) has a complexity of O(1) if the envelopes are not semantically equivalent (that is, their top-level digests are different, and thus they must have different structures) and a complexity of O(m + n) where m and n are the number of elements in each of the two envelopes when they are semantically equivalent.

Source§

impl Envelope

Source

pub fn case(&self) -> &EnvelopeCase

Source§

impl Envelope

Source

pub fn false() -> Self

Source

pub fn true() -> Self

Source

pub fn null() -> Self

Source

pub fn is_false(&self) -> bool

Source

pub fn is_true(&self) -> bool

Source

pub fn is_null(&self) -> bool

Source§

impl Envelope

Support for basic envelope creation.

Source

pub fn new(subject: impl EnvelopeEncodable) -> Self

Creates an envelope with a subject, which can be any instance that implements EnvelopeEncodable.

Source

pub fn new_or_null(subject: Option<impl EnvelopeEncodable>) -> Self

Creates an envelope with a subject, which can be any instance that implements EnvelopeEncodable.

If subject is None, returns a null envelope.

Source

pub fn new_or_none(subject: Option<impl EnvelopeEncodable>) -> Option<Self>

Creates an envelope with a subject, which can be any instance that implements EnvelopeEncodable.

If subject is None, returns None.

Source

pub fn new_assertion( predicate: impl EnvelopeEncodable, object: impl EnvelopeEncodable, ) -> Self

Creates an assertion envelope with a predicate and object, each of which can be any instance that implements EnvelopeEncodable.

Source§

impl Envelope

Support for eliding elements from envelopes.

This includes eliding, encrypting and compressing (obscuring) elements.

Source

pub fn elide(&self) -> Self

Returns the elided variant of this envelope.

Returns the same envelope if it is already elided.

Source

pub fn elide_removing_set_with_action( &self, target: &HashSet<Digest>, action: &ObscureAction, ) -> Self

Returns a version of this envelope with elements in the target set elided.

  • Parameters:

    • target: The target set of digests.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_removing_set(&self, target: &HashSet<Digest>) -> Self

Returns a version of this envelope with elements in the target set elided.

  • Parameters:

    • target: The target set of digests.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_removing_array_with_action( &self, target: &[&dyn DigestProvider], action: &ObscureAction, ) -> Self

Returns a version of this envelope with elements in the target set elided.

  • Parameters:

    • target: An array of DigestProviders.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_removing_array(&self, target: &[&dyn DigestProvider]) -> Self

Returns a version of this envelope with elements in the target set elided.

  • Parameters:

    • target: An array of DigestProviders.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_removing_target_with_action( &self, target: &dyn DigestProvider, action: &ObscureAction, ) -> Self

Returns a version of this envelope with the target element elided.

  • Parameters:

    • target: A DigestProvider.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_removing_target(&self, target: &dyn DigestProvider) -> Self

Returns a version of this envelope with the target element elided.

  • Parameters:

    • target: A DigestProvider.
  • Returns: The elided envelope.

Source

pub fn elide_revealing_set_with_action( &self, target: &HashSet<Digest>, action: &ObscureAction, ) -> Self

Returns a version of this envelope with elements not in the target set elided.

  • Parameters:

    • target: The target set of digests.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_revealing_set(&self, target: &HashSet<Digest>) -> Self

Returns a version of this envelope with elements not in the target set elided.

  • Parameters:

    • target: The target set of digests.
  • Returns: The elided envelope.

Source

pub fn elide_revealing_array_with_action( &self, target: &[&dyn DigestProvider], action: &ObscureAction, ) -> Self

Returns a version of this envelope with elements not in the target set elided.

  • Parameters:

    • target: An array of DigestProviders.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_revealing_array(&self, target: &[&dyn DigestProvider]) -> Self

Returns a version of this envelope with elements not in the target set elided.

  • Parameters:

    • target: An array of DigestProviders.
  • Returns: The elided envelope.

Source

pub fn elide_revealing_target_with_action( &self, target: &dyn DigestProvider, action: &ObscureAction, ) -> Self

Returns a version of this envelope with all elements except the target element elided.

  • Parameters:

    • target: A DigestProvider.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_revealing_target(&self, target: &dyn DigestProvider) -> Self

Returns a version of this envelope with all elements except the target element elided.

  • Parameters:

    • target: A DigestProvider.
  • Returns: The elided envelope.

Source

pub fn elide_set_with_action( &self, target: &HashSet<Digest>, is_revealing: bool, action: &ObscureAction, ) -> Self

Returns an elided version of this envelope.

  • Parameters:

    • target: The target set of digests.
    • isRevealing: If true, the target set contains the digests of the elements to leave revealed. If it is false, the target set contains the digests of the elements to elide.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_set(&self, target: &HashSet<Digest>, is_revealing: bool) -> Self

Returns an elided version of this envelope.

  • Parameters:

    • target: The target set of digests.
    • isRevealing: If true, the target set contains the digests of the elements to leave revealed. If it is false, the target set contains the digests of the elements to elide.
  • Returns: The elided envelope.

Source

pub fn elide_array_with_action( &self, target: &[&dyn DigestProvider], is_revealing: bool, action: &ObscureAction, ) -> Self

Returns an elided version of this envelope.

  • Parameters:

    • target: An array of DigestProviders.
    • isRevealing: If true, the target set contains the digests of the elements to leave revealed. If it is false, the target set contains the digests of the elements to elide.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_array( &self, target: &[&dyn DigestProvider], is_revealing: bool, ) -> Self

Returns an elided version of this envelope.

  • Parameters:

    • target: An array of DigestProviders.
    • isRevealing: If true, the target set contains the digests of the elements to leave revealed. If it is false, the target set contains the digests of the elements to elide.
  • Returns: The elided envelope.

Source

pub fn elide_target_with_action( &self, target: &dyn DigestProvider, is_revealing: bool, action: &ObscureAction, ) -> Self

Returns an elided version of this envelope.

  • Parameters:

    • target: A DigestProvider.
    • isRevealing: If true, the target is the element to leave revealed, eliding all others. If it is false, the target is the element to elide, leaving all others revealed.
    • action: Perform the specified action (elision, encryption or compression).
  • Returns: The elided envelope.

Source

pub fn elide_target( &self, target: &dyn DigestProvider, is_revealing: bool, ) -> Self

Returns an elided version of this envelope.

  • Parameters:

    • target: A DigestProvider.
    • isRevealing: If true, the target is the element to leave revealed, eliding all others. If it is false, the target is the element to elide, leaving all others revealed.
  • Returns: The elided envelope.

Source

pub fn unelide(&self, envelope: impl Into<Envelope>) -> Result<Self>

Returns the unelided variant of this envelope.

Returns the same envelope if it is already unelided.

Source§

impl Envelope

Source

pub fn try_from_cbor(cbor: CBOR) -> Result<Self>

Source

pub fn try_from_cbor_data(data: Vec<u8>) -> Result<Self>

Source§

impl Envelope

Support for various queries on envelopes.

Source

pub fn subject(&self) -> Self

The envelope’s subject.

For an envelope with no assertions, returns the same envelope.

Source

pub fn assertions(&self) -> Vec<Self>

The envelope’s assertions.

Source

pub fn has_assertions(&self) -> bool

true if the envelope has at least one assertion, false otherwise.

Source

pub fn as_assertion(&self) -> Option<Self>

If the envelope’s subject is an assertion return it, else return None.

Source

pub fn try_assertion(&self) -> Result<Self>

If the envelope’s subject is an assertion return it, else return an error.

Source

pub fn as_predicate(&self) -> Option<Self>

The envelope’s predicate, or None if the envelope is not an assertion.

Source

pub fn try_predicate(&self) -> Result<Self>

The envelope’s predicate, or an error if the envelope is not an assertion.

Source

pub fn as_object(&self) -> Option<Self>

The envelope’s object, or None if the envelope is not an assertion.

Source

pub fn try_object(&self) -> Result<Self>

The envelope’s object, or an error if the envelope is not an assertion.

Source

pub fn as_leaf(&self) -> Option<CBOR>

The envelope’s leaf CBOR object, or None if the envelope is not a leaf.

Source

pub fn try_leaf(&self) -> Result<CBOR>

The envelope’s leaf CBOR object, or an error if the envelope is not a leaf.

Source

pub fn as_known_value(&self) -> Option<&KnownValue>

The envelope’s KnownValue, or None if the envelope is not case ::KnownValue.

Source

pub fn try_known_value(&self) -> Result<&KnownValue>

The envelope’s KnownValue, or an error if the envelope is not case ::KnownValue.

Source

pub fn is_leaf(&self) -> bool

true if the envelope is case ::Leaf, false otherwise.

Source

pub fn is_node(&self) -> bool

true if the envelope is case ::Node, false otherwise.

Source

pub fn is_wrapped(&self) -> bool

true if the envelope is case ::Wrapped, false otherwise.

Source

pub fn is_known_value(&self) -> bool

true if the envelope is case ::KnownValue, false otherwise.

Source

pub fn is_assertion(&self) -> bool

true if the envelope is case ::Assertion, false otherwise.

Source

pub fn is_encrypted(&self) -> bool

true if the envelope is case ::Encrypted, false otherwise.

Source

pub fn is_compressed(&self) -> bool

true if the envelope is case ::Compressed, false otherwise.

Source

pub fn is_elided(&self) -> bool

true if the envelope is case ::Elided, false otherwise.

Source

pub fn is_subject_assertion(&self) -> bool

true if the subject of the envelope is an assertion, false otherwise.

Source

pub fn is_subject_encrypted(&self) -> bool

true if the subject of the envelope has been encrypted, false otherwise.

Source

pub fn is_subject_compressed(&self) -> bool

true if the subject of the envelope has been compressed, false otherwise.

Source

pub fn is_subject_elided(&self) -> bool

true if the subject of the envelope has been elided, false otherwise.

Source

pub fn is_subject_obscured(&self) -> bool

true if the subject of the envelope has been encrypted, elided, or compressed, false otherwise.

Obscured assertion envelopes may exist in the list of an envelope’s assertions.

Source

pub fn is_internal(&self) -> bool

true if the envelope is internal, that is, it has child elements, or false if it is a leaf node.

Internal elements include .node, .wrapped, and .assertion.

Source

pub fn is_obscured(&self) -> bool

true if the envelope is encrypted, elided, or compressed; false otherwise.

Source

pub fn extract_subject<T>(&self) -> Result<T>
where T: Any + TryFrom<CBOR, Error = Error>,

Returns the envelope’s subject, decoded as the given type.

If the encoded type doesn’t match the given type, returns Error::InvalidFormat.

Source

pub fn assertions_with_predicate( &self, predicate: impl EnvelopeEncodable, ) -> Vec<Self>

Returns all assertions with the given predicate. Match by comparing digests.

Source

pub fn assertion_with_predicate( &self, predicate: impl EnvelopeEncodable, ) -> Result<Self>

Returns the assertion with the given predicate.

Returns an error if there is no matching predicate or multiple matching predicates.

Source

pub fn optional_assertion_with_predicate( &self, predicate: impl EnvelopeEncodable, ) -> Result<Option<Self>>

Returns the assertion with the given predicate, or None if there is no matching predicate.

Returns an error if there are multiple matching predicates.

Source

pub fn object_for_predicate( &self, predicate: impl EnvelopeEncodable, ) -> Result<Self>

Returns the object of the assertion with the given predicate.

Returns an error if there is no matching predicate or multiple matching predicates.

Source

pub fn optional_object_for_predicate( &self, predicate: impl EnvelopeEncodable, ) -> Result<Option<Self>>

Returns the object of the assertion with the given predicate, or None if there is no matching predicate.

Returns an error if there are multiple matching predicates.

Source

pub fn extract_object<T: TryFrom<CBOR, Error = Error> + 'static>( &self, ) -> Result<T>

Returns the object of the assertion, decoded as the given type.

Returns an error if the envelope is not an assertion. Returns an error if the encoded type doesn’t match the given type.

Source

pub fn extract_predicate<T: TryFrom<CBOR, Error = Error> + 'static>( &self, ) -> Result<T>

Returns the predicate of the assertion, decoded as the given type.

Returns an error if the envelope is not an assertion. Returns an error if the encoded type doesn’t match the given type.

Source

pub fn extract_object_for_predicate<T: TryFrom<CBOR, Error = Error> + 'static>( &self, predicate: impl EnvelopeEncodable, ) -> Result<T>

Returns the object of the assertion with the given predicate, decoded as the given type.

Returns an error if there is no matching predicate or multiple matching predicates. Returns an error if the encoded type doesn’t match the given type.

Source

pub fn extract_optional_object_for_predicate<T: TryFrom<CBOR, Error = Error> + 'static>( &self, predicate: impl EnvelopeEncodable, ) -> Result<Option<T>>

Returns the object of the assertion with the given predicate, or None if there is no matching predicate.

Returns an error if there are multiple matching predicates.

Source

pub fn extract_object_for_predicate_with_default<T: TryFrom<CBOR, Error = Error> + 'static>( &self, predicate: impl EnvelopeEncodable, default: T, ) -> Result<T>

Returns the object of the assertion with the given predicate, or a default value if there is no matching predicate.

Source

pub fn objects_for_predicate( &self, predicate: impl EnvelopeEncodable, ) -> Vec<Self>

Returns the objects of all assertions with the matching predicate.

Source

pub fn extract_objects_for_predicate<T: TryFrom<CBOR, Error = Error> + 'static>( &self, predicate: impl EnvelopeEncodable, ) -> Result<Vec<T>>

Returns the objects of all assertions with the matching predicate, decoded as the given type.

Returns an error if the encoded type doesn’t match the given type.

Source

pub fn elements_count(&self) -> usize

Returns the number of structural elements in the envelope, including itself.

Source§

impl Envelope

Support for the various text output formats for Envelope.

Source

pub fn format_opt(&self, context: Option<&FormatContext>) -> String

Returns the envelope notation for this envelope.

Source

pub fn format(&self) -> String

Returns the envelope notation for this envelope.

Uses the current format context.

Source

pub fn format_flat(&self) -> String

Returns the envelope notation for this envelope in flat format.

In flat format, the envelope is printed on a single line.

Source

pub fn diagnostic_annotated(&self) -> String

Returns the CBOR diagnostic notation for this envelope, with annotations.

See RFC-8949 §8 for information on CBOR diagnostic notation.

Source

pub fn diagnostic(&self) -> String

Returns the CBOR diagnostic notation for this envelope.

Uses the current format context.

See RFC-8949 §8 for information on CBOR diagnostic notation.

Source

pub fn hex_opt(&self, annotate: bool, context: Option<&FormatContext>) -> String

Returns the CBOR hex dump of this envelope.

See RFC-8949 for information on the CBOR binary format.

Source

pub fn hex(&self) -> String

Returns the CBOR hex dump of this envelope.

Uses the current format context.

See RFC-8949 for information on the CBOR binary format.

Source§

impl Envelope

Support for tree-formatting envelopes.

Source

pub fn tree_format_opt( &self, hide_nodes: bool, context: Option<&FormatContext>, ) -> String

Source

pub fn tree_format(&self, hide_nodes: bool) -> String

Source

pub fn tree_format_with_target_opt( &self, hide_nodes: bool, highlighting_target: &HashSet<Digest>, context: Option<&FormatContext>, ) -> String

Source

pub fn tree_format_with_target( &self, hide_nodes: bool, highlighting_target: &HashSet<Digest>, ) -> String

Source§

impl Envelope

Source

pub fn short_id(&self) -> String

Source

pub fn summary(&self, max_length: usize, context: &FormatContext) -> String

Source§

impl Envelope

Functions for walking an envelope.

Source

pub fn walk<Parent: Clone>(&self, hide_nodes: bool, visit: &Visitor<'_, Parent>)

Walk the envelope, calling the visitor function for each element.

If hide_nodes is true, then the visitor function will not be called for nodes, but only for the children of nodes.

Source§

impl Envelope

Support for wrapping and unwrapping envelopes.

Source

pub fn wrap_envelope(&self) -> Self

Return a new envelope which wraps the current envelope.

Source

pub fn unwrap_envelope(&self) -> Result<Self>

Unwraps and returns the inner envelope.

Returns an error if this is not a wrapped envelope.

Source§

impl Envelope

Source

pub fn new_attachment( payload: impl EnvelopeEncodable, vendor: &str, conforms_to: Option<&str>, ) -> Self

Returns a new attachment envelope.

The payload envelope has a 'vendor': String assertion and an optional 'conformsTo': String assertion.

Source

pub fn add_attachment( &self, payload: impl EnvelopeEncodable, vendor: &str, conforms_to: Option<&str>, ) -> Self

Returns a new envelope with an added 'attachment': Envelope assertion.

The payload envelope has a 'vendor': String assertion and an optional 'conformsTo': String assertion.

Source§

impl Envelope

Source

pub fn attachment_payload(&self) -> Result<Self>

Returns the payload of the given attachment envelope.

Source

pub fn attachment_vendor(&self) -> Result<String>

Returns the vendor of the given attachment envelope.

Source

pub fn attachment_conforms_to(&self) -> Result<Option<String>>

Returns the conformsTo of the given attachment envelope.

Source

pub fn attachments_with_vendor_and_conforms_to( &self, vendor: Option<&str>, conforms_to: Option<&str>, ) -> Result<Vec<Self>>

Searches the envelope’s attachments for any that match the given vendor and conformsTo.

If vendor is None, matches any vendor. If conformsTo is None, matches any conformsTo. If both are None, matches any attachment. On success, returns a vector of matching attachments. Returns an error if any of the attachments are invalid.

Source

pub fn attachments(&self) -> Result<Vec<Self>>

Source

pub fn validate_attachment(&self) -> Result<()>

Validates the given attachment envelope.

Ensures:

  • The attachment envelope is a valid assertion envelope.
  • The attachment envelope’s predicate is known_values::ATTACHMENT.
  • The attachment envelope’s object is an envelope.
  • The attachment envelope’s object has a 'vendor': String assertion.
  • The attachment envelope’s object has an optional 'conformsTo': String assertion.
Source

pub fn attachment_with_vendor_and_conforms_to( &self, vendor: Option<&str>, conforms_to: Option<&str>, ) -> Result<Self>

Searches the envelope’s attachments for any that match the given vendor and conformsTo.

If vendor is None, matches any vendor. If conformsTo is None, matches any conformsTo. If both are None, matches any attachment. On success, returns the first matching attachment. Returns an error if more than one attachment matches, or if any of the attachments are invalid.

Source§

impl Envelope

Support for compressing and uncompressing envelopes.

Source

pub fn compress(&self) -> Result<Self>

Returns the compressed variant of this envelope.

Returns the same envelope if it is already compressed.

Source

pub fn uncompress(&self) -> Result<Self>

Returns the uncompressed variant of this envelope.

Returns the same envelope if it is already uncompressed.

Source

pub fn compress_subject(&self) -> Result<Self>

Returns this envelope with its subject compressed.

Returns the same envelope if its subject is already compressed.

Source

pub fn uncompress_subject(&self) -> Result<Self>

Returns this envelope with its subject uncompressed.

Returns the same envelope if its subject is already uncompressed.

Source§

impl Envelope

Support for encrypting and decrypting envelopes.

Source

pub fn encrypt_subject(&self, key: &SymmetricKey) -> Result<Self>

Returns a new envelope with its subject encrypted.

Assertions are not encrypted. To encrypt an entire envelope including its assertions it must first be wrapped using the wrap() method.

  • Parameters:

    • key: The SymmetricKey to be used to encrypt the subject.
  • Returns: The encrypted envelope.

  • Throws: If the envelope is already encrypted.

Source

pub fn decrypt_subject(&self, key: &SymmetricKey) -> Result<Self>

Returns a new envelope with its subject decrypted.

Source§

impl Envelope

Source

pub fn encrypt(&self, key: &SymmetricKey) -> Envelope

Source

pub fn decrypt(&self, key: &SymmetricKey) -> Result<Envelope>

Source§

impl Envelope

Source

pub fn unknown() -> Self

Source

pub fn ok() -> Self

Source§

impl Envelope

Support for inclusions proofs.

Source

pub fn proof_contains_set( &self, target: &HashSet<Digest, RandomState>, ) -> Option<Envelope>

Returns a proof that this envelope includes every element in the target set.

§Parameters
  • target: The elements if this envelope that the proof must include.
§Returns

The proof, of None if it cannot be proven that the envelope contains every element in the target set.

Source

pub fn proof_contains_target( &self, target: &dyn DigestProvider, ) -> Option<Envelope>

Returns a proof that this envelope includes the target element.

§Parameters
  • target: The element of this envelope that the proof must include.
§Returns

The proof, of None if it cannot be proven that the envelope contains the targeted element.

Source

pub fn confirm_contains_set( &self, target: &HashSet<Digest, RandomState>, proof: &Envelope, ) -> bool

Confirms whether or not this envelope contains the target set using the given inclusion proof.

§Parameters
  • target: The target elements that need to be proven exist somewhere in this envelope, even if they were elided or encrypted.
  • proof: The inclusion proof to use.
§Returns

true if every element of target is in this envelope as shown by proof, false otherwise.

Source

pub fn confirm_contains_target( &self, target: &dyn DigestProvider, proof: &Envelope, ) -> bool

Confirms whether or not this envelope contains the target element using the given inclusion proof.

§Parameters
  • target: The target element that needs to be proven to exist somewhere in this envelope, even if it was elided or encrypted.
  • proof: The inclusion proof to use.
§Returns

true if target is in this envelope as shown by proof, false otherwise.

Source§

impl Envelope

Support for public key encryption.

Source

pub fn add_recipient( &self, recipient: &dyn Encrypter, content_key: &SymmetricKey, ) -> Self

Returns a new envelope with an added hasRecipient: SealedMessage assertion.

The SealedMessage contains the contentKey encrypted to the recipient’s PublicKeyBase.

  • Parameters:

    • recipient: The PublicKeyBase of the recipient.
    • contentKey: The SymmetricKey that was used to encrypt the subject.
  • Returns: The new envelope.

Source

pub fn recipients(&self) -> Result<Vec<SealedMessage>>

Returns an array of SealedMessages from all of the envelope’s hasRecipient assertions.

  • Throws: Throws an exception if any hasRecipient assertions do not have a SealedMessage as their object.
Source

pub fn encrypt_subject_to_recipients( &self, recipients: &[&dyn Encrypter], ) -> Result<Self>

Returns an new envelope with its subject encrypted and a hasRecipient assertion added for each of the recipients.

Generates an ephemeral symmetric key which is used to encrypt the subject and which is then encrypted to each recipient’s public key.

  • Parameter recipients: An array of PublicKeyBase, one for each potential recipient.

  • Returns: The encrypted envelope.

  • Throws: If the envelope is already encrypted.

Source

pub fn encrypt_subject_to_recipient( &self, recipient: &dyn Encrypter, ) -> Result<Self>

Returns a new envelope with its subject encrypted and a hasRecipient assertion added for the recipient.

Generates an ephemeral symmetric key which is used to encrypt the subject and which is then encrypted to the recipient’s public key.

  • Parameter recipient: The recipient’s PublicKeyBase.

  • Returns: The encrypted envelope.

Source

pub fn decrypt_subject_to_recipient( &self, recipient: &PrivateKeyBase, ) -> Result<Self>

Returns a new envelope with its subject decrypted using the recipient’s PrivateKeyBase.

  • Parameter recipient: The recipient’s PrivateKeyBase

  • Returns: The decryptedEnvelope.

  • Throws: If a SealedMessage for recipient is not found among the hasRecipient assertions on the envelope.

Source§

impl Envelope

Source

pub fn encrypt_to_recipient(&self, recipient: &dyn Encrypter) -> Envelope

Source

pub fn decrypt_to_recipient( &self, recipient: &PrivateKeyBase, ) -> Result<Envelope>

Source§

impl Envelope

Support for signing envelopes and verifying signatures.

Source

pub fn add_signature(&self, private_key: &dyn Signer) -> Self

Creates a signature for the envelope’s subject and returns a new envelope with a 'signed': Signature assertion.

  • Parameters:

    • private_key: The signer’s SigningPrivateKey
  • Returns: The signed envelope.

Source

pub fn make_signed_assertion( &self, signature: &Signature, note: Option<&str>, ) -> Self

Convenience constructor for a 'signed': Signature assertion envelope.

  • Parameters:

    • signature: The Signature for the object.
    • note: An optional note to be added to the Signature.
  • Returns: The new assertion envelope.

Source

pub fn is_verified_signature( &self, signature: &Signature, public_key: &dyn Verifier, ) -> bool

Returns whether the given signature is valid.

  • Parameters:

    • signature: The Signature to be checked.
    • public_key: The potential signer’s Verifier.
  • Returns: true if the signature is valid for this envelope’s subject, false otherwise.

Source

pub fn verify_signature( &self, signature: &Signature, public_key: &dyn Verifier, ) -> Result<Self>

Checks whether the given signature is valid for the given public key.

Used for chaining a series of operations that include validating signatures.

  • Parameters:

    • signature: The Signature to be checked.
    • public_key: The potential signer’s Verifier.
  • Returns: This envelope.

  • Throws: Throws EnvelopeError.unverifiedSignature if the signature is not valid. valid.

Source

pub fn has_signature_from(&self, public_key: &dyn Verifier) -> Result<bool>

Returns whether the envelope’s subject has a valid signature from the given public key.

  • Parameters:

    • public_key: The potential signer’s Verifier.
  • Returns: true if any signature is valid for this envelope’s subject, false otherwise.

  • Throws: Throws an exception if any 'signed' assertion doesn’t contain a valid Signature as its object.

Source

pub fn has_signature_from_returning_metadata( &self, public_key: &dyn Verifier, ) -> Result<Option<Envelope>>

Returns whether the envelope’s subject has a valid signature from the given public key by returning the signature metadata.

  • Parameters:

  • public_key: The potential signer’s Verifier.

  • Returns: The metadata envelope if the signature is valid, None otherwise.

Source

pub fn verify_signature_from(&self, public_key: &dyn Verifier) -> Result<Self>

Returns whether the envelope’s subject has a valid signature from the given public key.

Used for chaining a series of operations that include validating signatures.

  • Parameters:

    • public_key: The potential signer’s Verifier.
  • Returns: This envelope.

  • Throws: Throws EnvelopeError.unverifiedSignature if the signature is not valid. valid.

Source

pub fn verify_signature_from_returning_metadata( &self, public_key: &dyn Verifier, ) -> Result<Envelope>

Source

pub fn has_signatures_from(&self, public_keys: &[&dyn Verifier]) -> Result<bool>

Checks whether the envelope’s subject has a set of signatures.

Source

pub fn has_signatures_from_threshold( &self, public_keys: &[&dyn Verifier], threshold: Option<usize>, ) -> Result<bool>

Returns whether the envelope’s subject has some threshold of signatures.

If threshold is nil, then all signers in public_keys must have signed. If threshold is 1, then at least one signer must have signed.

  • Parameters:

    • public_keys: An array of potential signers’ Verifiers.
    • threshold: Optional minimum number of signers.
  • Returns: true if the threshold of valid signatures is met, false otherwise.

  • Throws: Throws an exception if any 'signed' assertion doesn’t contain a valid Signature as its object.

Source

pub fn verify_signatures_from_threshold( &self, public_keys: &[&dyn Verifier], threshold: Option<usize>, ) -> Result<Self>

Checks whether the envelope’s subject has some threshold of signatures.

If threshold is nil, then all signers in public_keys must have signed. If threshold is 1, then at least one signer must have signed.

Used for chaining a series of operations that include validating signatures.

  • Parameters:

    • public_keys: An array of potential signers’ Verifiers.
    • threshold: Optional minimum number of signers.
  • Returns: This envelope.

  • Throws: Throws an exception if the threshold of valid signatures is not met.

Source

pub fn verify_signatures_from( &self, public_keys: &[&dyn Verifier], ) -> Result<Self>

Checks whether the envelope’s subject has a set of signatures.

Source§

impl Envelope

Source

pub fn sign(&self, signer: &dyn Signer) -> Envelope

Source

pub fn verify(&self, verifier: &dyn Verifier) -> Result<Envelope>

Source

pub fn verify_returning_metadata( &self, verifier: &dyn Verifier, ) -> Result<(Envelope, Envelope)>

Source§

impl Envelope

Support for decorrelation of envelopes using salt.

Source

pub fn add_salt(&self) -> Self

Add a number of bytes of salt generally proportionate to the size of the object being salted.

Source

pub fn add_salt_instance(&self, salt: Salt) -> Self

Add the given Salt as an assertion

Source

pub fn add_salt_with_len(&self, count: usize) -> Result<Self>

Add a specified number of bytes of salt.

Returns an error if the number of bytes is less than 8.

Source

pub fn add_salt_in_range(&self, range: RangeInclusive<usize>) -> Result<Self>

Add a number of bytes of salt chosen randomly from the given range.

Returns an error if the minimum number of bytes is less than 8.

Source§

impl Envelope

Support for splitting and combining envelopes using SSKR (Shamir’s Secret Sharing).

Source

pub fn sskr_split( &self, spec: &SSKRSpec, content_key: &SymmetricKey, ) -> Result<Vec<Vec<Envelope>>>

Splits the envelope into a set of SSKR shares.

The envelope subject should already be encrypted by a specific SymmetricKey known as the content_key.

Each returned envelope will have an sskrShare: SSKRShare assertion added to it.

  • Parameters:

    • spec: The SSKR split specification.
    • content_key: The SymmetricKey used to encrypt the envelope’s subject.
  • Returns: An array of arrays. Each element of the outer array represents an SSKR group, and the elements of each inner array are the envelope with a unique sskrShare: SSKRShare assertion added to each.

Source

pub fn sskr_split_flattened( &self, spec: &SSKRSpec, content_key: &SymmetricKey, ) -> Result<Vec<Envelope>>

Splits the envelope into a set of SSKR shares.

The envelope subject should already be encrypted by a specific SymmetricKey known as the content_key.

Each returned envelope will have an sskrShare: SSKRShare assertion added to it.

  • Parameters:

    • spec: The SSKR split specification.
    • content_key: The SymmetricKey used to encrypt the envelope’s subject.
  • Returns: An array of shares. Each element of the array represents an SSKR share.

Source

pub fn sskr_join(envelopes: &[&Envelope]) -> Result<Envelope>

Creates a new envelope resulting from the joining a set of envelopes split by SSKR.

Given a set of envelopes that are ostensibly all part of the same SSKR split, this method attempts to reconstruct the original envelope subject. It will try all present sskrShare: SSKRShare assertions, grouped by split ID, to achieve a threshold of shares. If it can do so successfully the initializer succeeds.

  • Parameter envelopes: The envelopes to be joined.

  • Throws: Throws an exception if no quorum of shares can be found to reconstruct the original envelope.

Source§

impl Envelope

Source

pub fn add_type(&self, object: impl EnvelopeEncodable) -> Self

Returns the result of adding the given 'IsA' type assertion to the envelope.

Source

pub fn types(&self) -> Vec<Self>

Returns all of the envelope’s 'IsA' type assertions.

Source

pub fn get_type(&self) -> Result<Self>

Gets a single 'IsA' type assertion from the envelope.

If there is more than one 'IsA' type assertion, returns an error.

Source

pub fn has_type_envelope(&self, t: impl EnvelopeEncodable) -> bool

Returns true if the envelope has an 'IsA' type assertion with the given envelope t’s digest.

Source

pub fn has_type(&self, t: &KnownValue) -> bool

Returns true if the envelope has an 'IsA' type assertion with the given known value t.

Source

pub fn check_type(&self, t: &KnownValue) -> Result<()>

Succeeds if the envelope has an 'IsA' type assertion with the given known value t.

Fails with EnvelopeError::InvalidType otherwise.

Source

pub fn check_type_envelope(&self, t: impl EnvelopeEncodable) -> Result<()>

Succeeds if the envelope has an 'IsA' type assertion with the given envelope t’s digest.

Fails with EnvelopeError::InvalidType otherwise.

Source§

impl Envelope

Source

pub fn seal(&self, sender: &impl Signer, recipient: &PublicKeyBase) -> Envelope

Source

pub fn unseal( &self, sender: &impl Verifier, recipient: &PrivateKeyBase, ) -> Result<Envelope>

Trait Implementations§

Source§

impl CBORTagged for Envelope

Support for CBOR encoding and decoding of Envelope. All envelopes are tagged with the envelope tag. Within that tag, each of the seven cases has a unique CBOR signature:

  • .node contains a CBOR array, the first element of which is the subject, followed by one or more assertions.
  • .leaf is tagged #6.24, which is the IANA tag for embedded CBOR.
  • .wrapped is tagged with the envelope tag.
  • .assertion is a single-element map {predicate: object}.
  • .knownValue is an unsigned 64-bit integer.
  • .encrypted is tagged with the crypto-msg tag.
  • .elided is a byte string of length 32.
Source§

fn cbor_tags() -> Vec<Tag>

The CBOR tags assocated with this type. If more than one tag is present, they are considered equivalent for reading, but only the first one is used for writing.
Source§

impl CBORTaggedDecodable for Envelope

Source§

fn from_untagged_cbor(cbor: CBOR) -> Result<Self>

Creates an instance of this type by decoding it from untagged CBOR.
Source§

fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from tagged CBOR.
Source§

fn from_tagged_cbor_data(data: impl AsRef<[u8]>) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from binary encoded tagged CBOR.
Source§

fn from_untagged_cbor_data(data: impl AsRef<[u8]>) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from binary encoded untagged CBOR.
Source§

impl CBORTaggedEncodable for Envelope

Source§

fn untagged_cbor(&self) -> CBOR

Returns the untagged CBOR encoding of this instance.
Source§

fn tagged_cbor(&self) -> CBOR

Returns the tagged CBOR encoding of this instance.
Source§

fn tagged_cbor_data(&self) -> Vec<u8>

Returns the tagged value in CBOR binary representation.
Source§

impl Clone for Envelope

Source§

fn clone(&self) -> Envelope

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Envelope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DigestProvider for Envelope

Support for calculating the digests associated with Envelope.

Source§

fn digest(&self) -> Cow<'_, Digest>

The envelope’s digest.

This digest can be used to compare two envelopes for semantic equivalence, that is, the two envelopes would contain the same information in their unencrypted and unelided forms. See doc:Diffing for more information.

Source§

impl Display for Envelope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EnvelopeFormat for Envelope

Source§

impl From<&Envelope> for Envelope

Source§

fn from(envelope: &Envelope) -> Self

Converts to this type from the input type.
Source§

impl From<Envelope> for CBOR

Source§

fn from(value: Envelope) -> Self

Converts to this type from the input type.
Source§

impl From<EnvelopeCase> for Envelope

Source§

fn from(case: EnvelopeCase) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Event<T>> for Envelope

Source§

fn from(event: Event<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Expression> for Envelope

Expression -> Envelope

Source§

fn from(expression: Expression) -> Self

Converts to this type from the input type.
Source§

impl From<Request> for Envelope

Source§

fn from(request: Request) -> Self

Converts to this type from the input type.
Source§

impl From<Response> for Envelope

Source§

fn from(value: Response) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Envelope

Implement PartialEq for Envelope to allow for structural comparison.

Note that we deliberately do not also implement Eq as this comparison for identicality is potentially expensive, and structures like HashMap require that Eq be implemented for its keys. This should be a fast/cheap operation.

If you want to use envelopes as keys in such structures, you can pre-compute an envelope’s structural_digest and use that as the key.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<CBOR> for Envelope

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: CBOR) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Compressed> for Envelope

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(compressed: Compressed) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<EncryptedMessage> for Envelope

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: EncryptedMessage) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for ByteString

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl<T> TryFrom<Envelope> for Event<T>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for Expression

Envelope -> Expression

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for Function

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for Request

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for Response

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for String

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CBOREncodable for T
where T: Into<CBOR> + Clone,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> EnvelopeEncodable for T
where T: Into<Envelope> + Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> URDecodable for T

Source§

fn from_ur(ur: impl AsRef<UR>) -> Result<Self, Error>
where Self: Sized,

Source§

fn from_ur_string(ur_string: impl Into<String>) -> Result<Self, Error>
where Self: Sized,

Source§

impl<T> UREncodable for T

Source§

fn ur(&self) -> UR

Returns the UR representation of the object.
Source§

fn ur_string(&self) -> String

Returns the UR string representation of the object.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> CBORCodable for T

Source§

impl<T> CBORDecodable for T
where T: TryFrom<CBOR>,

Source§

impl<T> CBORTaggedCodable for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> URCodable for T