//! Encodings use super::*; use ext::*; use std::{fmt, error}; use bytes::{ Buf, Bytes, }; use std::io; use tokio::io::{ AsyncRead, AsyncWrite, AsyncReadExt, AsyncWriteExt, }; use serde::{ Serialize, de::DeserializeOwned }; use cryptohelpers::{ sha256, rsa, }; /// Size of buffer to use when copying a stream. pub const STREAMING_BUFFER_SIZE: usize = 4096; pub mod ser; /// Copy `from` to `to`, transforming the data with the provided key and IV. /// /// # Stream cipher usage /// The copy is buffered by `STREAMING_BUFFER_SIZE` bytes, and the cipher applied to each read buffer. /// If the buffer cannot be filled (because the stream reached EOF before filling it), then only the full portion of the buffer is transformed and written. #[inline] pub async fn cc20_copy_stream(from: &mut F, to: &mut T, keys: K, decrypt: bool) -> io::Result<(usize, usize)> where K: key::CC20Key, F: AsyncRead + Unpin + ?Sized, T: AsyncWrite + Unpin + ?Sized { if decrypt { ser::cha_copy::(from, to, keys.key(), keys.iv()).await } else { ser::cha_copy::(from, to, keys.key(), keys.iv()).await } }