pub struct StorageEncryptionLayer { /* private fields */ }Expand description
Storage encryption layer providing XOR-based encryption for blocks.
This is an educational/demonstration implementation. Do not use for production security.
Implementations§
Source§impl StorageEncryptionLayer
impl StorageEncryptionLayer
Sourcepub fn new(config: EncryptionLayerConfig) -> Self
pub fn new(config: EncryptionLayerConfig) -> Self
Create a new encryption layer with the given configuration.
Sourcepub fn encrypt(&mut self, cid: &str, plaintext: &[u8]) -> EncryptedBlock
pub fn encrypt(&mut self, cid: &str, plaintext: &[u8]) -> EncryptedBlock
Encrypt plaintext data for a given CID.
For Xor mode, XORs plaintext with the repeating key.
For XorWithNonce mode, generates a deterministic nonce from the CID,
derives a working key by XORing the base key with the repeated nonce,
then XORs the plaintext with the working key.
Sourcepub fn decrypt(&mut self, block: &EncryptedBlock) -> Result<Vec<u8>, String>
pub fn decrypt(&mut self, block: &EncryptedBlock) -> Result<Vec<u8>, String>
Decrypt an encrypted block, returning the original plaintext.
Returns an error if the decrypted size does not match original_size.
Sourcepub fn derive_key(base_key: &[u8], nonce: &[u8]) -> Vec<u8> ⓘ
pub fn derive_key(base_key: &[u8], nonce: &[u8]) -> Vec<u8> ⓘ
Derive a working key by XORing the base key with a repeated nonce.
The output length matches the base key length. The nonce is repeated cyclically to cover the full key length.
Sourcepub fn generate_nonce(cid: &str, size: usize) -> Vec<u8> ⓘ
pub fn generate_nonce(cid: &str, size: usize) -> Vec<u8> ⓘ
Generate a deterministic nonce from a CID using FNV-1a hash.
Produces size bytes by repeatedly hashing the CID with different
seed offsets derived from FNV-1a.
Sourcepub fn is_encrypted(data: &[u8]) -> bool
pub fn is_encrypted(data: &[u8]) -> bool
Heuristic check whether data appears to be encrypted.
Estimates Shannon entropy; if > 7.5 bits/byte, data is likely encrypted or incompressible random data.
Sourcepub fn stats(&self) -> EncryptionLayerStats
pub fn stats(&self) -> EncryptionLayerStats
Return current encryption layer statistics.
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