pub struct StorageEncryptionLayer { /* private fields */ }Expand description
A pure-Rust encryption layer for block storage.
Manages a key store, an encrypted-block index, a bounded audit log, and exposes encrypt/decrypt/rotate/re-encrypt operations.
Implementations§
Source§impl StorageEncryptionLayer
impl StorageEncryptionLayer
Sourcepub fn with_config(config: SelEncryptionConfig) -> Self
pub fn with_config(config: SelEncryptionConfig) -> Self
Create a new layer with the given configuration.
Sourcepub fn generate_key(&mut self, seed: u64) -> KeyId
pub fn generate_key(&mut self, seed: u64) -> KeyId
Generate a new key derived from seed via xorshift64 and add it to
the key store. Returns the new KeyId.
Sourcepub fn set_active_key(&mut self, key_id: KeyId) -> Result<(), SelError>
pub fn set_active_key(&mut self, key_id: KeyId) -> Result<(), SelError>
Set the active key. Returns an error if key_id is not in the store.
Sourcepub fn rotate_key(&mut self, seed: u64) -> KeyId
pub fn rotate_key(&mut self, seed: u64) -> KeyId
Generate a new key (from seed) and make it active. The old key
remains in the store so existing encrypted blocks can still be
decrypted. Returns the new KeyId.
Sourcepub fn active_key_id(&self) -> Result<KeyId, SelError>
pub fn active_key_id(&self) -> Result<KeyId, SelError>
Return the active KeyId, or an error if none is set.
Sourcepub fn get_key(&self, key_id: &KeyId) -> Option<&SelEncryptionKey>
pub fn get_key(&self, key_id: &KeyId) -> Option<&SelEncryptionKey>
Look up a key by ID.
Sourcepub fn encrypt_block(
&mut self,
cid: BlockCid,
plaintext: &[u8],
) -> Result<Vec<u8>, SelError>
pub fn encrypt_block( &mut self, cid: BlockCid, plaintext: &[u8], ) -> Result<Vec<u8>, SelError>
Encrypt a block identified by cid.
Stores a record in the encrypted block index so that decrypt_block
can look up the key and nonce by CID.
Sourcepub fn decrypt_block(
&mut self,
cid: BlockCid,
ciphertext: &[u8],
) -> Result<Vec<u8>, SelError>
pub fn decrypt_block( &mut self, cid: BlockCid, ciphertext: &[u8], ) -> Result<Vec<u8>, SelError>
Decrypt a block identified by cid.
Looks up the key and nonce from the block index.
Sourcepub fn encrypt_batch(
&mut self,
blocks: &[(BlockCid, Vec<u8>)],
) -> Vec<Result<Vec<u8>, SelError>>
pub fn encrypt_batch( &mut self, blocks: &[(BlockCid, Vec<u8>)], ) -> Vec<Result<Vec<u8>, SelError>>
Encrypt multiple blocks in one call. Each entry returns independently; a failure on one block does not abort the rest.
Sourcepub fn re_encrypt(
&mut self,
cid: BlockCid,
ciphertext: &[u8],
new_key_id: KeyId,
) -> Result<Vec<u8>, SelError>
pub fn re_encrypt( &mut self, cid: BlockCid, ciphertext: &[u8], new_key_id: KeyId, ) -> Result<Vec<u8>, SelError>
Re-encrypt a block with a different key.
Decrypts with the key stored in the index, then re-encrypts with
new_key_id and updates the index entry.
Sourcepub fn verify_mac(&mut self, cid: BlockCid, data: &[u8]) -> bool
pub fn verify_mac(&mut self, cid: BlockCid, data: &[u8]) -> bool
Verify a simple FNV-1a-based MAC for a block.
The expected MAC is computed as fnv1a_64(cid || data) and compared
against the FNV-1a hash of the block index entry’s encrypted CID.
Returns true if and only if the MACs match.
Sourcepub fn encryption_stats(&self) -> SelEncryptionStats
pub fn encryption_stats(&self) -> SelEncryptionStats
Return current aggregate statistics (snapshot).
Sourcepub fn audit_log(&self) -> &VecDeque<EncAuditEntry>
pub fn audit_log(&self) -> &VecDeque<EncAuditEntry>
Return a reference to the full audit log.
Sourcepub fn block_index(&self) -> &HashMap<BlockCid, SelEncryptedBlockRecord>
pub fn block_index(&self) -> &HashMap<BlockCid, SelEncryptedBlockRecord>
Return a reference to the block index.
Sourcepub fn remove_block(&mut self, cid: &BlockCid) -> bool
pub fn remove_block(&mut self, cid: &BlockCid) -> bool
Remove the block index entry for cid, if present.
Returns true if an entry was removed.
Sourcepub fn delete_key(&mut self, key_id: KeyId) -> Result<(), SelError>
pub fn delete_key(&mut self, key_id: KeyId) -> Result<(), SelError>
Delete a key from the store. Active key is cleared if it matches. Returns an error if the key is not found.
Sourcepub fn list_key_ids(&self) -> Vec<KeyId> ⓘ
pub fn list_key_ids(&self) -> Vec<KeyId> ⓘ
List all key IDs in the store.
Sourcepub fn clear_audit_log(&mut self)
pub fn clear_audit_log(&mut self)
Clear the audit log.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageEncryptionLayer
impl RefUnwindSafe for StorageEncryptionLayer
impl Send for StorageEncryptionLayer
impl Sync for StorageEncryptionLayer
impl Unpin for StorageEncryptionLayer
impl UnsafeUnpin for StorageEncryptionLayer
impl UnwindSafe for StorageEncryptionLayer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more