pub struct EncryptedMessage { /* private fields */ }Expand description
A secure encrypted message using IETF ChaCha20-Poly1305 authenticated encryption.
EncryptedMessage represents data that has been encrypted using a symmetric key with the
ChaCha20-Poly1305 AEAD (Authenticated Encryption with Associated Data) construction as
specified in RFC-8439.
An EncryptedMessage contains:
ciphertext: The encrypted data (same length as the original plaintext)aad: Additional Authenticated Data that is not encrypted but is authenticated (optional)nonce: A 12-byte number used once for this specific encryption operationauth: A 16-byte authentication tag that verifies the integrity of the message
The aad field is often used to include the Digest of the plaintext, which allows
verification of the plaintext after decryption and preserves the unique identity of
the data when used with structures like Gordian Envelope.
To facilitate decoding, it is recommended that the plaintext of an EncryptedMessage be
tagged CBOR.
CDDL:
EncryptedMessage =
#6.40002([ ciphertext: bstr, nonce: bstr, auth: bstr, ? aad: bstr ]) ; TAG_ENCRYPTEDImplementations§
Source§impl EncryptedMessage
impl EncryptedMessage
Sourcepub fn new(
ciphertext: impl Into<Vec<u8>>,
aad: impl Into<Vec<u8>>,
nonce: Nonce,
auth: AuthenticationTag,
) -> Self
pub fn new( ciphertext: impl Into<Vec<u8>>, aad: impl Into<Vec<u8>>, nonce: Nonce, auth: AuthenticationTag, ) -> Self
Restores an EncryptedMessage from its CBOR representation.
This is a low-level function that is not normally needed.
Sourcepub fn ciphertext(&self) -> &Vec<u8> ⓘ
pub fn ciphertext(&self) -> &Vec<u8> ⓘ
Returns a reference to the ciphertext data.
Sourcepub fn aad(&self) -> &Vec<u8> ⓘ
pub fn aad(&self) -> &Vec<u8> ⓘ
Returns a reference to the additional authenticated data (AAD).
Sourcepub fn authentication_tag(&self) -> &AuthenticationTag
pub fn authentication_tag(&self) -> &AuthenticationTag
Returns a reference to the authentication tag value used for encryption.
Sourcepub fn opt_digest(&self) -> Option<Digest>
pub fn opt_digest(&self) -> Option<Digest>
Returns an optional Digest instance if the AAD data can be parsed as CBOR.
Sourcepub fn has_digest(&self) -> bool
pub fn has_digest(&self) -> bool
Returns true if the AAD data can be parsed as CBOR.
Trait Implementations§
Source§impl AsRef<EncryptedMessage> for EncryptedMessage
Implements AsRef<EncryptedMessage> to allow self-reference.
impl AsRef<EncryptedMessage> for EncryptedMessage
Implements AsRef<EncryptedMessage> to allow self-reference.
Source§fn as_ref(&self) -> &EncryptedMessage
fn as_ref(&self) -> &EncryptedMessage
Source§impl CBORTagged for EncryptedMessage
Implements CBORTagged to provide the CBOR tag for the EncryptedMessage.
impl CBORTagged for EncryptedMessage
Implements CBORTagged to provide the CBOR tag for the EncryptedMessage.
Source§impl CBORTaggedDecodable for EncryptedMessage
Implements CBORTaggedDecodable to provide CBOR decoding functionality.
impl CBORTaggedDecodable for EncryptedMessage
Implements CBORTaggedDecodable to provide CBOR decoding functionality.
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 EncryptedMessage
Implements CBORTaggedEncodable to provide CBOR encoding functionality.
impl CBORTaggedEncodable for EncryptedMessage
Implements CBORTaggedEncodable to provide CBOR encoding functionality.
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for EncryptedMessage
impl Clone for EncryptedMessage
Source§fn clone(&self) -> EncryptedMessage
fn clone(&self) -> EncryptedMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EncryptedMessage
Implements Debug formatting to display the message contents in a structured format.
impl Debug for EncryptedMessage
Implements Debug formatting to display the message contents in a structured format.
Source§impl DigestProvider for EncryptedMessage
Implements DigestProvider to provide the digest stored in the AAD field.
impl DigestProvider for EncryptedMessage
Implements DigestProvider to provide the digest stored in the AAD field.
Source§impl From<EncryptedMessage> for CBOR
Implements conversion from EncryptedMessage to CBOR for serialization.
impl From<EncryptedMessage> for CBOR
Implements conversion from EncryptedMessage to CBOR for serialization.
Source§fn from(value: EncryptedMessage) -> Self
fn from(value: EncryptedMessage) -> Self
Source§impl PartialEq for EncryptedMessage
impl PartialEq for EncryptedMessage
Source§impl TryFrom<CBOR> for EncryptedMessage
Implements TryFrom<CBOR> for EncryptedMessage to support conversion from CBOR data.
impl TryFrom<CBOR> for EncryptedMessage
Implements TryFrom<CBOR> for EncryptedMessage to support conversion from CBOR data.