pub struct Envelope {
pub ephemeral_key: Vec<u8>,
pub encrypted_content: Vec<u8>,
pub encrypted_headers: Vec<u8>,
}Expand description
An encrypted message envelope for transport.
Contains an ephemeral X25519 public key and XChaCha20-Poly1305 encrypted
headers and content. Created by Message::enclose_for and opened by
Envelope::open or Envelope::open_with_replay_guard.
§Examples
use ma_core::{generate_identity_from_secret, Message, Envelope, EncryptionKey, SigningKey, Did};
let alice = generate_identity_from_secret([1u8; 32]).unwrap();
let bob = generate_identity_from_secret([2u8; 32]).unwrap();
let alice_sign_url = Did::new_url(&alice.subject_url.ipns, None::<String>).unwrap();
let alice_key = SigningKey::from_private_key_bytes(
alice_sign_url,
hex::decode(&alice.signing_private_key_hex).unwrap().try_into().unwrap(),
).unwrap();
let msg = Message::new(
alice.document.id.clone(),
bob.document.id.clone(),
"text/plain",
b"secret".to_vec(),
&alice_key,
).unwrap();
// Encrypt for Bob
let envelope = msg.enclose_for(&bob.document).unwrap();
// Bob decrypts
let bob_enc_url = Did::new_url(&bob.subject_url.ipns, None::<String>).unwrap();
let bob_enc_key = EncryptionKey::from_private_key_bytes(
bob_enc_url,
hex::decode(&bob.encryption_private_key_hex).unwrap().try_into().unwrap(),
).unwrap();
let decrypted = envelope.open(&bob.document, &bob_enc_key, &alice.document).unwrap();
assert_eq!(decrypted.content, b"secret");Fields§
§ephemeral_key: Vec<u8>§encrypted_content: Vec<u8>§encrypted_headers: Vec<u8>Implementations§
Source§impl Envelope
impl Envelope
pub fn verify(&self) -> Result<()>
pub fn encode(&self) -> Result<Vec<u8>>
pub fn decode(bytes: &[u8]) -> Result<Self>
pub fn open( &self, recipient_document: &Document, recipient_key: &EncryptionKey, sender_document: &Document, ) -> Result<Message>
pub fn open_with_replay_guard( &self, recipient_document: &Document, recipient_key: &EncryptionKey, sender_document: &Document, replay_guard: &mut ReplayGuard, ) -> Result<Message>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Envelope
impl<'de> Deserialize<'de> for Envelope
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Envelope
impl StructuralPartialEq 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 UnsafeUnpin 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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