pub struct EncryptedBackend { /* private fields */ }Expand description
An encrypted storage backend that wraps another backend.
All data written through this backend is encrypted using AES-256-GCM. Data is encrypted in fixed-size blocks for efficient random access.
§Security Guarantees
- Confidentiality: Data is encrypted with AES-256-GCM
- Integrity: Each block has a 128-bit authentication tag
- Determinism: Same data + key produces identical ciphertext (AC-01)
- Key security: Keys are zeroized on drop
§Example
ⓘ
use entidb_storage::{InMemoryBackend, EncryptedBackend, EncryptionKey};
let key = EncryptionKey::from_bytes(&[0x42u8; 32])?;
let inner = InMemoryBackend::new();
let mut encrypted = EncryptedBackend::new(Box::new(inner), key)?;
let offset = encrypted.append(b"secret data")?;
let data = encrypted.read_at(offset, 11)?;
assert_eq!(&data, b"secret data");Implementations§
Source§impl EncryptedBackend
impl EncryptedBackend
Sourcepub fn new(
inner: Box<dyn StorageBackend>,
key: EncryptionKey,
) -> StorageResult<Self>
pub fn new( inner: Box<dyn StorageBackend>, key: EncryptionKey, ) -> StorageResult<Self>
Creates a new encrypted backend wrapping the given inner backend.
If the inner backend is empty, initializes a new encrypted storage. If it contains data, reads and validates the header.
§Errors
Returns an error if:
- The inner backend contains invalid encrypted data
- The encryption key is wrong (authentication will fail on first read)
- The format version is unsupported
Sourcepub fn with_block_size(
inner: Box<dyn StorageBackend>,
key: &EncryptionKey,
block_size: usize,
) -> StorageResult<Self>
pub fn with_block_size( inner: Box<dyn StorageBackend>, key: &EncryptionKey, block_size: usize, ) -> StorageResult<Self>
Trait Implementations§
Source§impl StorageBackend for EncryptedBackend
impl StorageBackend for EncryptedBackend
Source§fn append(&mut self, data: &[u8]) -> StorageResult<u64>
fn append(&mut self, data: &[u8]) -> StorageResult<u64>
Appends data to the end of the storage. Read more
Source§fn flush(&mut self) -> StorageResult<()>
fn flush(&mut self) -> StorageResult<()>
Flushes all pending writes to durable storage. Read more
Source§fn size(&self) -> StorageResult<u64>
fn size(&self) -> StorageResult<u64>
Returns the current size of the storage in bytes. Read more
Auto Trait Implementations§
impl !Freeze for EncryptedBackend
impl !RefUnwindSafe for EncryptedBackend
impl Send for EncryptedBackend
impl Sync for EncryptedBackend
impl Unpin for EncryptedBackend
impl !UnwindSafe for EncryptedBackend
Blanket Implementations§
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
Mutably borrows from an owned value. Read more