//! Socket encryption wrapper use super::*; use cryptohelpers::{ rsa::{ RsaPublicKey, RsaPrivateKey, }, sha256, }; use chacha20stream::{ AsyncSink, }; use std::sync::Arc; use tokio::{ sync::{ RwLock, }, io::{ self, DuplexStream, }, }; /// Encrypted socket information. #[derive(Debug)] struct ESockInfo { us: RsaPrivateKey, them: Option, } /// A tx+rx socket. #[pin_project] #[derive(Debug)] pub struct ESock { info: RwLock, #[pin] // Raw (not encrypted) reader rx: R, #[pin] tx: AsyncSink, } /// Write half for `ESock`. #[pin_project] #[derive(Debug)] pub struct ESockWriteHalf(Arc, #[pin] AsyncSink); /// Read half for `ESock`. #[pin_project] #[derive(Debug)] pub struct ESockReadHalf( Arc, #[pin] R, // read from this (raw.) #[pin] AsyncSink, // sink raw from `R` here, outputs decrypted bytes into next. #[pin] DuplexStream, // read decrypted bytes from here. );