pub struct Assertion { /* private fields */ }Expand description
A predicate-object relationship representing an assertion about a subject.
In Gordian Envelope, assertions are the basic building blocks for attaching information to a subject. An assertion consists of a predicate (which states what is being asserted) and an object (which provides the assertion’s value).
Assertions can be attached to envelope subjects to form semantic statements like: “subject hasAttribute value” or “document signedBy signature”.
Assertions are equivalent to RDF (Resource Description Framework) triples, where:
- The envelope’s subject is the subject of the triple
- The assertion’s predicate is the predicate of the triple
- The assertion’s object is the object of the triple
Generally you do not create an instance of this type directly, but
instead use Envelope::new_assertion, or the various functions
on Envelope that create assertions.
Implementations§
Source§impl Assertion
impl Assertion
Sourcepub fn new(
predicate: impl EnvelopeEncodable,
object: impl EnvelopeEncodable,
) -> Self
pub fn new( predicate: impl EnvelopeEncodable, object: impl EnvelopeEncodable, ) -> Self
Creates a new assertion and calculates its digest.
This constructor takes a predicate and object, both of which are
converted to envelopes using the EnvelopeEncodable trait. It then
calculates the assertion’s digest by combining the digests of the
predicate and object.
The digest is calculated according to the Gordian Envelope specification, which ensures that semantically equivalent assertions always produce the same digest.
§Parameters
predicate- The predicate of the assertion, which states what is being assertedobject- The object of the assertion, which provides the assertion’s value
§Returns
A new assertion with the specified predicate, object, and calculated digest.
§Example
// Direct method - create an assertion envelope
let assertion_envelope = Envelope::new_assertion("name", "Alice");
// Or create and add an assertion to a subject
let person = Envelope::new("person").add_assertion("name", "Alice");Sourcepub fn predicate(&self) -> Envelope
pub fn predicate(&self) -> Envelope
Returns the predicate of the assertion.
The predicate states what is being asserted about the subject. It is typically a string or known value, but can be any envelope.
§Returns
A clone of the assertion’s predicate envelope.
Sourcepub fn object(&self) -> Envelope
pub fn object(&self) -> Envelope
Returns the object of the assertion.
The object provides the value or content of the assertion. It can be any type that can be represented as an envelope.
§Returns
A clone of the assertion’s object envelope.
Sourcepub fn digest_ref(&self) -> &Digest
pub fn digest_ref(&self) -> &Digest
Returns a reference to the digest of the assertion.
The digest is calculated when the assertion is created and is used for verification and deduplication. The digest calculation follows the rules specified in the Gordian Envelope IETF draft, Section 4.4.
§Returns
A reference to the assertion’s digest.
Source§impl Assertion
Support for adding vendor-specific attachments to Gordian Envelopes.
impl Assertion
Support for adding vendor-specific attachments to Gordian Envelopes.
This module extends Gordian Envelope with the ability to add vendor-specific attachments to an envelope. Attachments provide a standardized way for different applications to include their own data in an envelope without interfering with the main data structure or with other attachments.
Each attachment has:
- A payload (arbitrary data)
- A required vendor identifier (typically a reverse domain name)
- An optional conformsTo URI that indicates the format of the attachment
This allows for a common envelope format that can be extended by different vendors while maintaining interoperability.
§Example
use bc_envelope::prelude::*;
// Create a base envelope
let envelope = Envelope::new("Alice").add_assertion("knows", "Bob");
// Add a vendor-specific attachment
let with_attachment = envelope.add_attachment(
"Custom data for this envelope",
"com.example",
Some("https://example.com/attachment-format/v1"),
);
// The attachment is added as an assertion with the 'attachment' predicate
assert!(
!with_attachment
.assertions_with_predicate(known_values::ATTACHMENT)
.is_empty()
);
// The attachment can be extracted later
let attachment = with_attachment.attachments().unwrap()[0].clone();
let payload = attachment.attachment_payload().unwrap();
let vendor = attachment.attachment_vendor().unwrap();
let format = attachment.attachment_conforms_to().unwrap();
assert_eq!(payload.format_flat(), r#""Custom data for this envelope""#);
assert_eq!(vendor, "com.example");
assert_eq!(
format,
Some("https://example.com/attachment-format/v1".to_string())
);Methods for creating and accessing attachments at the assertion level
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
Creates a new attachment assertion.
An attachment assertion consists of:
- The predicate
known_values::ATTACHMENT - An object that is a wrapped envelope containing:
- The payload (as the subject)
- A required
'vendor': Stringassertion - An optional
'conformsTo': Stringassertion
See BCR-2023-006 for the detailed specification.
§Parameters
payload- The content of the attachmentvendor- A string that uniquely identifies the vendor (typically a reverse domain name)conforms_to- An optional URI that identifies the format of the attachment
§Returns
A new attachment assertion
§Examples
Example:
Create an attachment assertion that contains vendor-specific data, then use it to access the payload, vendor ID, and conformsTo value.
The assertion will have a predicate of “attachment” and an object that’s a wrapped envelope containing the payload with vendor and conformsTo assertions added to it.
Sourcepub fn attachment_payload(&self) -> Result<Envelope>
pub fn attachment_payload(&self) -> Result<Envelope>
Sourcepub fn attachment_vendor(&self) -> Result<String>
pub fn attachment_vendor(&self) -> Result<String>
Sourcepub fn attachment_conforms_to(&self) -> Result<Option<String>>
pub fn attachment_conforms_to(&self) -> Result<Option<String>>
Sourcepub fn validate_attachment(&self) -> Result<()>
pub fn validate_attachment(&self) -> Result<()>
Validates that an assertion is a proper attachment assertion.
This ensures:
- The attachment assertion’s predicate is
known_values::ATTACHMENT - The attachment assertion’s object is an envelope
- The attachment assertion’s object has a
'vendor': Stringassertion - The attachment assertion’s object has an optional
'conformsTo': Stringassertion
§Returns
Ok(()) if the assertion is a valid attachment assertion
§Errors
Returns EnvelopeError::InvalidAttachment if the assertion is not a
valid attachment assertion
Trait Implementations§
Source§impl DigestProvider for Assertion
Implementation of DigestProvider for Assertion.
impl DigestProvider for Assertion
Implementation of DigestProvider for Assertion.
This allows an assertion to provide its digest for calculation of higher-level digests in the envelope digest tree.
Source§impl EnvelopeEncodable for Assertion
Implementation of EnvelopeEncodable for Assertion.
impl EnvelopeEncodable for Assertion
Implementation of EnvelopeEncodable for Assertion.
This implementation converts an assertion into an envelope with the assertion as its subject.
Source§fn into_envelope(self) -> Envelope
fn into_envelope(self) -> Envelope
Creates an envelope with this assertion as its subject.
Source§impl From<Assertion> for CBOR
Converts an assertion to its CBOR representation.
impl From<Assertion> for CBOR
Converts an assertion to its CBOR representation.
The CBOR representation of an assertion is a map with a single key-value pair, where the key is the predicate’s CBOR and the value is the object’s CBOR.
Source§impl PartialEq for Assertion
Equality is based on digest equality, not structural equality.
impl PartialEq for Assertion
Equality is based on digest equality, not structural equality.
Two assertions are considered equal if they have the same digest, regardless of how they were constructed.
Source§impl TryFrom<CBOR> for Assertion
Attempts to convert a CBOR value to an assertion.
impl TryFrom<CBOR> for Assertion
Attempts to convert a CBOR value to an assertion.
The CBOR must be a map with exactly one entry, where the key represents the predicate and the value represents the object.
Source§impl TryFrom<Map> for Assertion
Attempts to convert a CBOR map to an assertion.
impl TryFrom<Map> for Assertion
Attempts to convert a CBOR map to an assertion.
The map must have exactly one entry, where the key represents the predicate and the value represents the object. This is used in the deserialization process.
impl Eq for Assertion
Assertion implements full equality.
Auto Trait Implementations§
impl Freeze for Assertion
impl RefUnwindSafe for Assertion
impl !Send for Assertion
impl !Sync for Assertion
impl Unpin for Assertion
impl UnwindSafe for Assertion
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: 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