parent
b8fcdb094f
commit
fb1096f9a3
@ -0,0 +1,40 @@
|
|||||||
|
//! 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!()`?
|
||||||
|
}
|
Loading…
Reference in new issue