parent
e657b72bcf
commit
0b9af0ee18
@ -0,0 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
/// TODO: RSA private key
|
||||
pub type RsaPrivateKey = ();
|
||||
|
||||
/// TODO: RSA public key
|
||||
pub type RsaPublicKey = ();
|
@ -0,0 +1,61 @@
|
||||
use super::*;
|
||||
use crypt::{
|
||||
RsaPublicKey,
|
||||
RsaPrivateKey,
|
||||
};
|
||||
|
||||
/// Inner rsa data for encrypted stream read+write halves
|
||||
struct EncryptedStreamMeta
|
||||
{
|
||||
us: RsaPrivateKey,
|
||||
them: Option<RsaPublicKey>,
|
||||
}
|
||||
|
||||
/// Writable half of `EncryptedStream`.
|
||||
pub struct WriteHalf<S>
|
||||
where S: AsyncWrite
|
||||
{
|
||||
meta: Arc<EncryptedStreamMeta>,
|
||||
|
||||
backing_write: Box<dual::DualStream<S>>,
|
||||
}
|
||||
|
||||
/// Readable half of `EncryptedStream`.
|
||||
pub struct ReadHalf<S>
|
||||
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>,
|
||||
backing_read: Box<S>,
|
||||
}
|
||||
|
||||
struct ReadWriteCombined<R, W>
|
||||
{
|
||||
/// Since chacha20stream has no AsyncRead counterpart, we have to do it ourselves.
|
||||
cipher_read: Option<Crypter>,
|
||||
backing_read: R,
|
||||
|
||||
backing_write: dual::DualStream<W>,
|
||||
}
|
||||
|
||||
/// RSA/chacha20 encrypted stream
|
||||
pub struct EncryptedStream<S>
|
||||
where S: AsyncStream
|
||||
{
|
||||
meta: EncryptedStreamMeta,
|
||||
|
||||
// Keep the streams on the heap to keep this type not hueg.
|
||||
backing: Box<ReadWriteCombined<S, S>>,
|
||||
}
|
||||
|
||||
impl<S: AsyncStream> EncryptedStream<S>
|
||||
{
|
||||
/// Has this stream done its RSA key exchange?
|
||||
pub fn has_exchanged(&self) -> bool
|
||||
{
|
||||
self.meta.them.is_some()
|
||||
}
|
||||
}
|
Loading…
Reference in new issue