Skip to main content

Cipher

Trait Cipher 

Source
pub trait Cipher:
    Random
    + Sized
    + Send
    + Sync
    + 'static {
    type Tag: Array;

    // Required methods
    fn seal(self, aad: &[u8], data: &mut [u8]) -> Option<(Self, Self::Tag)>;
    fn open(self, aad: &[u8], data: &mut [u8], tag: &Self::Tag) -> Option<Self>;
}
Expand description

Authenticated encryption of an ordered sequence of messages.

Every message is encrypted and authenticated with its associated data. The nth call to Cipher::open accepts only the nth message sealed under the same key, so replayed, reordered, or modified messages fail to open. A failed call consumes the cipher. At most one instance may seal under a given key.

Required Associated Types§

Source

type Tag: Array

Authentication tag produced for each message.

Required Methods§

Source

fn seal(self, aad: &[u8], data: &mut [u8]) -> Option<(Self, Self::Tag)>

Encrypts the next message in place, authenticated together with aad, and returns the cipher with the tag.

Returns None if sealing fails, in which case the contents of data are unspecified.

Source

fn open(self, aad: &[u8], data: &mut [u8], tag: &Self::Tag) -> Option<Self>

Decrypts the next message in place if tag authenticates it together with aad, and returns the cipher.

Returns None if opening fails, in which case the contents of data are unspecified.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§