From cb0257e9665b6fc9f0004c928ec043662ea275e0 Mon Sep 17 00:00:00 2001 From: Isabelle L Date: Thu, 14 May 2020 01:19:28 -0500 Subject: [PATCH] swapping orion for ring --- Cargo.toml | 2 +- src/lib.rs | 31 ------------------------------- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8d05511..14f44ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,10 @@ authors = ["Isabelle L. "] edition = "2018" [dependencies] -orion = "0.15.1" serde = { version = "1.0.110", features = ["derive"]} serde_json = "1.0.53" futures = "0.3.5" futures-util = "0.3.5" uuid = { version = "0.8.1", features = ["v4"] } chrono = "0.4.11" +ring = "0.16.13" diff --git a/src/lib.rs b/src/lib.rs index ccff7d3..1432c26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ #![allow(dead_code)] use futures_util::io::{AsyncReadExt, AsyncWriteExt}; -use orion::aead; use std::convert::TryInto; use std::marker::Unpin; @@ -73,23 +72,6 @@ where Ok(Some(packet)) } -/// reads a `Packet` from a stream and decrypts -/// -/// if `Ok(None)` is returned the stream has been disconnected. -pub async fn read_encrypted(stream: &mut S, key: &aead::SecretKey) -> Result> -where - S: AsyncReadExt + Unpin, -{ - let packet = read(stream).await?; - match packet { - None => Ok(packet), - Some(mut packet) => { - packet.contents = aead::open(&key, &packet.contents)?; - Ok(Some(packet)) - } - } -} - /// Writes a `Sendable` packet to a stream pub async fn write(stream: &mut S, packet: P) -> Result<()> where @@ -101,19 +83,6 @@ where Ok(()) } -/// Writes an encrypted `Sendable` packet to a stream -pub async fn write_encrypted(stream: &mut S, packet: P, key: &aead::SecretKey) -> Result<()> -where - S: AsyncWriteExt + Unpin, - P: Sendable, -{ - let mut packet = packet.to_packet()?; - packet.contents = aead::seal(&key, &packet.contents)?; - let network_packet = packet.to_network_packet(); - stream.write(&network_packet.0).await?; - Ok(()) -} - /// Kinds of packets that can be sent #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)]