|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
//! Container for switching between un/encrypted stream
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
|
use chacha20stream::{
|
|
|
|
|
AsyncSink,
|
|
|
|
@ -257,7 +258,6 @@ mod tests
|
|
|
|
|
use chacha20stream::keygen;
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
/// Write the whole `input` buffer encrypted, switch to plain, then write the first 5 bytes of `input` again.
|
|
|
|
|
// TODO: Read the `written` buffer back in the same way and order, and check for identity.
|
|
|
|
|
async fn wrapper_construct()
|
|
|
|
|
{
|
|
|
|
|
let input = "Hello world!";
|
|
|
|
@ -268,11 +268,11 @@ mod tests
|
|
|
|
|
let written = {
|
|
|
|
|
let mut wrapper = super::DualStream::Plain(backing);
|
|
|
|
|
|
|
|
|
|
// Encrypted
|
|
|
|
|
// Encrypting
|
|
|
|
|
wrapper.to_crypt(super::Encryption::Encrypt, key, iv).await.unwrap();
|
|
|
|
|
wrapper.write_all(input.as_bytes()).await.unwrap();
|
|
|
|
|
|
|
|
|
|
// Unencrypted
|
|
|
|
|
// Plain
|
|
|
|
|
wrapper.to_plain().await.unwrap();
|
|
|
|
|
wrapper.write_all(&input.as_bytes()[..5]).await.unwrap();
|
|
|
|
|
|
|
|
|
@ -286,4 +286,7 @@ mod tests
|
|
|
|
|
eprintln!("Output bytes: {:?}", written);
|
|
|
|
|
eprintln!("Output attempted string: {:?}", String::from_utf8_lossy(&written[..]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Write a test using Tokio's `duplex` to read and write encrypted bytes on 2 tasks, then compare the output to the input afterwards
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|