pub struct Token { /* private fields */ }Implementations§
Source§impl Token
impl Token
pub fn new(key: &[u8]) -> Result<Self, TokenError>
pub fn encrypt(&self, plaintext: &[u8], rng: &mut dyn Rng) -> Vec<u8> ⓘ
Sourcepub fn token_len(plaintext_len: usize) -> usize
pub fn token_len(plaintext_len: usize) -> usize
Length of the token Token::encrypt produces for a plaintext of
plaintext_len bytes.
Sourcepub fn encrypt_into(&self, plaintext: &[u8], rng: &mut dyn Rng, out: &mut [u8])
pub fn encrypt_into(&self, plaintext: &[u8], rng: &mut dyn Rng, out: &mut [u8])
Token::encrypt into out, which must be exactly
Token::token_len(plaintext.len()) bytes long.
Sourcepub fn encrypt_with_iv_into(
&self,
plaintext: &[u8],
iv: &[u8; 16],
out: &mut [u8],
)
pub fn encrypt_with_iv_into( &self, plaintext: &[u8], iv: &[u8; 16], out: &mut [u8], )
Token::encrypt_with_iv into out, which must be exactly
Token::token_len(plaintext.len()) bytes long.
pub fn encrypt_with_iv(&self, plaintext: &[u8], iv: &[u8; 16]) -> Vec<u8> ⓘ
Sourcepub fn encrypt_untagged(
&self,
plaintext: &[u8],
rng: &mut dyn Rng,
) -> (Vec<u8>, HmacSha256)
pub fn encrypt_untagged( &self, plaintext: &[u8], rng: &mut dyn Rng, ) -> (Vec<u8>, HmacSha256)
Token::encrypt with the tag left to the caller: the token’s last
32 bytes are zero, and the returned MAC, fed every byte before them,
finalizes to the tag. The caller can hash those bytes together with
other data before writing it.
pub fn verify_hmac(&self, token: &[u8]) -> Result<bool, TokenError>
Sourcepub fn decrypt_into(
&self,
token: &[u8],
out: &mut Vec<u8>,
) -> Result<(), TokenError>
pub fn decrypt_into( &self, token: &[u8], out: &mut Vec<u8>, ) -> Result<(), TokenError>
Token::decrypt into out, replacing its contents and reusing
its capacity. On error out holds no plaintext.
pub fn decrypt(&self, token: &[u8]) -> Result<Vec<u8>, TokenError>
Sourcepub fn decrypt_chunks(
&self,
chunks: &[&[u8]],
skip: usize,
) -> Result<Vec<u8>, TokenError>
pub fn decrypt_chunks( &self, chunks: &[&[u8]], skip: usize, ) -> Result<Vec<u8>, TokenError>
Decrypt a token that arrives as consecutive chunks, such as the parts
of a resource, without joining them first. Each chunk is authenticated
and decrypted while it is still in cache; nothing is returned unless
the tag matches. The result is Token::decrypt of the joined bytes
with its first skip bytes (at most one block) dropped, and the errors
are the same, except that a plaintext shorter than skip is
TokenError::DecryptionFailed.
Sourcepub fn decrypt_stream(&self, skip: usize) -> TokenDecryptStream
pub fn decrypt_stream(&self, skip: usize) -> TokenDecryptStream
Start a Token::decrypt_chunks whose chunks are fed one at a time,
as they become available.