pub struct MessageBuilder<'a> { /* private fields */ }Expand description
A struct used to construct a message.
It implements a Rust twist on the state pattern by returning intermediate
types: SignedMessage, SymEncryptedMessage and AsmEncryptedMessage.
They all implement the MessageFinal trait with the return types being:
Result<Message>forSymEncryptedMessageandAsmEncryptedMessage,MessageforSignedMessage.
In addition the SignedMessage type implements the following methods:
encrypt_for,encrypt_with, which have the same API and functionality as their counterparts defined inMessageBuilder.
§Example
A typical message build method call chain:
let msg = Message::new(&larry)? // start building a message (issuer: larry)
.write(&plaintext[..])? // add plaintext content to the message
.sign() // sign the message (issuer: larry)
.encrypt_for(&friends)? // asymmetrically encrypt the message (for friends)
.finalize()?; // finalize the message (returns Result<Message>)Implementations§
Source§impl<'a> MessageBuilder<'a>
impl<'a> MessageBuilder<'a>
Sourcepub fn write<R: Read>(self, content: R) -> Result<Self>
pub fn write<R: Read>(self, content: R) -> Result<Self>
Adds plaintext content to the message. content must implement the
Read trait.
§Errors
CryptoError::Unknownwhen a reading error or other error related to the reader object occured.
Sourcepub fn encrypt_with(
self,
passphrase: impl AsRef<[u8]>,
) -> Result<SymEncryptedMessage<'a>>
pub fn encrypt_with( self, passphrase: impl AsRef<[u8]>, ) -> Result<SymEncryptedMessage<'a>>
Symmetrically encrypt the message using a passphrase.
Sourcepub fn encrypt_for(
self,
recipients: &'a [Arc<Cert>],
) -> Result<AsmEncryptedMessage<'a>>
pub fn encrypt_for( self, recipients: &'a [Arc<Cert>], ) -> Result<AsmEncryptedMessage<'a>>
Asymmetrically encrypts the message for every recipient in recipients.
Auto Trait Implementations§
impl<'a> Freeze for MessageBuilder<'a>
impl<'a> RefUnwindSafe for MessageBuilder<'a>
impl<'a> Send for MessageBuilder<'a>
impl<'a> Sync for MessageBuilder<'a>
impl<'a> Unpin for MessageBuilder<'a>
impl<'a> UnwindSafe for MessageBuilder<'a>
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