From 1eb80122407627ddce45ab169f6f136b1addab24 Mon Sep 17 00:00:00 2001 From: Avril Date: Sun, 11 Apr 2021 01:51:36 +0100 Subject: [PATCH] Cleaned up code TODO: Duplex test --- src/dual.rs | 9 ++++++--- src/ext.rs | 2 +- src/lib.rs | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/dual.rs b/src/dual.rs index 8ef20aa..9286594 100644 --- a/src/dual.rs +++ b/src/dual.rs @@ -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 + } diff --git a/src/ext.rs b/src/ext.rs index 7e7e9dc..8dd0645 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -1,4 +1,4 @@ -use super::*; +//! Extensions and macros #[macro_export] macro_rules! basic_enum { ($(#[$meta:meta])* $vis:vis $name:ident $(; $tcomment:literal)?: $($var:ident $(=> $comment:literal)?),+ $(,)?) => { diff --git a/src/lib.rs b/src/lib.rs index f6fd2ed..aba720b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,9 @@ #![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;