[][src]Module saltlick::crypter

Low-level API for saltlick stream operations.

Example

use saltlick::crypter::{Decrypter, Encrypter};

let test_data = vec![vec![1, 2, 3], vec![4, 5, 6]];

let (public, secret) = saltlick::gen_keypair();

// Data is fed into the encrypter. Chunking into blocks is handled
// automatically.
let mut encrypter = Encrypter::new(public.clone());
let mut ciphertext = Vec::new();
for block in test_data.iter() {
    let encrypted_block = encrypter.update_to_vec(block, false).unwrap();
    ciphertext.extend(encrypted_block);
}

// Once all data is written, the encrypter must be finalized. After
// this trying to add more data will result in an error. If the encryption
// stream is not finalized, decryption will fail as incomplete.
let final_block = encrypter.update_to_vec(&[] as &[u8], true).unwrap();
ciphertext.extend(final_block);

// Decryption is the opposite of encrypting - feed chunks of ciphertext to
// the decrypter until `Decrypter::is_finalized` returns true (or just give
// the decrypter the full data set like we do here).
let mut decrypter = Decrypter::new(public, secret);
let plaintext = decrypter.update_to_vec(&ciphertext[..]).unwrap();
assert!(decrypter.is_finalized());
assert_eq!(
    test_data.into_iter().flatten().collect::<Vec<u8>>(),
    plaintext
);

Structs

AsyncDecrypter

Wrapper type for the decrypter to support async key lookup functions.

Decrypter

Low-level interface to decrypting data in the saltlick format.

Encrypter

Low-level interface to encrypting data in the saltlick format.

Constants

DEFAULT_BLOCK_SIZE

Default block size.

MAX_BLOCK_SIZE

Maximum block size allowed - values larger than this will automatically be coerced down to this value.

MIN_BLOCK_SIZE

Minimum block size allowed - values smaller than this will automatically be coerced up to this value.