Struct bc_envelope::base::envelope::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
impl Envelope
Support for adding assertions.
sourcepub fn add_assertion(
&self,
predicate: impl EnvelopeEncodable,
object: impl EnvelopeEncodable
) -> Self
pub fn add_assertion( &self, predicate: impl EnvelopeEncodable, object: impl EnvelopeEncodable ) -> Self
Returns the result of adding the given assertion to the envelope.
sourcepub fn add_assertion_envelope(
&self,
assertion_envelope: impl EnvelopeEncodable
) -> Result<Self>
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.
sourcepub fn add_assertion_envelopes(&self, assertions: &[Self]) -> Result<Self>
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.
sourcepub fn add_optional_assertion_envelope(
&self,
assertion: Option<Self>
) -> Result<Self>
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.
sourcepub fn add_optional_assertion(
&self,
predicate: impl EnvelopeEncodable,
object: Option<impl EnvelopeEncodable>
) -> Self
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.
sourcepub fn add_assertions(&self, envelopes: &[Self]) -> Self
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
impl Envelope
Support for adding conditional assertions.
sourcepub fn add_assertion_if(
&self,
condition: bool,
predicate: impl EnvelopeEncodable,
object: impl EnvelopeEncodable
) -> Self
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.
sourcepub fn add_assertion_envelope_if(
&self,
condition: bool,
assertion_envelope: Self
) -> Result<Self>
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
impl Envelope
Support for adding assertions with salt.
sourcepub fn add_assertion_salted<P, O>(
&self,
predicate: P,
object: O,
salted: bool
) -> Selfwhere
P: EnvelopeEncodable,
O: EnvelopeEncodable,
pub fn add_assertion_salted<P, O>(
&self,
predicate: P,
object: O,
salted: bool
) -> Selfwhere
P: EnvelopeEncodable,
O: EnvelopeEncodable,
Returns the result of adding the given assertion to the envelope, optionally salting it.
sourcepub fn add_assertion_envelope_salted(
&self,
assertion_envelope: Self,
salted: bool
) -> Result<Self>
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.
sourcepub fn add_optional_assertion_envelope_salted(
&self,
assertion: Option<Self>,
salted: bool
) -> Result<Self>
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.
pub fn add_assertions_salted(&self, assertions: &[Self], salted: bool) -> Self
source§impl Envelope
impl Envelope
Support for removing or replacing assertions.
sourcepub fn remove_assertion(&self, target: Self) -> Self
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.
sourcepub fn replace_assertion(
&self,
assertion: Self,
new_assertion: Self
) -> Result<Self>
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.
sourcepub fn replace_subject(&self, subject: Self) -> Self
pub fn replace_subject(&self, subject: Self) -> Self
Returns a new envelope with its subject replaced by the provided one.
source§impl Envelope
impl Envelope
Support for working with the digest tree of an Envelope.
sourcepub fn digests(&self, level_limit: usize) -> HashSet<Digest>
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.
sourcepub fn deep_digests(&self) -> HashSet<Digest>
pub fn deep_digests(&self) -> HashSet<Digest>
Returns the set of all digests in the envelope.
sourcepub fn shallow_digests(&self) -> HashSet<Digest>
pub fn shallow_digests(&self) -> HashSet<Digest>
Returns the set of all digests in the envelope, down to its second level.
sourcepub fn structural_digest(&self) -> Digest
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.
sourcepub fn is_equivalent_to(&self, other: &Self) -> bool
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.
sourcepub fn is_identical_to(&self, other: &Self) -> bool
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
impl Envelope
Support for basic envelope creation.
sourcepub fn new(subject: impl EnvelopeEncodable) -> Self
pub fn new(subject: impl EnvelopeEncodable) -> Self
Creates an envelope with a subject, which
can be any instance that implements EnvelopeEncodable.
sourcepub fn new_or_null(subject: Option<impl EnvelopeEncodable>) -> Self
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.
sourcepub fn new_or_none(subject: Option<impl EnvelopeEncodable>) -> Option<Self>
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.
sourcepub fn new_assertion(
predicate: impl EnvelopeEncodable,
object: impl EnvelopeEncodable
) -> Self
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
impl Envelope
Support for eliding elements from envelopes.
This includes eliding, encrypting and compressing (obscuring) elements.
sourcepub fn elide(&self) -> Self
pub fn elide(&self) -> Self
Returns the elided variant of this envelope.
Returns the same envelope if it is already elided.
sourcepub fn elide_removing_set_with_action(
&self,
target: &HashSet<Digest>,
action: &ObscureAction
) -> Self
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.
sourcepub fn elide_removing_set(&self, target: &HashSet<Digest>) -> Self
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.
sourcepub fn elide_removing_array_with_action(
&self,
target: &[&dyn DigestProvider],
action: &ObscureAction
) -> Self
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).
- target: An array of
-
Returns: The elided envelope.
sourcepub fn elide_removing_array(&self, target: &[&dyn DigestProvider]) -> Self
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).
- target: An array of
-
Returns: The elided envelope.
sourcepub fn elide_removing_target_with_action(
&self,
target: &dyn DigestProvider,
action: &ObscureAction
) -> Self
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).
- target: A
-
Returns: The elided envelope.
sourcepub fn elide_removing_target(&self, target: &dyn DigestProvider) -> Self
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.
- target: A
-
Returns: The elided envelope.
sourcepub fn elide_revealing_set_with_action(
&self,
target: &HashSet<Digest>,
action: &ObscureAction
) -> Self
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.
sourcepub fn elide_revealing_set(&self, target: &HashSet<Digest>) -> Self
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.
sourcepub fn elide_revealing_array_with_action(
&self,
target: &[&dyn DigestProvider],
action: &ObscureAction
) -> Self
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).
- target: An array of
-
Returns: The elided envelope.
sourcepub fn elide_revealing_array(&self, target: &[&dyn DigestProvider]) -> Self
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.
- target: An array of
-
Returns: The elided envelope.
sourcepub fn elide_revealing_target_with_action(
&self,
target: &dyn DigestProvider,
action: &ObscureAction
) -> Self
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).
- target: A
-
Returns: The elided envelope.
sourcepub fn elide_revealing_target(&self, target: &dyn DigestProvider) -> Self
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.
- target: A
-
Returns: The elided envelope.
sourcepub fn elide_set_with_action(
&self,
target: &HashSet<Digest>,
is_revealing: bool,
action: &ObscureAction
) -> Self
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 isfalse, the target set contains the digests of the elements to elide. - action: Perform the specified action (elision, encryption or compression).
-
Returns: The elided envelope.
sourcepub fn elide_set(&self, target: &HashSet<Digest>, is_revealing: bool) -> Self
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 isfalse, the target set contains the digests of the elements to elide.
-
Returns: The elided envelope.
sourcepub fn elide_array_with_action(
&self,
target: &[&dyn DigestProvider],
is_revealing: bool,
action: &ObscureAction
) -> Self
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 isfalse, the target set contains the digests of the elements to elide. - action: Perform the specified action (elision, encryption or compression).
- target: An array of
-
Returns: The elided envelope.
sourcepub fn elide_array(
&self,
target: &[&dyn DigestProvider],
is_revealing: bool
) -> Self
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 isfalse, the target set contains the digests of the elements to elide.
- target: An array of
-
Returns: The elided envelope.
sourcepub fn elide_target_with_action(
&self,
target: &dyn DigestProvider,
is_revealing: bool,
action: &ObscureAction
) -> Self
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 isfalse, the target is the element to elide, leaving all others revealed. - action: Perform the specified action (elision, encryption or compression).
- target: A
-
Returns: The elided envelope.
sourcepub fn elide_target(
&self,
target: &dyn DigestProvider,
is_revealing: bool
) -> Self
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 isfalse, the target is the element to elide, leaving all others revealed.
- target: A
-
Returns: The elided envelope.
source§impl Envelope
impl Envelope
pub fn try_from_cbor(cbor: CBOR) -> Result<Self>
pub fn try_from_cbor_data(data: Bytes) -> Result<Self>
source§impl Envelope
impl Envelope
Support for various queries on envelopes.
sourcepub fn subject(&self) -> Self
pub fn subject(&self) -> Self
The envelope’s subject.
For an envelope with no assertions, returns the same envelope.
sourcepub fn assertions(&self) -> Vec<Self>
pub fn assertions(&self) -> Vec<Self>
The envelope’s assertions.
sourcepub fn has_assertions(&self) -> bool
pub fn has_assertions(&self) -> bool
true if the envelope has at least one assertion, false otherwise.
sourcepub fn as_assertion(&self) -> Option<Self>
pub fn as_assertion(&self) -> Option<Self>
If the envelope’s subject is an assertion return it, else return None.
sourcepub fn try_assertion(&self) -> Result<Self>
pub fn try_assertion(&self) -> Result<Self>
If the envelope’s subject is an assertion return it, else return an error.
sourcepub fn as_predicate(&self) -> Option<Self>
pub fn as_predicate(&self) -> Option<Self>
The envelope’s predicate, or None if the envelope is not an assertion.
sourcepub fn try_predicate(&self) -> Result<Self>
pub fn try_predicate(&self) -> Result<Self>
The envelope’s predicate, or an error if the envelope is not an assertion.
sourcepub fn as_object(&self) -> Option<Self>
pub fn as_object(&self) -> Option<Self>
The envelope’s object, or None if the envelope is not an assertion.
sourcepub fn try_object(&self) -> Result<Self>
pub fn try_object(&self) -> Result<Self>
The envelope’s object, or an error if the envelope is not an assertion.
sourcepub fn as_leaf(&self) -> Option<CBOR>
pub fn as_leaf(&self) -> Option<CBOR>
The envelope’s leaf CBOR object, or None if the envelope is not a leaf.
sourcepub fn try_leaf(&self) -> Result<CBOR>
pub fn try_leaf(&self) -> Result<CBOR>
The envelope’s leaf CBOR object, or an error if the envelope is not a leaf.
sourcepub fn as_known_value(&self) -> Option<&KnownValue>
pub fn as_known_value(&self) -> Option<&KnownValue>
The envelope’s KnownValue, or None if the envelope is not case ::KnownValue.
sourcepub fn try_known_value(&self) -> Result<&KnownValue>
pub fn try_known_value(&self) -> Result<&KnownValue>
The envelope’s KnownValue, or an error if the envelope is not case ::KnownValue.
sourcepub fn is_wrapped(&self) -> bool
pub fn is_wrapped(&self) -> bool
true if the envelope is case ::Wrapped, false otherwise.
sourcepub fn is_known_value(&self) -> bool
pub fn is_known_value(&self) -> bool
true if the envelope is case ::KnownValue, false otherwise.
sourcepub fn is_assertion(&self) -> bool
pub fn is_assertion(&self) -> bool
true if the envelope is case ::Assertion, false otherwise.
sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
true if the envelope is case ::Encrypted, false otherwise.
sourcepub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
true if the envelope is case ::Compressed, false otherwise.
sourcepub fn is_subject_assertion(&self) -> bool
pub fn is_subject_assertion(&self) -> bool
true if the subject of the envelope is an assertion, false otherwise.
sourcepub fn is_subject_encrypted(&self) -> bool
pub fn is_subject_encrypted(&self) -> bool
true if the subject of the envelope has been encrypted, false otherwise.
sourcepub fn is_subject_compressed(&self) -> bool
pub fn is_subject_compressed(&self) -> bool
true if the subject of the envelope has been compressed, false otherwise.
sourcepub fn is_subject_elided(&self) -> bool
pub fn is_subject_elided(&self) -> bool
true if the subject of the envelope has been elided, false otherwise.
sourcepub fn is_subject_obscured(&self) -> bool
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.
sourcepub fn is_internal(&self) -> bool
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.
sourcepub fn is_obscured(&self) -> bool
pub fn is_obscured(&self) -> bool
true if the envelope is encrypted, elided, or compressed; false otherwise.
sourcepub fn extract_subject<T>(&self) -> Result<T>
pub fn extract_subject<T>(&self) -> Result<T>
Returns the envelope’s subject, decoded as the given type.
If the encoded type doesn’t match the given type, returns Error::InvalidFormat.
sourcepub fn assertions_with_predicate(
&self,
predicate: impl EnvelopeEncodable
) -> Vec<Self>
pub fn assertions_with_predicate( &self, predicate: impl EnvelopeEncodable ) -> Vec<Self>
Returns all assertions with the given predicate. Match by comparing digests.
sourcepub fn assertion_with_predicate(
&self,
predicate: impl EnvelopeEncodable
) -> Result<Self>
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.
sourcepub fn object_for_predicate(
&self,
predicate: impl EnvelopeEncodable
) -> Result<Self>
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.
sourcepub fn extract_object<T: TryFrom<CBOR, Error = Error> + 'static>(
&self
) -> Result<T>
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.
sourcepub fn extract_predicate<T: TryFrom<CBOR, Error = Error> + 'static>(
&self
) -> Result<T>
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.
sourcepub fn extract_object_for_predicate<T: TryFrom<CBOR, Error = Error> + 'static>(
&self,
predicate: impl EnvelopeEncodable
) -> Result<T>
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.
sourcepub fn extract_optional_object_for_predicate<T: TryFrom<CBOR, Error = Error> + 'static>(
&self,
predicate: impl EnvelopeEncodable
) -> Result<Option<T>>
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.
sourcepub fn extract_object_for_predicate_with_default<T: TryFrom<CBOR, Error = Error> + 'static>(
&self,
predicate: impl EnvelopeEncodable,
default: T
) -> Result<T>
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.
sourcepub fn objects_for_predicate(
&self,
predicate: impl EnvelopeEncodable
) -> Vec<Self>
pub fn objects_for_predicate( &self, predicate: impl EnvelopeEncodable ) -> Vec<Self>
Returns the objects of all assertions with the matching predicate.
sourcepub fn extract_objects_for_predicate<T: TryFrom<CBOR, Error = Error> + 'static>(
&self,
predicate: impl EnvelopeEncodable
) -> Result<Vec<T>>
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.
sourcepub fn elements_count(&self) -> usize
pub fn elements_count(&self) -> usize
Returns the number of structural elements in the envelope, including itself.
source§impl Envelope
impl Envelope
Support for the various text output formats for Envelope.
sourcepub fn format_opt(&self, context: Option<&FormatContext>) -> String
pub fn format_opt(&self, context: Option<&FormatContext>) -> String
Returns the envelope notation for this envelope.
sourcepub fn format(&self) -> String
pub fn format(&self) -> String
Returns the envelope notation for this envelope.
Uses the current format context.
sourcepub fn diagnostic_opt(
&self,
annotate: bool,
context: Option<&FormatContext>
) -> String
pub fn diagnostic_opt( &self, annotate: bool, context: Option<&FormatContext> ) -> String
Returns the CBOR diagnostic notation for this envelope.
See RFC-8949 §8 for information on CBOR diagnostic notation.
sourcepub fn diagnostic(&self) -> String
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§impl Envelope
impl Envelope
Support for tree-formatting envelopes.
pub fn tree_format_opt( &self, hide_nodes: bool, context: Option<&FormatContext> ) -> String
pub fn tree_format(&self, hide_nodes: bool) -> String
pub fn tree_format_with_target_opt( &self, hide_nodes: bool, highlighting_target: &HashSet<Digest>, context: Option<&FormatContext> ) -> String
pub fn tree_format_with_target( &self, hide_nodes: bool, highlighting_target: &HashSet<Digest> ) -> String
source§impl Envelope
impl Envelope
Support for wrapping and unwrapping envelopes.
sourcepub fn wrap_envelope(&self) -> Self
pub fn wrap_envelope(&self) -> Self
Return a new envelope which wraps the current envelope.
sourcepub fn unwrap_envelope(&self) -> Result<Self>
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
impl Envelope
sourcepub fn new_attachment(
payload: impl EnvelopeEncodable,
vendor: &str,
conforms_to: Option<&str>
) -> Self
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.
sourcepub fn add_attachment(
&self,
payload: impl EnvelopeEncodable,
vendor: &str,
conforms_to: Option<&str>
) -> Self
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
impl Envelope
sourcepub fn attachment_payload(&self) -> Result<Self>
pub fn attachment_payload(&self) -> Result<Self>
Returns the payload of the given attachment envelope.
sourcepub fn attachment_vendor(&self) -> Result<String>
pub fn attachment_vendor(&self) -> Result<String>
Returns the vendor of the given attachment envelope.
sourcepub fn attachment_conforms_to(&self) -> Result<Option<String>>
pub fn attachment_conforms_to(&self) -> Result<Option<String>>
Returns the conformsTo of the given attachment envelope.
sourcepub fn attachments_with_vendor_and_conforms_to(
&self,
vendor: Option<&str>,
conforms_to: Option<&str>
) -> Result<Vec<Self>>
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.
pub fn attachments(&self) -> Result<Vec<Self>>
sourcepub fn validate_attachment(&self) -> Result<()>
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': Stringassertion. - The attachment envelope’s object has an optional
'conformsTo': Stringassertion.
sourcepub fn attachment_with_vendor_and_conforms_to(
&self,
vendor: Option<&str>,
conforms_to: Option<&str>
) -> Result<Self>
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
impl Envelope
Support for compressing and uncompressing envelopes.
sourcepub fn compress(&self) -> Result<Self>
pub fn compress(&self) -> Result<Self>
Returns the compressed variant of this envelope.
Returns the same envelope if it is already compressed.
sourcepub fn uncompress(&self) -> Result<Self>
pub fn uncompress(&self) -> Result<Self>
Returns the uncompressed variant of this envelope.
Returns the same envelope if it is already uncompressed.
sourcepub fn compress_subject(&self) -> Result<Self>
pub fn compress_subject(&self) -> Result<Self>
Returns this envelope with its subject compressed.
Returns the same envelope if its subject is already compressed.
sourcepub fn uncompress_subject(&self) -> Result<Self>
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
impl Envelope
Support for encrypting and decrypting envelopes.
sourcepub fn encrypt_subject(&self, key: &SymmetricKey) -> Result<Self>
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
SymmetricKeyto be used to encrypt the subject.
- key: The
-
Returns: The encrypted envelope.
-
Throws: If the envelope is already encrypted.
sourcepub fn decrypt_subject(&self, key: &SymmetricKey) -> Result<Self>
pub fn decrypt_subject(&self, key: &SymmetricKey) -> Result<Self>
Returns a new envelope with its subject decrypted.
source§impl Envelope
impl Envelope
Envelope Expressions: Function Construction
sourcepub fn new_function(function: impl Into<Function>) -> Self
pub fn new_function(function: impl Into<Function>) -> Self
Creates an envelope with a «function» subject.
source§impl Envelope
impl Envelope
Envelope Expressions: Parameter Construction
sourcepub fn new_parameter(
param: impl Into<Parameter>,
value: impl EnvelopeEncodable
) -> Self
pub fn new_parameter( param: impl Into<Parameter>, value: impl EnvelopeEncodable ) -> Self
Creates a new envelope containing a ❰parameter❱: value assertion.
-
Parameters:
- param: A
Parameter. This will be encoded as either an unsigned integer or a string. - value: The argument value.
- param: A
-
Returns: The new assertion envelope. If
valueisNone, returnsNone.
sourcepub fn new_optional_parameter(
param: impl Into<Parameter>,
value: Option<impl EnvelopeEncodable>
) -> Option<Self>
pub fn new_optional_parameter( param: impl Into<Parameter>, value: Option<impl EnvelopeEncodable> ) -> Option<Self>
Optionally adds a ❰parameter❱: value assertion to the envelope.
sourcepub fn add_parameter(
&self,
param: impl Into<Parameter>,
value: impl EnvelopeEncodable
) -> Self
pub fn add_parameter( &self, param: impl Into<Parameter>, value: impl EnvelopeEncodable ) -> Self
Adds a ❰parameter❱: value assertion to the envelope.
-
Parameters:
- param: A
Parameter. This will be encoded as either an unsigned integer or a string. - value: The argument value.
- param: A
-
Returns: The new envelope.
sourcepub fn add_optional_parameter(
&self,
param: impl Into<Parameter>,
value: Option<impl EnvelopeEncodable>
) -> Self
pub fn add_optional_parameter( &self, param: impl Into<Parameter>, value: Option<impl EnvelopeEncodable> ) -> Self
Optionally adds a ❰parameter❱: value assertion to the envelope.
-
Parameters:
- param: A
Parameter. This will be encoded as either an unsigned integer or a string. - value: The optional argument value.
- param: A
-
Returns: The new envelope. If
valueisNone, returns the original envelope.
source§impl Envelope
impl Envelope
Envelope Expressions: Request Construction
sourcepub fn new_request(id: impl AsRef<ARID>) -> Envelope
pub fn new_request(id: impl AsRef<ARID>) -> Envelope
Creates an envelope with a Request(ARID) subject.
sourcepub fn into_request_with_metadata(
self,
id: impl AsRef<ARID>,
note: impl Into<String>,
date: Option<Date>
) -> Self
pub fn into_request_with_metadata( self, id: impl AsRef<ARID>, note: impl Into<String>, date: Option<Date> ) -> Self
Creates an envelope with a Request(ARID) subject and a body: «function»
assertion.
Also adds a 'note' assertion if note is not empty, and a
'date' assertion if date is not nil.
sourcepub fn into_request(self, id: impl AsRef<ARID>) -> Self
pub fn into_request(self, id: impl AsRef<ARID>) -> Self
Creates an envelope with a Request(ARID) subject and a body: «function»
assertion.
source§impl Envelope
impl Envelope
Envelope Expression: Request Parsing
sourcepub fn parse_request_with_metadata(
&self,
expected_function: Option<&Function>
) -> Result<(ARID, Envelope, Function, String, Option<Date>)>
pub fn parse_request_with_metadata( &self, expected_function: Option<&Function> ) -> Result<(ARID, Envelope, Function, String, Option<Date>)>
Parses the request envelope and returns the id, body, note, and date.
sourcepub fn from_request(
&self,
expected_function: Option<&Function>
) -> Result<(ARID, Envelope, Function)>
pub fn from_request( &self, expected_function: Option<&Function> ) -> Result<(ARID, Envelope, Function)>
Parses the request envelope and returns the id and body.
sourcepub fn request_id(&self) -> Result<ARID>
pub fn request_id(&self) -> Result<ARID>
Parses the request envelope and returns the id.
sourcepub fn request_body(&self) -> Result<Self>
pub fn request_body(&self) -> Result<Self>
Parses the request envelope and returns the body.
sourcepub fn request_note(&self) -> Result<String>
pub fn request_note(&self) -> Result<String>
Parses the request envelope and returns the note.
sourcepub fn request_date(&self) -> Result<Option<Date>>
pub fn request_date(&self) -> Result<Option<Date>>
Parses the request envelope and returns the date.
source§impl Envelope
impl Envelope
Envelope Expressions: Parameter Decoding
sourcepub fn object_for_parameter(
&self,
param: impl Into<Parameter>
) -> Result<Envelope>
pub fn object_for_parameter( &self, param: impl Into<Parameter> ) -> Result<Envelope>
Returns the argument for the given parameter.
sourcepub fn objects_for_parameter(
&self,
param: impl Into<Parameter>
) -> Vec<Envelope>
pub fn objects_for_parameter( &self, param: impl Into<Parameter> ) -> Vec<Envelope>
Returns the arguments for the given possibly repeated parameter.
sourcepub fn extract_object_for_parameter<T>(
&self,
param: impl Into<Parameter>
) -> Result<T>
pub fn extract_object_for_parameter<T>( &self, param: impl Into<Parameter> ) -> Result<T>
Returns the argument for the given parameter, decoded as the given type.
- Throws: Throws an exception if there is not exactly one matching
parameter, or if the parameter value is not the correct type.
sourcepub fn extract_optional_object_for_parameter<T: TryFrom<CBOR, Error = Error> + 'static>(
&self,
param: impl Into<Parameter>
) -> Result<Option<T>>
pub fn extract_optional_object_for_parameter<T: TryFrom<CBOR, Error = Error> + 'static>( &self, param: impl Into<Parameter> ) -> Result<Option<T>>
Returns the argument for the given parameter, or None if there is no matching parameter.
source§impl Envelope
impl Envelope
Envelope Expressions: Response Construction
sourcepub fn new_response(id: Option<&ARID>) -> Envelope
pub fn new_response(id: Option<&ARID>) -> Envelope
Creates an envelope with a Response(ID) subject.
The id parameter is the ID of the response. Typically, this will be an
ARID that matches the corresponding request. In certain error cases,
there may not be a known ID, in which case None can be passed for
id.
sourcepub fn into_response(self, id: Option<&ARID>, is_success: bool) -> Self
pub fn into_response(self, id: Option<&ARID>, is_success: bool) -> Self
Creates an envelope with a Response(ID) subject and a 'result': value
assertion, where value is self.
The id parameter is the ID of the response. Typically, this will be an
ARID that matches the corresponding request. In certain error cases,
there may not be a known ID, in which case None can be passed for
id.
sourcepub fn into_success_response(self, id: impl AsRef<ARID>) -> Self
pub fn into_success_response(self, id: impl AsRef<ARID>) -> Self
Creates an envelope with a Response(ID) subject and a 'result': value
assertion, where value is self.
The id parameter is the ID of the response. Typically, this will be an
ARID that matches the corresponding request.
sourcepub fn new_success_response(
id: impl AsRef<ARID>,
result: Option<Envelope>
) -> Envelope
pub fn new_success_response( id: impl AsRef<ARID>, result: Option<Envelope> ) -> Envelope
Creates an envelope with a Response(ID) subject and a 'error': value
assertion.
The id parameter is the ID of the response. Typically, this will be an
ARID that matches the corresponding request.
If there is no explicit result, the result predicate will be set to
the known value OK.
sourcepub fn into_failure_response(self, id: Option<&ARID>) -> Self
pub fn into_failure_response(self, id: Option<&ARID>) -> Self
Creates an envelope with a Response(ID) subject and a 'error': value
assertion, where value is self.
The id parameter is the ID of the response. Typically, this will be an
ARID that matches the corresponding request. In certain error cases,
there may not be a known ID, in which case None can be passed for
id.
sourcepub fn new_failure_response(
id: Option<&ARID>,
error: Option<Envelope>
) -> Envelope
pub fn new_failure_response( id: Option<&ARID>, error: Option<Envelope> ) -> Envelope
Creates an envelope with a Response(ID) subject and a 'error': value
assertion.
The id parameter is the ID of the response. Typically, this will be an
ARID that matches the corresponding request. In certain error cases,
there may not be a known ID, in which case None can be passed for
id.
If there is no known error, the error predicate will be set to the
known value Unknown.
source§impl Envelope
impl Envelope
Envelope Expressions: Response Decoding
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns whether the envelope is a success response.
sourcepub fn is_failure(&self) -> bool
pub fn is_failure(&self) -> bool
Returns whether the envelope is a failure response.
sourcepub fn response_id(&self) -> Result<ARID>
pub fn response_id(&self) -> Result<ARID>
Returns the ID of the response.
- Throws: Throws an exception if the subject is not a tagged value with
the tag
RESPONSE.
sourcepub fn result(&self) -> Result<Self>
pub fn result(&self) -> Result<Self>
Returns the response’s result.
- Throws: Throws an exception if there is no
resultpredicate.
sourcepub fn extract_result<T>(&self) -> Result<T>
pub fn extract_result<T>(&self) -> Result<T>
Returns the response’s result, decoded as the given type.
- Throws: Throws an exception if there is no
resultpredicate.
sourcepub fn is_result_ok(&self) -> Result<bool>
pub fn is_result_ok(&self) -> Result<bool>
Returns whether the response’s result is the known value OK.
- Throws: Throws an exception if there is no
resultpredicate.
sourcepub fn extract_error<T>(&self) -> Result<T>
pub fn extract_error<T>(&self) -> Result<T>
Returns the error value, decoded as the given type.
- Throws: Throws an exception if there is no
errorpredicate.
sourcepub fn parse_response(
&self,
expected_id: Option<&ARID>
) -> Result<(Envelope, ARID, bool)>
pub fn parse_response( &self, expected_id: Option<&ARID> ) -> Result<(Envelope, ARID, bool)>
Parses the response envelope and returns the result or error value, the
id, and a boolean that is true if the response represents success.
If expected_id is provided, the response ID must match it.
source§impl Envelope
impl Envelope
Transaction Request Construction
sourcepub fn into_transaction_request_with_metadata(
self,
id: impl AsRef<ARID>,
sender: impl AsRef<PublicKeyBase>,
note: impl Into<String>,
date: Option<Date>
) -> Self
pub fn into_transaction_request_with_metadata( self, id: impl AsRef<ARID>, sender: impl AsRef<PublicKeyBase>, note: impl Into<String>, date: Option<Date> ) -> Self
Creates an envelope with an ARID subject, a body: «function»
assertion, and a 'senderPublicKey' assertion.
Also adds a 'note' assertion if note is not empty, and a
'date' assertion if date is not nil.
sourcepub fn into_signed_transaction_request_with_metadata(
self,
id: impl AsRef<ARID>,
sender: &PrivateKeyBase,
note: impl Into<String>,
date: Option<Date>
) -> Self
pub fn into_signed_transaction_request_with_metadata( self, id: impl AsRef<ARID>, sender: &PrivateKeyBase, note: impl Into<String>, date: Option<Date> ) -> Self
Creates an envelope with an ARID subject, a body: «function»
assertion, and a 'senderPublicKey' assertion, then wraps and signs
the envelope with the sender’s private key.
Also adds a 'note' assertion if note is not empty, and a
'date' assertion if date is not nil.
sourcepub fn into_sealed_transaction_request_with_metadata(
self,
id: impl AsRef<ARID>,
sender: &PrivateKeyBase,
recipient: &PublicKeyBase,
note: impl Into<String>,
date: Option<Date>
) -> Result<Envelope>
pub fn into_sealed_transaction_request_with_metadata( self, id: impl AsRef<ARID>, sender: &PrivateKeyBase, recipient: &PublicKeyBase, note: impl Into<String>, date: Option<Date> ) -> Result<Envelope>
Creates an envelope with an ARID subject, a body: «function»
assertion, and a 'senderPublicKey' assertion, then wraps and signs the
envelope with the sender’s private key, and finally wraps and encrypts
the envelope with the recipient’s public key.
Also adds a 'note' assertion if note is not empty, and a
'date' assertion if date is not nil.
sourcepub fn into_transaction_request(
self,
id: impl AsRef<ARID>,
sender: impl AsRef<PublicKeyBase>
) -> Self
pub fn into_transaction_request( self, id: impl AsRef<ARID>, sender: impl AsRef<PublicKeyBase> ) -> Self
Creates an envelope with an ARID subject, a body: «function», and a
'senderPublicKey' assertion.
sourcepub fn into_signed_transaction_request(
self,
id: impl AsRef<ARID>,
sender: &PrivateKeyBase
) -> Self
pub fn into_signed_transaction_request( self, id: impl AsRef<ARID>, sender: &PrivateKeyBase ) -> Self
Creates an envelope with an ARID subject, a body: «function», and a
'senderPublicKey' assertion, then wraps and signs the envelope with the
sender’s private key.
sourcepub fn into_sealed_transaction_request(
self,
id: impl AsRef<ARID>,
sender: &PrivateKeyBase,
recipient: &PublicKeyBase
) -> Result<Envelope>
pub fn into_sealed_transaction_request( self, id: impl AsRef<ARID>, sender: &PrivateKeyBase, recipient: &PublicKeyBase ) -> Result<Envelope>
Creates an envelope with an ARID subject, a body: «function», and a
'senderPublicKey' assertion, then wraps and signs the envelope with the
sender’s private key, and finally wraps and encrypts the envelope with the
recipient’s public key.
source§impl Envelope
impl Envelope
Transaction Request Parsing
sourcepub fn parse_transaction_request_with_metadata(
&self,
expected_function: Option<&Function>
) -> Result<(ARID, PublicKeyBase, Envelope, Function, String, Option<Date>)>
pub fn parse_transaction_request_with_metadata( &self, expected_function: Option<&Function> ) -> Result<(ARID, PublicKeyBase, Envelope, Function, String, Option<Date>)>
Parses the transaction request envelope and returns the id, sender, body, note, and date.
sourcepub fn parse_signed_transaction_request_with_metadata(
&self,
expected_function: Option<&Function>
) -> Result<(ARID, PublicKeyBase, Envelope, Function, String, Option<Date>)>
pub fn parse_signed_transaction_request_with_metadata( &self, expected_function: Option<&Function> ) -> Result<(ARID, PublicKeyBase, Envelope, Function, String, Option<Date>)>
Parses the signed transaction request envelope and verifies the signature from the sender, then returns the id, sender, body, note, and date.
sourcepub fn parse_sealed_transaction_request_with_metadata(
&self,
expected_function: Option<&Function>,
recipient: &PrivateKeyBase
) -> Result<(ARID, PublicKeyBase, Envelope, Function, String, Option<Date>)>
pub fn parse_sealed_transaction_request_with_metadata( &self, expected_function: Option<&Function>, recipient: &PrivateKeyBase ) -> Result<(ARID, PublicKeyBase, Envelope, Function, String, Option<Date>)>
Decrypts the sealed transaction request envelope to the recipient, verifies the signature from the sender, and returns the id, sender, body, note, and date.
sourcepub fn parse_transaction_request(
&self,
expected_function: Option<&Function>
) -> Result<(ARID, PublicKeyBase, Envelope, Function)>
pub fn parse_transaction_request( &self, expected_function: Option<&Function> ) -> Result<(ARID, PublicKeyBase, Envelope, Function)>
Parses the transaction request envelope and returns the id, sender, and body.
sourcepub fn parse_signed_transaction_request(
&self,
expected_function: Option<&Function>
) -> Result<(ARID, PublicKeyBase, Envelope, Function)>
pub fn parse_signed_transaction_request( &self, expected_function: Option<&Function> ) -> Result<(ARID, PublicKeyBase, Envelope, Function)>
Parses the signed transaction request envelope and verifies the signature from the sender, then returns the id, sender, and body.
sourcepub fn parse_sealed_transaction_request(
&self,
expected_function: Option<&Function>,
recipient: &PrivateKeyBase
) -> Result<(ARID, PublicKeyBase, Envelope, Function)>
pub fn parse_sealed_transaction_request( &self, expected_function: Option<&Function>, recipient: &PrivateKeyBase ) -> Result<(ARID, PublicKeyBase, Envelope, Function)>
Decrypts the sealed transaction request envelope to the recipient, verifies the signature from the sender, and returns the id, sender, and body.
source§impl Envelope
impl Envelope
Support for inclusions proofs.
sourcepub fn proof_contains_set(
&self,
target: &HashSet<Digest, RandomState>
) -> Option<Envelope>
pub fn proof_contains_set( &self, target: &HashSet<Digest, RandomState> ) -> Option<Envelope>
sourcepub fn proof_contains_target(
&self,
target: &dyn DigestProvider
) -> Option<Envelope>
pub fn proof_contains_target( &self, target: &dyn DigestProvider ) -> Option<Envelope>
sourcepub fn confirm_contains_set(
&self,
target: &HashSet<Digest, RandomState>,
proof: &Envelope
) -> bool
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.
sourcepub fn confirm_contains_target(
&self,
target: &dyn DigestProvider,
proof: &Envelope
) -> bool
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
impl Envelope
Support for public key encryption.
sourcepub fn add_recipient(
&self,
recipient: &PublicKeyBase,
content_key: &SymmetricKey
) -> Self
pub fn add_recipient( &self, recipient: &PublicKeyBase, 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
PublicKeyBaseof the recipient. - contentKey: The
SymmetricKeythat was used to encrypt the subject.
- recipient: The
-
Returns: The new envelope.
sourcepub fn recipients(&self) -> Result<Vec<SealedMessage>>
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
hasRecipientassertions do not have aSealedMessageas their object.
sourcepub fn encrypt_subject_to_recipients<T>(&self, recipients: &[T]) -> Result<Self>where
T: AsRef<PublicKeyBase>,
pub fn encrypt_subject_to_recipients<T>(&self, recipients: &[T]) -> Result<Self>where
T: AsRef<PublicKeyBase>,
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.
sourcepub fn encrypt_subject_to_recipient(
&self,
recipient: &PublicKeyBase
) -> Result<Self>
pub fn encrypt_subject_to_recipient( &self, recipient: &PublicKeyBase ) -> 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.
sourcepub fn decrypt_to_recipient(&self, recipient: &PrivateKeyBase) -> Result<Self>
pub fn decrypt_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
SealedMessageforrecipientis not found among thehasRecipientassertions on the envelope.
source§impl Envelope
impl Envelope
Support for signing envelopes and verifying signatures.
sourcepub fn add_signature_with(&self, private_key: &PrivateKeyBase) -> Self
pub fn add_signature_with(&self, private_key: &PrivateKeyBase) -> Self
Creates a signature for the envelope’s subject and returns a new envelope with a verifiedBy: Signature assertion.
-
Parameters:
- private_key: The signer’s
PrivateKeyBase
- private_key: The signer’s
-
Returns: The signed envelope.
sourcepub fn add_signature_with_opt<D>(
&self,
private_key: &PrivateKeyBase,
note: Option<&str>,
tag: D
) -> Self
pub fn add_signature_with_opt<D>( &self, private_key: &PrivateKeyBase, note: Option<&str>, tag: D ) -> Self
Creates a signature for the envelope’s subject and returns a new envelope with a verifiedBy: Signature assertion.
-
Parameters:
- private_key: The signer’s
PrivateKeyBase - note: Optional text note to add to the
Signature
- private_key: The signer’s
-
Returns: The signed envelope.
pub fn add_signatures_with_keys<T>(&self, private_keys: &[T]) -> Selfwhere
T: AsRef<PrivateKeyBase>,
sourcepub fn add_signatures_with_keys_opt<D, T>(
&self,
private_keys: &[T],
tag: D
) -> Self
pub fn add_signatures_with_keys_opt<D, T>( &self, private_keys: &[T], tag: D ) -> Self
Creates several signatures for the envelope’s subject and returns a new envelope with additional verifiedBy: Signature assertions.
-
Parameters:
- private_key: An array of signers’
PrivateKeyBases.
- private_key: An array of signers’
-
Returns: The signed envelope.
sourcepub fn add_signatures_with_uncovered_assertions<D>(
&self,
private_key: &PrivateKeyBase,
uncovered_assertions: &[Self],
tag: D
) -> Self
pub fn add_signatures_with_uncovered_assertions<D>( &self, private_key: &PrivateKeyBase, uncovered_assertions: &[Self], tag: D ) -> Self
Creates a signature for the envelope’s subject and returns a new envelope with a verifiedBy: Signature assertion.
-
Parameters:
- private_key: The signer’s
PrivateKeyBase - uncoveredAssertions: Assertions to add to the
Signature.
- private_key: The signer’s
-
Returns: The signed envelope.
sourcepub fn make_verified_by_signature(
&self,
signature: &Signature,
note: Option<&str>
) -> Self
pub fn make_verified_by_signature( &self, signature: &Signature, note: Option<&str> ) -> Self
Convenience constructor for a verifiedBy: Signature assertion envelope.
-
Parameters:
- signature: The
Signaturefor the object. - note: An optional note to be added to the
Signature.
- signature: The
-
Returns: The new assertion envelope.
sourcepub fn signatures(&self) -> Result<Vec<Signature>>
pub fn signatures(&self) -> Result<Vec<Signature>>
Returns an array of Signatures from all of the envelope’s verifiedBy predicates.
- Throws: Throws an exception if any
verifiedByassertion doesn’t contain a validSignatureas its object.
sourcepub fn is_verified_signature(
&self,
signature: &Signature,
public_key: &PublicKeyBase
) -> bool
pub fn is_verified_signature( &self, signature: &Signature, public_key: &PublicKeyBase ) -> bool
Returns whether the given signature is valid.
-
Parameters:
- signature: The
Signatureto be checked. - public_key: The potential signer’s
PublicKeyBase.
- signature: The
-
Returns:
trueif the signature is valid for this envelope’s subject,falseotherwise.
sourcepub fn verify_signature(
&self,
signature: &Signature,
public_key: &PublicKeyBase
) -> Result<Self>
pub fn verify_signature( &self, signature: &Signature, public_key: &PublicKeyBase ) -> 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
Signatureto be checked. - public_key: The potential signer’s
PublicKeyBase.
- signature: The
-
Returns: This envelope.
-
Throws: Throws
EnvelopeError.unverifiedSignatureif the signature is not valid. valid.
sourcepub fn has_signature_from(&self, public_key: &PublicKeyBase) -> Result<bool>
pub fn has_signature_from(&self, public_key: &PublicKeyBase) -> Result<bool>
Returns whether the envelope’s subject has a valid signature from the given public key.
-
Parameters:
- public_key: The potential signer’s
PublicKeyBase.
- public_key: The potential signer’s
-
Returns:
trueif the signature is valid for this envelope’s subject,falseotherwise. -
Throws: Throws an exception if any
verifiedByassertion doesn’t contain a validSignatureas its object.
sourcepub fn verify_signature_from(&self, public_key: &PublicKeyBase) -> Result<Self>
pub fn verify_signature_from(&self, public_key: &PublicKeyBase) -> 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
PublicKeyBase.
- public_key: The potential signer’s
-
Returns: This envelope.
-
Throws: Throws
EnvelopeError.unverifiedSignatureif the signature is not valid. valid.
sourcepub fn has_signatures_from<T>(&self, public_keys: &[T]) -> Result<bool>where
T: AsRef<PublicKeyBase>,
pub fn has_signatures_from<T>(&self, public_keys: &[T]) -> Result<bool>where
T: AsRef<PublicKeyBase>,
Checks whether the envelope’s subject has a set of signatures.
sourcepub fn has_signatures_from_threshold<T>(
&self,
public_keys: &[T],
threshold: Option<usize>
) -> Result<bool>where
T: AsRef<PublicKeyBase>,
pub fn has_signatures_from_threshold<T>(
&self,
public_keys: &[T],
threshold: Option<usize>
) -> Result<bool>where
T: AsRef<PublicKeyBase>,
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’
PublicKeyBases. - threshold: Optional minimum number of signers.
- public_keys: An array of potential signers’
-
Returns:
trueif the threshold of valid signatures is met,falseotherwise. -
Throws: Throws an exception if any
verifiedByassertion doesn’t contain a validSignatureas its object.
sourcepub fn verify_signatures_from<T>(&self, public_keys: &[T]) -> Result<Self>where
T: AsRef<PublicKeyBase>,
pub fn verify_signatures_from<T>(&self, public_keys: &[T]) -> Result<Self>where
T: AsRef<PublicKeyBase>,
Checks whether the envelope’s subject has a set of signatures.
sourcepub fn verify_signatures_from_threshold<T>(
&self,
public_keys: &[T],
threshold: Option<usize>
) -> Result<Self>where
T: AsRef<PublicKeyBase>,
pub fn verify_signatures_from_threshold<T>(
&self,
public_keys: &[T],
threshold: Option<usize>
) -> Result<Self>where
T: AsRef<PublicKeyBase>,
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’
PublicKeyBases. - threshold: Optional minimum number of signers.
- public_keys: An array of potential signers’
-
Returns: This envelope.
-
Throws: Throws an exception if the threshold of valid signatures is not met.
source§impl Envelope
impl Envelope
Support for decorrelation of envelopes using salt.
sourcepub fn add_salt(&self) -> Self
pub fn add_salt(&self) -> Self
Add a number of bytes of salt generally proportionate to the size of the object being salted.
sourcepub fn add_salt_instance(&self, salt: Salt) -> Self
pub fn add_salt_instance(&self, salt: Salt) -> Self
Add the given Salt as an assertion
sourcepub fn add_salt_with_len(&self, count: usize) -> Result<Self>
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.
sourcepub fn add_salt_in_range(&self, range: RangeInclusive<usize>) -> Result<Self>
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
impl Envelope
Support for splitting and combining envelopes using SSKR (Shamir’s Secret Sharing).
sourcepub fn sskr_split(
&self,
spec: &SSKRSpec,
content_key: &SymmetricKey
) -> Result<Vec<Vec<Envelope>>>
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 contentKey.
Each returned envelope will have an sskrShare: SSKRShare assertion added to
it.
-
Parameters:
- spec: The SSKR split specification.
- contentKey: The
SymmetricKeyused 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: SSKRShareassertion added to each.
sourcepub fn sskr_join(envelopes: &[&Envelope]) -> Result<Envelope>
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
impl Envelope
sourcepub fn add_type(&self, object: impl EnvelopeEncodable) -> Self
pub fn add_type(&self, object: impl EnvelopeEncodable) -> Self
Returns the result of adding the given 'IsA' type assertion to the envelope.
sourcepub fn get_type(&self) -> Result<Self>
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.
sourcepub fn has_type_envelope(&self, t: impl EnvelopeEncodable) -> bool
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.
sourcepub fn has_type(&self, t: &KnownValue) -> bool
pub fn has_type(&self, t: &KnownValue) -> bool
Returns true if the envelope has an 'IsA' type assertion with the given known value t.
sourcepub fn check_type(&self, t: &KnownValue) -> Result<()>
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.
sourcepub fn check_type_envelope(&self, t: impl EnvelopeEncodable) -> Result<()>
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
impl Envelope
pub fn sign(&self, sender: &PrivateKeyBase) -> Envelope
pub fn verify(&self, sender: &PublicKeyBase) -> Result<Envelope>
source§impl Envelope
impl Envelope
pub fn encrypt(&self, recipient: &PublicKeyBase) -> Result<Envelope>
pub fn decrypt(&self, recipient: &PrivateKeyBase) -> Result<Envelope>
source§impl Envelope
impl Envelope
pub fn seal( &self, sender: &PrivateKeyBase, recipient: &PublicKeyBase ) -> Result<Envelope>
pub fn unseal( &self, sender: &PublicKeyBase, recipient: &PrivateKeyBase ) -> Result<Envelope>
Trait Implementations§
source§impl CBORTagged for Envelope
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:
.nodecontains a CBOR array, the first element of which is the subject, followed by one or more assertions..leafis tagged #6.24, which is the IANA tag for embedded CBOR..wrappedis tagged with theenvelopetag..assertionis a single-element map{predicate: object}..knownValueis an unsigned 64-bit integer..encryptedis tagged with thecrypto-msgtag..elidedis a byte string of length 32.
source§impl CBORTaggedDecodable for Envelope
impl CBORTaggedDecodable for Envelope
source§fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
source§impl CBORTaggedEncodable for Envelope
impl CBORTaggedEncodable for Envelope
source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
source§impl DigestProvider for Envelope
impl DigestProvider for Envelope
Support for calculating the digests associated with Envelope.
source§impl EnvelopeFormat for Envelope
impl EnvelopeFormat for Envelope
fn format_item(&self, context: &FormatContext) -> EnvelopeFormatItem
source§impl From<EnvelopeCase> for Envelope
impl From<EnvelopeCase> for Envelope
source§fn from(case: EnvelopeCase) -> Self
fn from(case: EnvelopeCase) -> Self
source§impl TryFrom<Compressed> for Envelope
impl TryFrom<Compressed> for Envelope
source§impl TryFrom<EncryptedMessage> for Envelope
impl TryFrom<EncryptedMessage> for Envelope
Auto Trait Implementations§
impl Freeze for Envelope
impl RefUnwindSafe for Envelope
impl !Send for Envelope
impl !Sync for Envelope
impl Unpin for Envelope
impl UnwindSafe for Envelope
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
source§impl<T> EnvelopeEncodable for T
impl<T> EnvelopeEncodable for T
fn into_envelope(self) -> Envelope
fn to_envelope(&self) -> Envelopewhere
Self: Clone,
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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