secrets
is a library to help Rust programmers safely held cryptographic
secrets in memory.
It is mostly an ergonomic wrapper around the memory-protection utilities provided by [libsodium].
Fixed-size buffers allocated on the stack gain the following protections:
mlock(2)
is called on the underlying memoryDebug
Clone
dFixed and variable-sized buffers can be allocated on the heap and gain the following protections:
mprotect(2)
unless an active borrow is in scopemlock(2)
is called on the allocated memoryGenerating cryptographic keys:
rust
Secret::<[u8; 16]>::random(|s| {
// use `s` as if it were a `&mut [u8; 16]`
});
Holding a decrypted plaintext (pseudocode):
```rust let key = SecretBox::<[u8; 16]>::new(|mut s| { /// initialized from some preexisting key });
let mut ciphertext = SecretVec::
let ciphertextrw = ciphertext.borrowmut();
crypto::secretbox::opendetached( &ciphertextrw[..], tag, nonce, key ); ```
Licensed under either of
at your option.