diff --git a/Cargo.lock b/Cargo.lock index c5db987..c87c964 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,9 +106,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chacha20stream" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a27e1b4a96dea2045de11b4c72d5717f84acd73de7133f3ee6005244d838d56" +checksum = "b5b34f4279658654cc2c7dbb36ba00b620dd5532153a9b9ebfea1b7ef282e1d4" dependencies = [ "base64 0.13.0", "getrandom 0.2.3", diff --git a/Cargo.toml b/Cargo.toml index bc9f355..e86180c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] bytes = { version = "1.0.1", features = ["serde"] } -chacha20stream = { version = "2.0", features = ["async"] } +chacha20stream = { version = "2.0.1", features = ["async"] } color-eyre = "0.5.11" cryptohelpers = { version = "1.8.1" , features = ["serialise", "full"] } futures = "0.3.16" diff --git a/src/sock/enc.rs b/src/sock/enc.rs index 8340022..a3b013b 100644 --- a/src/sock/enc.rs +++ b/src/sock/enc.rs @@ -9,6 +9,7 @@ use cryptohelpers::{ }; use chacha20stream::{ AsyncSink, + AsyncSource, }; use std::sync::Arc; use tokio::{ @@ -35,50 +36,6 @@ struct ESockInfo { them: Option, } -/// A shitty way of reversing `AsyncSink` -//TODO: Implement a decrypting reader in `chacha20stream`. -#[pin_project] -#[derive(Debug)] -struct ReverseSink { - #[pin] temp_sink: AsyncSink, - #[pin] rx: DuplexStream, - #[pin] raw: R, -} - -impl AsyncRead for ReverseSink -{ - fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll> { - let proj = self.project(); - use futures::ready; - macro_rules! try_ready { - ($poll_res:expr) => { - match ready!($poll_res) { - Ok(v) => v, - Err(e) => return Poll::Ready(Err(e)), - } - } - } - alloc_local_bytes(buf.len(), |temp_buf| -> Poll> { - //XXX: Does this work? I dunno... Maybe just pin and poll a local `async{}` block (this doesn't work, because `raw` needs to be `Unpin`... sigh....). - - // Read encrypted bytes into `temp_buf`. - let filled_buffer: &[u8] = try_ready!(proj.raw.poll_read(cx, temp_buf).map_ok(|read| { - &temp_buf[..read] - })); - - // Sink the `filled_buffer`. - let sunk: usize = try_ready!(proj.temp_sink.poll_write(cx, filled_buffer)); - debug_assert_eq!(sunk, filled_buffer.len()); - - // Ready from the `rx`. - let bytes_read: usize = try_ready!(proj.rx.poll_read(cx, &mut buf[..sunk])); - debug_assert_eq!(bytes_read, sunk); - - Poll::Ready(Ok(bytes_read)) - }) - } -} - /// A tx+rx socket. #[pin_project] #[derive(Debug)] @@ -100,8 +57,4 @@ pub struct ESockWriteHalf(Arc, #[pin] AsyncSink); /// Read half for `ESock`. #[pin_project] #[derive(Debug)] -pub struct ESockReadHalf( - Arc, - - #[pin] ReverseSink, -); +pub struct ESockReadHalf(Arc, #[pin] AsyncSource);