pub struct ClusterDek { /* private fields */ }Expand description
The cluster-wide DEK. 32 bytes of key material.
Held in Zeroizing memory; zeroed on drop. The type does NOT
implement Debug / Display to keep accidental disclosure off
the table.
Implementations§
Source§impl ClusterDek
impl ClusterDek
Sourcepub fn generate() -> Self
pub fn generate() -> Self
Generate a fresh DEK from the operating system RNG.
§Panics
Panics if the OS random number generator fails.
Sourcepub fn from_bytes(bytes: [u8; 32]) -> Self
pub fn from_bytes(bytes: [u8; 32]) -> Self
Construct from raw bytes (e.g. after unwrapping). Bytes are copied into the zeroized buffer; the source is left untouched.
Sourcepub fn wrap(
&self,
recipient: &RecipientPublicKey,
) -> Result<Vec<u8>, SecretsError>
pub fn wrap( &self, recipient: &RecipientPublicKey, ) -> Result<Vec<u8>, SecretsError>
Sealed-box-wrap this DEK to a single recipient.
Returns the raw libsodium sealed-box ciphertext bytes
(ephemeral_pubkey || box(dek)), suitable for direct insertion
into WrappedDek::wraps.
§Errors
Returns SecretsError::Encryption if the sealed-box construction
fails.
Sourcepub fn rewrap_for_set(
&self,
recipients: &HashMap<String, RecipientPublicKey>,
new_generation: u64,
) -> Result<WrappedDek, SecretsError>
pub fn rewrap_for_set( &self, recipients: &HashMap<String, RecipientPublicKey>, new_generation: u64, ) -> Result<WrappedDek, SecretsError>
Sealed-box-wrap this DEK to every recipient in a node-id-keyed map
and produce a WrappedDek envelope ready to commit through Raft.
§Errors
Returns SecretsError::Encryption if any per-recipient wrap fails.
Sourcepub fn unwrap(
node_priv: &RecipientPrivateKey,
wrapped: &[u8],
) -> Result<Self, SecretsError>
pub fn unwrap( node_priv: &RecipientPrivateKey, wrapped: &[u8], ) -> Result<Self, SecretsError>
Unwrap a sealed-box-encrypted DEK using a node’s X25519 private key.
§Errors
Returns SecretsError::Decryption if the sealed-box ciphertext
fails authentication, is malformed, or does not decode to exactly
32 bytes of key material.
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, SecretsError>
pub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, SecretsError>
Encrypt a plaintext payload under the DEK using XChaCha20-Poly1305.
On-wire format: [24-byte nonce][ciphertext + tag].
§Errors
Returns SecretsError::Encryption if cipher construction or the
AEAD encryption itself fails.
§Panics
Panics if the OS random number generator fails to produce nonce bytes.
Sourcepub fn decrypt(&self, blob: &[u8]) -> Result<Zeroizing<Vec<u8>>, SecretsError>
pub fn decrypt(&self, blob: &[u8]) -> Result<Zeroizing<Vec<u8>>, SecretsError>
Decrypt the inverse of Self::encrypt.
Returns the plaintext wrapped in Zeroizing so it is scrubbed
from memory when the caller drops it.
§Errors
Returns SecretsError::Decryption if:
blobis shorter thanNONCE_SIZE.- Cipher construction fails.
- AEAD authentication or decryption fails.
Auto Trait Implementations§
impl Freeze for ClusterDek
impl RefUnwindSafe for ClusterDek
impl Send for ClusterDek
impl Sync for ClusterDek
impl Unpin for ClusterDek
impl UnsafeUnpin for ClusterDek
impl UnwindSafe for ClusterDek
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
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