parent
d271f164fa
commit
62f3c384b2
@ -0,0 +1,58 @@
|
||||
//! 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<RsaPublicKey>,
|
||||
}
|
||||
|
||||
/// A tx+rx socket.
|
||||
#[pin_project]
|
||||
#[derive(Debug)]
|
||||
pub struct ESock<W, R> {
|
||||
info: RwLock<ESockInfo>,
|
||||
|
||||
#[pin]
|
||||
// Raw (not encrypted) reader
|
||||
rx: R,
|
||||
#[pin]
|
||||
tx: AsyncSink<W>,
|
||||
}
|
||||
|
||||
/// Write half for `ESock`.
|
||||
#[pin_project]
|
||||
#[derive(Debug)]
|
||||
pub struct ESockWriteHalf<W>(Arc<ESockInfo>, #[pin] AsyncSink<W>);
|
||||
|
||||
/// Read half for `ESock`.
|
||||
#[pin_project]
|
||||
#[derive(Debug)]
|
||||
pub struct ESockReadHalf<R>(
|
||||
Arc<ESockInfo>,
|
||||
|
||||
#[pin] R, // read from this (raw.)
|
||||
#[pin] AsyncSink<DuplexStream>, // sink raw from `R` here, outputs decrypted bytes into next.
|
||||
#[pin] DuplexStream, // read decrypted bytes from here.
|
||||
);
|
Loading…
Reference in new issue