pub struct MessageBuilder<'a, R = DummyReader, E = NoEncryption> { /* private fields */ }
Expand description
Constructs message from a given data source.
All data is processed in a streaming fashion, with minimal memory allocations.
If the file size is known upfront (fixed buffer, or file source), the resulting packets will be fixed size lengths (unless compression is involved).
If the file size is not known upfront, partial packets will be generated, at each level (encryption, compression, literal data).
If the total data fits into a single chunk, a single fixed packet is generated.
Implementations§
Source§impl Builder<'_, DummyReader>
impl Builder<'_, DummyReader>
Source§impl<'a, R: Read> Builder<'a, R, NoEncryption>
impl<'a, R: Read> Builder<'a, R, NoEncryption>
Sourcepub fn seipd_v1<RAND>(
self,
rng: RAND,
sym_alg: SymmetricKeyAlgorithm,
) -> Builder<'a, R, EncryptionSeipdV1>
pub fn seipd_v1<RAND>( self, rng: RAND, sym_alg: SymmetricKeyAlgorithm, ) -> Builder<'a, R, EncryptionSeipdV1>
Encrypt this message using Seipd V1.
Source§impl<'a, R: Read> Builder<'a, R, NoEncryption>
impl<'a, R: Read> Builder<'a, R, NoEncryption>
Sourcepub fn seipd_v2<RAND>(
self,
rng: RAND,
sym_alg: SymmetricKeyAlgorithm,
aead: AeadAlgorithm,
chunk_size: ChunkSize,
) -> Builder<'a, R, EncryptionSeipdV2>
pub fn seipd_v2<RAND>( self, rng: RAND, sym_alg: SymmetricKeyAlgorithm, aead: AeadAlgorithm, chunk_size: ChunkSize, ) -> Builder<'a, R, EncryptionSeipdV2>
Encrypt this message using Seipd V2.
Source§impl<R: Read> Builder<'_, R, EncryptionSeipdV1>
impl<R: Read> Builder<'_, R, EncryptionSeipdV1>
Sourcepub fn set_session_key(&mut self, sk: RawSessionKey) -> Result<&mut Self>
pub fn set_session_key(&mut self, sk: RawSessionKey) -> Result<&mut Self>
Overwrite the auto-generated session key with a user-provided one.
May only be called before adding any keys or symmetric message passwords!
CAUTION: The session key must be generated appropriately! If it’s not random, then encryption based on it does not provide privacy!
Sourcepub fn encrypt_to_key<RAND, K>(
&mut self,
rng: RAND,
pkey: &K,
) -> Result<&mut Self>
pub fn encrypt_to_key<RAND, K>( &mut self, rng: RAND, pkey: &K, ) -> Result<&mut Self>
Encrypt to a public key
Sourcepub fn encrypt_to_key_anonymous<RAND, K>(
&mut self,
rng: RAND,
pkey: &K,
) -> Result<&mut Self>
pub fn encrypt_to_key_anonymous<RAND, K>( &mut self, rng: RAND, pkey: &K, ) -> Result<&mut Self>
Encrypt to a public key, but leave the recipient field unset
Sourcepub fn encrypt_with_password(
&mut self,
s2k: StringToKey,
msg_pw: &Password,
) -> Result<&mut Self>
pub fn encrypt_with_password( &mut self, s2k: StringToKey, msg_pw: &Password, ) -> Result<&mut Self>
Encrypt to a password.
Sourcepub fn session_key(&self) -> &RawSessionKey
pub fn session_key(&self) -> &RawSessionKey
Returns the currently used session key.
WARNING: this is sensitive material, and leaking it can lead to a compromise of the data.
Source§impl<R: Read> Builder<'_, R, EncryptionSeipdV2>
impl<R: Read> Builder<'_, R, EncryptionSeipdV2>
Sourcepub fn set_session_key(&mut self, sk: RawSessionKey) -> Result<&mut Self>
pub fn set_session_key(&mut self, sk: RawSessionKey) -> Result<&mut Self>
Overwrite the auto-generated session key with a user-provided one.
May only be called before adding any keys or symmetric message passwords!
CAUTION: The session key must be generated appropriately! If it’s not random, then encryption based on it does not provide privacy!
Sourcepub fn encrypt_to_key<RAND, K>(
&mut self,
rng: RAND,
pkey: &K,
) -> Result<&mut Self>
pub fn encrypt_to_key<RAND, K>( &mut self, rng: RAND, pkey: &K, ) -> Result<&mut Self>
Encrypt to a public key
Sourcepub fn encrypt_to_key_anonymous<RAND, K>(
&mut self,
rng: RAND,
pkey: &K,
) -> Result<&mut Self>
pub fn encrypt_to_key_anonymous<RAND, K>( &mut self, rng: RAND, pkey: &K, ) -> Result<&mut Self>
Encrypt to a public key, but leave the recipient field unset
Sourcepub fn encrypt_with_password<RAND>(
&mut self,
rng: RAND,
s2k: StringToKey,
msg_pw: &Password,
) -> Result<&mut Self>
pub fn encrypt_with_password<RAND>( &mut self, rng: RAND, s2k: StringToKey, msg_pw: &Password, ) -> Result<&mut Self>
Encrypt to a password.
Sourcepub fn session_key(&self) -> &RawSessionKey
pub fn session_key(&self) -> &RawSessionKey
Returns the currently used session key.
WARNING: this is sensitive material, and leaking it can lead to a compromise of the data.
Source§impl<R: Read> Builder<'_, R, NoEncryption>
impl<R: Read> Builder<'_, R, NoEncryption>
Sourcepub fn from_reader(file_name: impl Into<Bytes>, reader: R) -> Self
pub fn from_reader(file_name: impl Into<Bytes>, reader: R) -> Self
Source the data from a reader.
Source§impl<'a, R: Read, E: Encryption> Builder<'a, R, E>
impl<'a, R: Read, E: Encryption> Builder<'a, R, E>
Sourcepub fn data_mode(&mut self, mode: DataMode) -> Result<&mut Self>
pub fn data_mode(&mut self, mode: DataMode) -> Result<&mut Self>
Configure the DataMode
for the literal data portion.
Defaults to DataMode::Binary
Alternatively, DataMode::Utf8
is supported.
In this case, the payload must be valid UTF-8, with CR-LF line endings!
Sourcepub fn sign_binary(&mut self) -> &mut Self
pub fn sign_binary(&mut self) -> &mut Self
Configure the data signatures to use SignatureType::Binary
.
This is the default.
Sourcepub fn sign_text(&mut self) -> &mut Self
pub fn sign_text(&mut self) -> &mut Self
Configure the data signatures to use SignatureType::Text
.
Sourcepub fn partial_chunk_size(&mut self, size: u32) -> Result<&mut Self>
pub fn partial_chunk_size(&mut self, size: u32) -> Result<&mut Self>
Set the chunk size, which controls how large partial packets will be.
Due to the restrictions on partial packet lengths, this size
- must be larger than
512
, - must be a power of 2.
Defaults to DEFAULT_PARTIAL_CHUNK_SIZE
.
Sourcepub fn compression(&mut self, compression: CompressionAlgorithm) -> &mut Self
pub fn compression(&mut self, compression: CompressionAlgorithm) -> &mut Self
Configure compression.
Defaults to no compression.
Sourcepub fn sign(
&mut self,
key: &'a dyn SecretKeyTrait,
key_pw: Password,
hash_algorithm: HashAlgorithm,
) -> &mut Self
pub fn sign( &mut self, key: &'a dyn SecretKeyTrait, key_pw: Password, hash_algorithm: HashAlgorithm, ) -> &mut Self
Produce a data signature with the signing key key
.
Sourcepub fn sign_with_subpackets(
&mut self,
key: &'a dyn SecretKeyTrait,
key_pw: Password,
hash_algorithm: HashAlgorithm,
subpackets: SubpacketConfig,
) -> &mut Self
pub fn sign_with_subpackets( &mut self, key: &'a dyn SecretKeyTrait, key_pw: Password, hash_algorithm: HashAlgorithm, subpackets: SubpacketConfig, ) -> &mut Self
Produce a data signature with the signing key key
and an explicit subpacket configuration.
This gives callers full control of the hashed and unhashed subpacket areas.
Sourcepub fn to_writer<RAND, W>(self, rng: RAND, out: W) -> Result<()>
pub fn to_writer<RAND, W>(self, rng: RAND, out: W) -> Result<()>
Write the data out to a writer.
Sourcepub fn to_armored_writer<RAND, W>(
self,
rng: RAND,
opts: ArmorOptions<'_>,
out: W,
) -> Result<()>
pub fn to_armored_writer<RAND, W>( self, rng: RAND, opts: ArmorOptions<'_>, out: W, ) -> Result<()>
Write the data not as binary, but ascii armor encoded.
Sourcepub fn to_file<RAND, P>(self, rng: RAND, out_path: P) -> Result<()>
pub fn to_file<RAND, P>(self, rng: RAND, out_path: P) -> Result<()>
Write the data out directly to a file.
Sourcepub fn to_armored_file<RAND, P>(
self,
rng: RAND,
out_path: P,
opts: ArmorOptions<'_>,
) -> Result<()>
pub fn to_armored_file<RAND, P>( self, rng: RAND, out_path: P, opts: ArmorOptions<'_>, ) -> Result<()>
Write the data out directly to a file.
Sourcepub fn to_vec<RAND>(self, rng: RAND) -> Result<Vec<u8>>
pub fn to_vec<RAND>(self, rng: RAND) -> Result<Vec<u8>>
Write the data out directly to a Vec<u8>
.
Sourcepub fn to_armored_string<RAND>(
self,
rng: RAND,
opts: ArmorOptions<'_>,
) -> Result<String>
pub fn to_armored_string<RAND>( self, rng: RAND, opts: ArmorOptions<'_>, ) -> Result<String>
Write the data as ascii armored data, directly to a String
.
Auto Trait Implementations§
impl<'a, R = Cursor<Vec<u8>>, E = NoEncryption> !Freeze for Builder<'a, R, E>
impl<'a, R = Cursor<Vec<u8>>, E = NoEncryption> !RefUnwindSafe for Builder<'a, R, E>
impl<'a, R = Cursor<Vec<u8>>, E = NoEncryption> !Send for Builder<'a, R, E>
impl<'a, R = Cursor<Vec<u8>>, E = NoEncryption> !Sync for Builder<'a, R, E>
impl<'a, R, E> Unpin for Builder<'a, R, E>
impl<'a, R = Cursor<Vec<u8>>, E = NoEncryption> !UnwindSafe for Builder<'a, R, E>
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.