Skip to main content

Token

Struct Token 

Source
pub struct Token { /* private fields */ }

Implementations§

Source§

impl Token

Source

pub fn new(key: &[u8]) -> Result<Self, TokenError>

Source

pub fn encrypt(&self, plaintext: &[u8], rng: &mut dyn Rng) -> Vec<u8> ⓘ

Source

pub fn token_len(plaintext_len: usize) -> usize

Length of the token Token::encrypt produces for a plaintext of plaintext_len bytes.

Source

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.

Source

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.

Source

pub fn encrypt_with_iv(&self, plaintext: &[u8], iv: &[u8; 16]) -> Vec<u8> ⓘ

Source

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.

Source

pub fn verify_hmac(&self, token: &[u8]) -> Result<bool, TokenError>

Source

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.

Source

pub fn decrypt(&self, token: &[u8]) -> Result<Vec<u8>, TokenError>

Source

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.

Source

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.

Auto Trait Implementations§

§

impl Forget for Token

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin for Token

§

impl UnsafeUnpin for Token

§

impl UnwindSafe for Token

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.