eh, idk if this is getting anywhere

master
Avril 4 years ago
parent f2868d11ff
commit ee89469b3f
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -5,3 +5,8 @@ pub type RsaPrivateKey = ();
/// TODO: RSA public key /// TODO: RSA public key
pub type RsaPublicKey = (); pub type RsaPublicKey = ();
pub(crate) fn generate() -> RsaPrivateKey
{
todo!()
}

@ -54,9 +54,12 @@ impl<T, U> Split for (T, U)
(a, b) (a, b)
} }
} }
//TODO: Add trait `SplitRef` for exchange, I guess?
/// Combined Read + Write encryptable async stream. /// Combined Read + Write encryptable async stream.
/// ///
/// The `AsyncRead` and `AsyncWrite` impls of this type forward to the backing impls for `S`.
///
/// # Exchange /// # Exchange
/// A combined stream is the only way to exchange pubkeys and enabling the creation of encrypted read/write wrappers on the combined stream or splits. /// A combined stream is the only way to exchange pubkeys and enabling the creation of encrypted read/write wrappers on the combined stream or splits.
#[pin_project] #[pin_project]
@ -67,7 +70,50 @@ pub struct Stream<S>
#[pin] stream: S, #[pin] stream: S,
} }
impl<S: AsyncStream> Split for Stream<S> impl<S> Stream<S>
where S: Split,
S::First: AsyncWrite,
S::Second: AsyncRead
{
/// Create a new `Stream` from two streams, one implemetor of `AsyncWrite`, and one of `AsyncRead`.
pub fn new(tx: S::First, rx: S::Second) -> Self
{
Self {
meta: EncryptedStreamMeta {
them: None,
us: crypt::generate(),
},
stream: S::unsplit(tx, rx),
}
}
}
impl<S: AsyncStream> Stream<S>
{
/// Create a new `Stream` from an implementor of both `AsyncRead` and `AsyncWrite`.
pub fn new_single(stream: S) -> Self
{
Self {
meta: EncryptedStreamMeta {
them: None,
us: crypt::generate(),
},
stream,
}
}
/// Create a split by cloning `S`.
pub fn split_clone(self) -> (WriteHalf<S>, ReadHalf<S>)
where S: Clone
{
Stream {
stream: (self.stream.clone(), self.stream),
meta: self.meta
}.split()
}
}
impl<S> Split for Stream<S>
where S: Split, where S: Split,
S::First: AsyncWrite, S::First: AsyncWrite,
S::Second: AsyncRead S::Second: AsyncRead
@ -83,7 +129,7 @@ where S: Split,
} }
} }
impl<S: AsyncStream> Stream<S> impl<S> Stream<S>
where S: Split, where S: Split,
S::First: AsyncWrite, S::First: AsyncWrite,
S::Second: AsyncRead S::Second: AsyncRead

Loading…
Cancel
Save