encrypted-sled

encrypted-sled is an (almost) drop in replacement / wrapper around the amazing sled embedded database. Just configure with an encryption and use normally.

Examples

```rust

let cipher = { use chacha20poly1305::{ChaCha20Poly1305, Key, Nonce}; let mut key = Key::default(); key.copyfromslice(b"an example very very secret key."); encryptedsled::EncryptionCipher::::new( key, encryptedsled::RandNonce::new(rand::threadrng()), encryptedsled::EncryptionMode::default(), ) };

let db = encryptedsled::open("mydb", cipher).unwrap();

// insert and get db.insert(b"yo!", b"v1"); assert_eq!(&db.get(b"yo!").unwrap().unwrap(), b"v1");

// Atomic compare-and-swap. db.compareandswap( b"yo!", // key Some(b"v1"), // old value, None for not present Some(b"v2"), // new value, None for delete ) .unwrap();

// Iterates over key-value pairs, starting at the given key. let scankey: &[u8] = b"a non-present key before yo!"; let mut iter = db.range(scankey..).unwrap(); asserteq!(&iter.next().unwrap().unwrap().0, b"yo!"); asserteq!(iter.next(), None);

db.remove(b"yo!"); assert_eq!(db.get(b"yo!"), Ok(None));

let othertree = db.opentree(b"cool db facts").unwrap(); other_tree.insert( b"k1", &b"a Db acts like a Tree due to implementing Deref"[..] ).unwrap(); ```

Todos

A few things are still not implemented:

A few functions don't handle encryption/decryption gracefully and therefore may cause corrupted data, so please use at your own risk! Encrypted keys will most likely break these

License: MIT