pub struct Decrypter<In>where
In: Read,{ /* private fields */ }stream only.Expand description
A streaming AES-GCM-SIV 256-bits decrypter.
Implements the Read trait to provide streaming, while internally keeping a
buffer of the chunk to decrypt as a single message.
Note: The size of the chunk used must match the chunk size used by the Encrypter. The decryption
will fail if there is a mismatch.
§Examples
use std::io::BufRead;
let key = get_key();
let decrypter = crypter::stream::Decrypter::new(&key, stdin())
.expect("Failed to read from stdin");
let reader = std::io::BufReader::new(decrypter);
for line in reader.lines() {
let line = line.expect("Failed to read from stdin");
println!("{line}");
}Implementations§
Source§impl<In> Decrypter<In>where
In: Read,
impl<In> Decrypter<In>where
In: Read,
Sourcepub fn new<'k, Key>(key: Key, input: In) -> Result<Self>
pub fn new<'k, Key>(key: Key, input: In) -> Result<Self>
Creates a new Decrypter using the reader input and a default size DEFAULT_CHUNK decrypted
with the cryptographic key key.
§Errors
When initializing, the Decrypter will read the first few bytes of input. If any error
happens at that stage, this function will fail.
Sourcepub fn new_with_password<Password>(
password: Password,
input: In,
) -> Result<Self>
Available on crate feature argon only.
pub fn new_with_password<Password>( password: Password, input: In, ) -> Result<Self>
argon only.Creates a new Decrypter using the reader input and a default size DEFAULT_CHUNK decrypted
with the cryptographic key derived from password using Argon2.
§Errors
- If the key derivation fails, an
InvalidDatais returned; - When initializing, the
Decrypterwill read the first few bytes ofinput. If any error happens at that stage, this function will fail.
Sourcepub fn with_chunk<'k, Key>(key: Key, input: In, chunk: usize) -> Result<Self>
pub fn with_chunk<'k, Key>(key: Key, input: In, chunk: usize) -> Result<Self>
Creates a new Decrypter using the reader input and a chunk size chunk decrypted
with the cryptographic key key.
§Errors
- If the value of
chunkis less than 32, anInvalidInputis returned. - When initializing, the
Decrypterwill read the first few bytes ofinput. If any error happens at that stage, this function will fail.
Sourcepub fn with_chunk_with_password<Password>(
password: Password,
input: In,
chunk: usize,
) -> Result<Self>
Available on crate feature argon only.
pub fn with_chunk_with_password<Password>( password: Password, input: In, chunk: usize, ) -> Result<Self>
argon only.Creates a new Decrypter using the reader input and a chunk size chunk decrypted
with the cryptographic key derived from password using Argon2.
§Errors
- If the value of
chunkis less than 32, anInvalidInputis returned. - If the key derivation fails, an
InvalidDatais returned; - When initializing, the
Decrypterwill read the first few bytes ofinput. If any error happens at that stage, this function will fail.
Trait Implementations§
Source§impl<In> Read for Decrypter<In>where
In: Read,
impl<In> Read for Decrypter<In>where
In: Read,
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)