Cleaned up code

TODO: Duplex test
no-dual
Avril 3 years ago
parent 136dc5f102
commit 1eb8012240
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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
} }

@ -1,4 +1,4 @@
use super::*; //! Extensions and macros
#[macro_export] macro_rules! basic_enum { #[macro_export] macro_rules! basic_enum {
($(#[$meta:meta])* $vis:vis $name:ident $(; $tcomment:literal)?: $($var:ident $(=> $comment:literal)?),+ $(,)?) => { ($(#[$meta:meta])* $vis:vis $name:ident $(; $tcomment:literal)?: $($var:ident $(=> $comment:literal)?),+ $(,)?) => {

@ -1,5 +1,9 @@
#![allow(dead_code)] #![allow(dead_code)]
mod ext; #[macro_use] use ext::*; // Extensions & macros
#[macro_use] mod ext;
#[allow(unused_imports)] use ext::*;
// Wrapper for plain/symm-enc stream swapping
mod dual; mod dual;

Loading…
Cancel
Save