Skip to main content

nectar_primitives/chunk/encryption/
mod.rs

1//! Chunk encryption using Keccak-256 counter-mode cipher.
2
3mod chunk;
4mod cipher;
5mod error;
6mod key;
7mod reference;
8
9pub(crate) use chunk::decrypt_chunk_data;
10#[cfg(feature = "encryption")]
11pub(crate) use chunk::encrypt_chunk;
12pub use cipher::{transcrypt, transcrypt_in_place};
13pub use error::EncryptionError;
14pub use key::EncryptionKey;
15pub use reference::EncryptedChunkRef;
16
17/// Trait for encrypting chunks with a Keccak-256 counter-mode cipher.
18#[cfg(feature = "encryption")]
19pub trait ChunkEncrypt {
20    /// The encrypted output type.
21    type Encrypted;
22
23    /// Encrypt with a caller-provided key.
24    fn encrypt_with(&self, key: &EncryptionKey) -> crate::error::Result<Self::Encrypted>;
25
26    /// Encrypt with a randomly generated key.
27    fn encrypt(&self) -> crate::error::Result<Self::Encrypted> {
28        self.encrypt_with(&EncryptionKey::generate())
29    }
30}