Compare commits
No commits in common. 'master' and 'no-dual' have entirely different histories.
@ -1,40 +0,0 @@
|
|||||||
//! RSA and chacha20 key exchange methods
|
|
||||||
use super::*;
|
|
||||||
/*
|
|
||||||
use tokio::prelude::*;
|
|
||||||
|
|
||||||
pub async fn write_cckey<W: AsyncWrite + Unpin>(mut to: W, rsa: &crypt::RsaPublicKey, key: &crypt::Key, iv: &crypt::IV) -> std::io::Result<()>
|
|
||||||
{
|
|
||||||
let key = {
|
|
||||||
let mut buf = Vec::with_capacity(chacha20stream::key::KEY_SIZE);
|
|
||||||
crypt::rsa_encrypt(rsa, &mut buf, key.as_ref())?;
|
|
||||||
buf
|
|
||||||
};
|
|
||||||
|
|
||||||
to.write_all(&key[..]).await?; //TODO: Find size of `key` here.
|
|
||||||
to.write_all(iv.as_ref()).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// A future that writes an RSA encrypted chacha20 key to a stream when awaited
|
|
||||||
//TODO: Find size of RSA ecnrypted chacha `Key`.
|
|
||||||
#[pin_project]
|
|
||||||
struct CCKeyWrite<'a, W: AsyncWrite>{
|
|
||||||
/// The bytes of an **already encrypted** chacha20 key.
|
|
||||||
enc_key: Vec<u8>,
|
|
||||||
/// A non-encrypted chacha20 IV.
|
|
||||||
iv: [u8; chacha20stream::key::IV_SIZE],
|
|
||||||
|
|
||||||
/// Stream to write the data to when this future is awaited.
|
|
||||||
#[pin] stream: &'a mut W,
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: impl `Future` for CCKeyWrite should `write_all` both `enc_key` and `iv` to `stream` when `.await`ed.
|
|
||||||
impl<'a, W: AsyncWrite> Future for CCKeyWrite<'a, S>
|
|
||||||
{
|
|
||||||
type Output = io::Result<()>;
|
|
||||||
|
|
||||||
//todo: how to we `write_all` in `poll`? implement it outselves with looping `poll_write` and `futures::ready!()`?
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
//! Stream traits
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
/// A type that implements both `AsyncWrite` and `AsyncRead`
|
|
||||||
pub trait AsyncStream: AsyncRead + AsyncWrite{}
|
|
||||||
impl<T: AsyncRead + AsyncWrite + ?Sized> AsyncStream for T{}
|
|
||||||
|
|
||||||
/// A type that can split itself into other types, and combine back from those types.
|
|
||||||
pub trait Split: Sized
|
|
||||||
{
|
|
||||||
/// First half of the split
|
|
||||||
type First;
|
|
||||||
/// Second half of the split
|
|
||||||
type Second;
|
|
||||||
|
|
||||||
fn split(self) -> (Self::First, Self::Second);
|
|
||||||
fn unsplit(a: Self::First, b: Self::Second) -> Self;
|
|
||||||
|
|
||||||
#[inline(always)] fn split_reverse(self) -> (Self::Second, Self::First)
|
|
||||||
{
|
|
||||||
let (tx, rx) = self.split();
|
|
||||||
(rx, tx)
|
|
||||||
}
|
|
||||||
#[inline(always)] fn unsplit_reverse(b: Self::Second, a: Self::First) -> Self
|
|
||||||
{
|
|
||||||
Self::unsplit(a, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T, U> Split for (T, U)
|
|
||||||
{
|
|
||||||
type First = T;
|
|
||||||
type Second = U;
|
|
||||||
#[inline(always)] fn split(self) -> (Self::First, Self::Second) {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
#[inline(always)] fn unsplit(a: Self::First, b: Self::Second) -> Self {
|
|
||||||
(a, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//TODO: Add trait `SplitRef` for exchange, I guess?
|
|
||||||
|
|
||||||
/// Merges a Read and Write stream in an implementor of `Split`, `AsyncRead`, and `Asyncwrite`.
|
|
||||||
///
|
|
||||||
/// Used for internal of `Stream`.
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub(super) struct Merge<Tx, Rx>(pub Tx, pub Rx);
|
|
||||||
|
|
||||||
impl<Tx, Rx> Merge<Tx, Rx>
|
|
||||||
{
|
|
||||||
fn rx(self: Pin<&mut Self>) -> Pin<&mut Rx>
|
|
||||||
{
|
|
||||||
unsafe {self.map_unchecked_mut(|this| &mut this.1)}
|
|
||||||
}
|
|
||||||
fn tx(self: Pin<&mut Self>) -> Pin<&mut Tx>
|
|
||||||
{
|
|
||||||
unsafe {self.map_unchecked_mut(|this| &mut this.0)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Tx, Rx> Split for Merge<Tx, Rx>
|
|
||||||
{
|
|
||||||
type First = Tx;
|
|
||||||
type Second = Rx;
|
|
||||||
|
|
||||||
#[inline] fn split(self) -> (Self::First, Self::Second) {
|
|
||||||
(self.0, self.1)
|
|
||||||
}
|
|
||||||
#[inline] fn unsplit(a: Self::First, b: Self::Second) -> Self {
|
|
||||||
Self(a, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<Tx, Rx> AsyncWrite for Merge<Tx, Rx>
|
|
||||||
where Tx: AsyncWrite
|
|
||||||
{
|
|
||||||
#[inline] fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize, io::Error>> {
|
|
||||||
self.tx().poll_write(cx, buf)
|
|
||||||
}
|
|
||||||
#[inline] fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
|
||||||
self.tx().poll_flush(cx)
|
|
||||||
}
|
|
||||||
#[inline] fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
|
||||||
self.tx().poll_flush(cx)
|
|
||||||
}
|
|
||||||
#[inline] fn poll_write_buf<B: Buf>(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B) -> Poll<Result<usize, io::Error>>
|
|
||||||
where
|
|
||||||
Self: Sized, {
|
|
||||||
self.tx().poll_write_buf(cx, buf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<Tx, Rx> AsyncRead for Merge<Tx, Rx>
|
|
||||||
where Rx: AsyncRead
|
|
||||||
{
|
|
||||||
#[inline] fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
|
|
||||||
self.rx().poll_read(cx, buf)
|
|
||||||
}
|
|
||||||
#[inline] fn poll_read_buf<B: BufMut>(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B) -> Poll<io::Result<usize>>
|
|
||||||
where
|
|
||||||
Self: Sized, {
|
|
||||||
self.rx().poll_read_buf(cx, buf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
pub(super) enum MaybeFullWrite<'a, S: AsyncWrite>
|
|
||||||
{
|
|
||||||
Full(&'a mut Stream<S>),
|
|
||||||
Half(&'a mut WriteHalf<S>),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) enum MaybeFullRead<'a, S: AsyncRead>
|
|
||||||
{
|
|
||||||
Full(&'a mut Stream<S>),
|
|
||||||
Half(&'a mut ReadHalf<S>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, S: AsyncRead> AsMut<dyn AsyncRead + 'a> for MaybeFullRead<'a, S>
|
|
||||||
{
|
|
||||||
#[inline] fn as_mut(&mut self) -> &mut (dyn AsyncRead + 'a)
|
|
||||||
{
|
|
||||||
self.as_dyn()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, S: AsyncWrite> AsMut<dyn AsyncWrite + 'a> for MaybeFullWrite<'a, S>
|
|
||||||
{
|
|
||||||
#[inline] fn as_mut(&mut self) -> &mut (dyn AsyncWrite + 'a)
|
|
||||||
{
|
|
||||||
self.as_dyn()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl<'a, S: AsyncRead> MaybeFullRead<'a, S>
|
|
||||||
{
|
|
||||||
#[inline(always)] fn as_dyn(&mut self) -> &mut (dyn AsyncRead + 'a)
|
|
||||||
{
|
|
||||||
match self {
|
|
||||||
Self::Full(f) => f,
|
|
||||||
Self::Half(h) => h,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<'a, S: AsyncWrite> MaybeFullWrite<'a, S>
|
|
||||||
{
|
|
||||||
#[inline(always)] fn as_dyn(&mut self) -> &mut (dyn AsyncWrite + 'a)
|
|
||||||
{
|
|
||||||
match self {
|
|
||||||
Self::Full(f) => f,
|
|
||||||
Self::Half(h) => h,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
Loading…
Reference in new issue