Skip to main content

Module protected

Module protected 

Source
Available on crate feature protected only.
Expand description

§Protected memory type aliases for DryocSecretBox

Type aliases for using DryocSecretBox with protected memory.

§Example

use dryoc::dryocsecretbox::DryocSecretBox;
use dryoc::dryocsecretbox::protected::*;

// Generate a random secret key, lock it, protect memory as read-only
let secret_key = Key::generate_readonly_locked().expect("key failed");

// Generate a random secret key, lock it, protect memory as read-only
let nonce = Nonce::generate_readonly_locked().expect("nonce failed");

// Load a message, lock it, protect memory as read-only
let message =
    HeapBytes::from_slice_into_readonly_locked(b"Secret message from the tooth fairy")
        .expect("message failed");

// Encrypt the message, placing the result into locked memory
let dryocsecretbox: LockedBox = DryocSecretBox::encrypt(&message, &nonce, &secret_key);

// Decrypt the message, placing the result into locked memory
let decrypted: LockedBytes = dryocsecretbox
    .decrypt(&nonce, &secret_key)
    .expect("decrypt failed");

assert_eq!(message.as_slice(), decrypted.as_slice());

Re-exports§

pub use crate::protected::*;

Type Aliases§

Key
Heap-allocated, page-aligned secret for authenticated secret box, for use with protected memory.
LockedBox
Locked DryocSecretBox, provided as a type alias for convenience.
Mac
Heap-allocated, page-aligned secret box message authentication code, for use with protected memory.
Nonce
Heap-allocated, page-aligned nonce for authenticated secret box, for use with protected memory.