|
|
|
@ -27,13 +27,26 @@ struct EncryptedStreamMeta
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Writable half of `EncryptedStream`.
|
|
|
|
|
#[pin_project]
|
|
|
|
|
pub struct WriteHalf<S>
|
|
|
|
|
where S: AsyncWrite
|
|
|
|
|
{
|
|
|
|
|
meta: Arc<EncryptedStreamMeta>,
|
|
|
|
|
|
|
|
|
|
backing_write: Box<dual::DualStream<S>>,
|
|
|
|
|
#[pin] backing_write: S,//Box<dual::DualStream<S>>,
|
|
|
|
|
}
|
|
|
|
|
//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<u8>,
|
|
|
|
|
|
|
|
|
|
backing: &'a mut WriteHalf<S>,
|
|
|
|
|
}
|
|
|
|
|
//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<EncryptedStreamMeta>,
|
|
|
|
|
|
|
|
|
|
/// 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<Crypter>,
|
|
|
|
|
#[pin] backing_read: Box<S>,
|
|
|
|
|
|
|
|
|
|
#[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<S>,
|
|
|
|
|
}
|
|
|
|
|
//TODO: EncryptedReadHalf's AsyncRead impl should en/decrypt the read from backing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Rework everything past this point:
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
struct ReadWriteCombined<R, W>
|
|
|
|
|
{
|
|
|
|
|
/// Since chacha20stream has no AsyncRead counterpart, we have to do it ourselves.
|
|
|
|
@ -112,7 +137,7 @@ impl<R: AsyncRead, W: AsyncWrite> EncryptedStream<R, W>
|
|
|
|
|
todo!("Drop write's `meta`, consume read's `meta`. Move the streams into `ReadWriteCombined`")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
impl<S: AsyncWrite> AsyncWrite for WriteHalf<S>
|
|
|
|
|
{
|
|
|
|
|
#[inline] fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize, io::Error>> {
|
|
|
|
@ -153,3 +178,5 @@ impl<S: AsyncRead> AsyncRead for ReadHalf<S>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
*/
|
|
|
|
|