pub struct LocalKeyCipher { /* private fields */ }Expand description
The single-user reference cipher: a local 256-bit ChaCha20-Poly1305 key.
Genuinely linearizable-free confidentiality + integrity for the personal multi-device case. NOT a login-derived or org-distributed key — see the module’s key-distribution follow-up.
Implementations§
Source§impl LocalKeyCipher
impl LocalKeyCipher
Sourcepub fn generate() -> Self
pub fn generate() -> Self
Mint a fresh random key (OS CSPRNG). Not persisted — pair with
Self::key_hex to store it, or use Self::load_or_generate.
Sourcepub fn from_key_hex(hex: &str) -> Result<Self, CryptoError>
pub fn from_key_hex(hex: &str) -> Result<Self, CryptoError>
Parse a 64-hex-char key.
Sourcepub fn load_or_generate(path: &Path) -> Result<Self, CryptoError>
pub fn load_or_generate(path: &Path) -> Result<Self, CryptoError>
Load the key from path, or mint + persist a new one there (0600 on
unix). The single-user “the key lives on my devices” story — a device
gets the key out of band (copy the file / a recovery phrase); this is
the local reference, not the login-derived distribution (the follow-up).
Trait Implementations§
Source§impl Clone for LocalKeyCipher
impl Clone for LocalKeyCipher
Source§fn clone(&self) -> LocalKeyCipher
fn clone(&self) -> LocalKeyCipher
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LocalKeyCipher
impl Debug for LocalKeyCipher
Source§impl PayloadCipher for LocalKeyCipher
impl PayloadCipher for LocalKeyCipher
Source§fn encrypt(&self, plaintext: &Value) -> Result<Value, CryptoError>
fn encrypt(&self, plaintext: &Value) -> Result<Value, CryptoError>
Encrypt a cleartext payload into a ciphertext
Envelope (as a
Value).Source§fn decrypt(&self, envelope: &Value) -> Result<Value, CryptoError>
fn decrypt(&self, envelope: &Value) -> Result<Value, CryptoError>
Recover the cleartext payload from a ciphertext
Envelope. Fails
(CryptoError::Decrypt) on a wrong key or any tamper.Auto Trait Implementations§
impl Freeze for LocalKeyCipher
impl RefUnwindSafe for LocalKeyCipher
impl Send for LocalKeyCipher
impl Sync for LocalKeyCipher
impl Unpin for LocalKeyCipher
impl UnsafeUnpin for LocalKeyCipher
impl UnwindSafe for LocalKeyCipher
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