Skip to main content

EncryptionAlgorithm

Trait EncryptionAlgorithm 

Source
pub trait EncryptionAlgorithm {
    type Meta: Serialize + DeserializeOwned;
    type Secrets: Serialize + DeserializeOwned;
    type Context: EncryptionContext;

    // Required methods
    fn alg() -> &'static str;
    fn generate(
        &self,
        rng: impl RngCore + CryptoRng,
    ) -> Result<(Key, Self::Secrets), AlgorithmError>;
    fn open_inner(
        &self,
        meta: &Self::Meta,
        secrets: &Self::Secrets,
    ) -> Result<Self::Context, AlgorithmError>;
    fn encrypt_inner(
        &self,
        rng: impl RngCore + CryptoRng,
        recipient: &PubRecord,
        payload: &[u8],
        aad: &[u8],
    ) -> Result<(Self::Meta, Vec<u8>), AlgorithmError>;

    // Provided methods
    fn info() -> Vec<u8>  { ... }
    fn open(
        &self,
        info: &EncryptionInfo,
        secrets: &[u8],
    ) -> Result<Self::Context, AlgorithmError> { ... }
    fn encrypt<T>(
        &self,
        rng: impl RngCore + CryptoRng,
        recipient: &PubRecord,
        payload: &[u8],
        aad: &[u8],
    ) -> Result<Payload<T>, AlgorithmError> { ... }
}

Required Associated Types§

Required Methods§

Source

fn alg() -> &'static str

Source

fn generate( &self, rng: impl RngCore + CryptoRng, ) -> Result<(Key, Self::Secrets), AlgorithmError>

Source

fn open_inner( &self, meta: &Self::Meta, secrets: &Self::Secrets, ) -> Result<Self::Context, AlgorithmError>

Source

fn encrypt_inner( &self, rng: impl RngCore + CryptoRng, recipient: &PubRecord, payload: &[u8], aad: &[u8], ) -> Result<(Self::Meta, Vec<u8>), AlgorithmError>

Provided Methods§

Source

fn info() -> Vec<u8>

Source

fn open( &self, info: &EncryptionInfo, secrets: &[u8], ) -> Result<Self::Context, AlgorithmError>

Source

fn encrypt<T>( &self, rng: impl RngCore + CryptoRng, recipient: &PubRecord, payload: &[u8], aad: &[u8], ) -> Result<Payload<T>, AlgorithmError>

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.

Implementations on Foreign Types§

Source§

impl EncryptionAlgorithm for X25519XChaCha20Poly1305

Implementors§