diff --git a/src/stream.rs b/src/stream.rs index f13e317..aa10026 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -27,13 +27,26 @@ struct EncryptedStreamMeta } /// Writable half of `EncryptedStream`. +#[pin_project] pub struct WriteHalf where S: AsyncWrite { meta: Arc, - backing_write: Box>, + #[pin] backing_write: S,//Box>, +} +//TODO: WriteHalf's AsyncWrite impl should just forward to backing_write + +pub struct EncryptedWriteHalf<'a, S> + where S: AsyncWrite, +{ + cipher: Crypter, + // Buffer for when `backing.poll_write()` returns `Pending`. + crypt_buffer: Vec, + + backing: &'a mut WriteHalf, } +//TODO: EncryptedWriteHalf's AsyncWrite impl should en/decrypt the input buffer into `crypt_buffer` then send it to `backing`. /// Readable half of `EncryptedStream`. #[pin_project] @@ -43,11 +56,23 @@ where S: AsyncRead meta: Arc, /// chacha20_poly1305 decrypter for incoming reads from `S` - //TODO: chacha20stream: implement a read version of AsyncSink so we don't need to keep this? - cipher: Option, - #[pin] backing_read: Box, + + #[pin] backing_read: S, } +//TODO: ReadHalf's AsyncRead impl should just forward to backing_read, +pub struct EncryptedReadHalf<'a, S> + where S: AsyncRead, +{ + cipher: Crypter, + backing: &'a mut ReadHalf, +} +//TODO: EncryptedReadHalf's AsyncRead impl should en/decrypt the read from backing. + + +//TODO: Rework everything past this point: + +/* struct ReadWriteCombined { /// Since chacha20stream has no AsyncRead counterpart, we have to do it ourselves. @@ -112,7 +137,7 @@ impl EncryptedStream todo!("Drop write's `meta`, consume read's `meta`. Move the streams into `ReadWriteCombined`") } } - +/* impl AsyncWrite for WriteHalf { #[inline] fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll> { @@ -153,3 +178,5 @@ impl AsyncRead for ReadHalf } } } +*/ +*/