Module nuts_container::memory

source ·
Expand description

A sample Backend implementation which stores the data in the memory.

This implementation is mainly used for demonstration, testing and documentation.

It stores the content of the data blocks in a hash indexed by the Id of this backend, where the id is a simple u32 value.

When creating a MemoryBackend you can choose how the data are encrypted. Choose the related options in CreateOptionsBuilder and the container will pass (possibly) encrypted data to this backend.

use nuts_container::container::*;
use nuts_container::memory::MemoryBackend;

// Example creates an encrypted container with an attached MemoryBackend.

let backend = MemoryBackend::new();
let kdf = Kdf::pbkdf2(Digest::Sha1, 65536, b"123");

// Let's create an encrypted container (with aes128-ctr).
let options = CreateOptionsBuilder::new(Cipher::Aes128Ctr)
    .with_password_callback(|| Ok(b"abc".to_vec()))
    .with_kdf(kdf.clone())
    .build::<MemoryBackend>()
    .unwrap();
let container = Container::<MemoryBackend>::create(backend, options).unwrap();
let info = container.info().unwrap();

assert_eq!(info.cipher, Cipher::Aes128Ctr);
assert_eq!(info.kdf, kdf);

When you open a MemoryBackend you have no possibility to choose further settings because (due to the nature of this volatile storage) nothing is made persistent. On open, always an unencrypted container is created.

use nuts_container::container::*;
use nuts_container::memory::MemoryBackend;

// Example opens a container with an attached MemoryBackend,
// which is always unencrypted.

let backend = MemoryBackend::new();

// When opening a contaier with a MemoryBackend attached,
// the container is always unencrypted.
let options = OpenOptionsBuilder::new().build::<MemoryBackend>().unwrap();
let container = Container::<MemoryBackend>::open(backend, options).unwrap();
let info = container.info().unwrap();

assert_eq!(info.cipher, Cipher::None);
assert_eq!(info.kdf, Kdf::None);

Structs

Enums

  • Error used by the memory backend.