Browse Source

swapping orion for ring

master
Isabelle L. 5 years ago
parent
commit
cb0257e966
2 changed files with 1 additions and 32 deletions
  1. +1
    -1
      Cargo.toml
  2. +0
    -31
      src/lib.rs

+ 1
- 1
Cargo.toml View File

@@ -5,10 +5,10 @@ authors = ["Isabelle L. <me@izzabelle.dev>"]
edition = "2018" edition = "2018"


[dependencies] [dependencies]
orion = "0.15.1"
serde = { version = "1.0.110", features = ["derive"]} serde = { version = "1.0.110", features = ["derive"]}
serde_json = "1.0.53" serde_json = "1.0.53"
futures = "0.3.5" futures = "0.3.5"
futures-util = "0.3.5" futures-util = "0.3.5"
uuid = { version = "0.8.1", features = ["v4"] } uuid = { version = "0.8.1", features = ["v4"] }
chrono = "0.4.11" chrono = "0.4.11"
ring = "0.16.13"

+ 0
- 31
src/lib.rs View File

@@ -2,7 +2,6 @@
#![allow(dead_code)] #![allow(dead_code)]


use futures_util::io::{AsyncReadExt, AsyncWriteExt}; use futures_util::io::{AsyncReadExt, AsyncWriteExt};
use orion::aead;
use std::convert::TryInto; use std::convert::TryInto;
use std::marker::Unpin; use std::marker::Unpin;


@@ -73,23 +72,6 @@ where
Ok(Some(packet)) 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<S>(stream: &mut S, key: &aead::SecretKey) -> Result<Option<Packet>>
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 /// Writes a `Sendable` packet to a stream
pub async fn write<S, P>(stream: &mut S, packet: P) -> Result<()> pub async fn write<S, P>(stream: &mut S, packet: P) -> Result<()>
where where
@@ -101,19 +83,6 @@ where
Ok(()) Ok(())
} }


/// Writes an encrypted `Sendable` packet to a stream
pub async fn write_encrypted<S, P>(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 /// Kinds of packets that can be sent
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]


Loading…
Cancel
Save