conundrum 0.1.0

Hard-to-misuse crypto primitives with purpose scoping.
Documentation
use chacha20::cipher::{KeyIvInit, StreamCipher};

use crate::symm_encr::EncrKey;

pub struct UnauthEncryptionStream<S> {
    cipher: chacha20::ChaCha20,
    _purpose: S
}

impl <S: Default> UnauthEncryptionStream<S> {
    pub fn new(key: EncrKey<S>, nonce: chacha20::Nonce) -> Self {
        let cipher = chacha20::ChaCha20::new(key.as_slice().into(), &nonce);
        UnauthEncryptionStream {
            cipher,
            _purpose: S::default()
        }
    }

    pub fn xor_chunk(&mut self, chunk: &mut [u8]) {
        self.cipher.apply_keystream(chunk)
    }
}