|
|
@ -1,5 +1,6 @@
|
|
|
|
//! Container for switching between un/encrypted stream
|
|
|
|
//! Container for switching between un/encrypted stream
|
|
|
|
use super::*;
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
use std::mem;
|
|
|
|
use chacha20stream::{
|
|
|
|
use chacha20stream::{
|
|
|
|
AsyncSink,
|
|
|
|
AsyncSink,
|
|
|
@ -257,7 +258,6 @@ mod tests
|
|
|
|
use chacha20stream::keygen;
|
|
|
|
use chacha20stream::keygen;
|
|
|
|
#[tokio::test]
|
|
|
|
#[tokio::test]
|
|
|
|
/// Write the whole `input` buffer encrypted, switch to plain, then write the first 5 bytes of `input` again.
|
|
|
|
/// 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()
|
|
|
|
async fn wrapper_construct()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let input = "Hello world!";
|
|
|
|
let input = "Hello world!";
|
|
|
@ -268,11 +268,11 @@ mod tests
|
|
|
|
let written = {
|
|
|
|
let written = {
|
|
|
|
let mut wrapper = super::DualStream::Plain(backing);
|
|
|
|
let mut wrapper = super::DualStream::Plain(backing);
|
|
|
|
|
|
|
|
|
|
|
|
// Encrypted
|
|
|
|
// Encrypting
|
|
|
|
wrapper.to_crypt(super::Encryption::Encrypt, key, iv).await.unwrap();
|
|
|
|
wrapper.to_crypt(super::Encryption::Encrypt, key, iv).await.unwrap();
|
|
|
|
wrapper.write_all(input.as_bytes()).await.unwrap();
|
|
|
|
wrapper.write_all(input.as_bytes()).await.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
// Unencrypted
|
|
|
|
// Plain
|
|
|
|
wrapper.to_plain().await.unwrap();
|
|
|
|
wrapper.to_plain().await.unwrap();
|
|
|
|
wrapper.write_all(&input.as_bytes()[..5]).await.unwrap();
|
|
|
|
wrapper.write_all(&input.as_bytes()[..5]).await.unwrap();
|
|
|
|
|
|
|
|
|
|
|
@ -286,4 +286,7 @@ mod tests
|
|
|
|
eprintln!("Output bytes: {:?}", written);
|
|
|
|
eprintln!("Output bytes: {:?}", written);
|
|
|
|
eprintln!("Output attempted string: {:?}", String::from_utf8_lossy(&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
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|