Skip to main content

Module protected

Module protected 

Source
Available on crate feature protected only.
Expand description

§Protected memory type aliases for DryocBox

Type aliases for using DryocBox with protected memory.

§Example

use dryoc::dryocbox::DryocBox;
use dryoc::dryocbox::protected::*;

// Generate a random sender and recipient keypair, into locked, readonly
// memory.
let sender_keypair = LockedROKeyPair::generate_readonly_locked_keypair().expect("keypair");
let recipient_keypair = LockedROKeyPair::generate_readonly_locked_keypair().expect("keypair");

// Generate a random nonce, into locked, readonly memory.
let nonce = Nonce::generate_readonly_locked().expect("nonce failed");

// Read message into locked, readonly memory.
let message = HeapBytes::from_slice_into_readonly_locked(b"Secret message from Santa Claus")
    .expect("message failed");

// Encrypt message into a locked box.
let dryocbox: LockedBox = DryocBox::encrypt(
    &message,
    &nonce,
    &recipient_keypair.public_key,
    &sender_keypair.secret_key,
)
.expect("encrypt failed");

// Decrypt message into locked bytes.
let decrypted: LockedBytes = dryocbox
    .decrypt(
        &nonce,
        &sender_keypair.public_key,
        &recipient_keypair.secret_key,
    )
    .expect("decrypt failed");

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

Re-exports§

pub use crate::protected::*;

Type Aliases§

LockedBox
Locked DryocBox, provided as a type alias for convenience.
LockedKeyPair
Heap-allocated, page-aligned public/secret keypair for authenticated public-key boxes, for use with protected memory.
LockedROKeyPair
Heap-allocated, page-aligned public/secret keypair for authenticated public-key boxes, for use with protected memory.
Mac
Heap-allocated, page-aligned message authentication code for authenticated public-key boxes, for use with protected memory.
Nonce
Heap-allocated, page-aligned nonce for authenticated public-key boxes, for use with protected memory.
PublicKey
Heap-allocated, page-aligned public key for authenticated public-key boxes, for use with protected memory.
SecretKey
Heap-allocated, page-aligned secret key for authenticated public-key boxes, for use with protected memory.