secrets

Build Status Test Coverage Cargo Crate License

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:

Fixed and variable-sized buffers can be allocated on the heap and gain the following protections:

Examples

Generating 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::::from(&mut b"..."); // some ciphertext let nonce = b"..."; // some nonce let tag = b"..."; // some authentication tag

let ciphertextrw = ciphertext.borrowmut();

crypto::secretbox::opendetached( &ciphertextrw[..], tag, nonce, key ); ```

License

Licensed under either of

at your option.