StrongBox

Trait StrongBox 

Source
pub trait StrongBox {
    // Required methods
    fn encrypt(
        &self,
        plaintext: impl AsRef<[u8]>,
        context: impl AsRef<[u8]> + Debug,
    ) -> Result<Vec<u8>, Error>;
    fn decrypt(
        &self,
        ciphertext: impl AsRef<[u8]>,
        context: impl AsRef<[u8]> + Debug,
    ) -> Result<Vec<u8>, Error>;
}
Expand description

Core trait that all the various forms of encrypting StrongBoxes implement to provide encryption / decryption functionality.

Required Methods§

Source

fn encrypt( &self, plaintext: impl AsRef<[u8]>, context: impl AsRef<[u8]> + Debug, ) -> Result<Vec<u8>, Error>

Encrypt secret data using the StrongBox’s encryption key, within the StrongBox’s specified context.

§Errors

Will return Error::Encryption or Error::Encoding in the (extremely unlikely) event something goes horribly wrong.

Source

fn decrypt( &self, ciphertext: impl AsRef<[u8]>, context: impl AsRef<[u8]> + Debug, ) -> Result<Vec<u8>, Error>

Decrypt a ciphertext, using any valid key for the StrongBox, and validate that the ciphertext was encrypted with the specified context.

§Errors

Will return one of the following:

  • Error::Decryption if the ciphertext was encrypted with a different key, or a different context.
  • Error::Decoding if the ciphertext was malformed, which means that either the ciphertext was corrupted in storage or transit, or the data provided was never a ciphertext.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§