mod inner;
#[cfg(all(test, feature = "hkdf"))]
mod cctv;
pub use inner::{StreamReader, StreamWriter};
use std::io::{Read, Write};
use zeroize::{Zeroize, Zeroizing};
pub const PAYLOAD_KEY_SIZE: usize = 32;
pub struct PayloadKey([u8; PAYLOAD_KEY_SIZE]);
impl PayloadKey {
pub fn from_bytes(bin: &[u8; PAYLOAD_KEY_SIZE]) -> Self {
Self(*bin)
}
pub fn to_bytes(&self) -> Zeroizing<[u8; PAYLOAD_KEY_SIZE]> {
Zeroizing::new(self.0)
}
}
impl From<[u8; PAYLOAD_KEY_SIZE]> for PayloadKey {
fn from(bin: [u8; PAYLOAD_KEY_SIZE]) -> Self {
Self(bin)
}
}
impl Drop for PayloadKey {
fn drop(&mut self) {
self.0.zeroize();
}
}
pub struct Stream;
impl Stream {
pub fn encrypt<W: Write>(key: PayloadKey, writer: W) -> StreamWriter<W> {
inner::Stream::encrypt(inner::PayloadKey(key.0.into()), writer)
}
pub fn decrypt<R: Read>(key: PayloadKey, reader: R) -> StreamReader<R> {
inner::Stream::decrypt(inner::PayloadKey(key.0.into()), reader)
}
}