Update dependency versions (#1265)

* Update versions of many dependencies

* Bump version of rand

* Updates for changed APIs in rand, ring, and webpki

* Replace references to `snow::Session`

`Session` no longer exists in `snow` but the replacement is two structs `HandshakeState` and `TransportState`
Something will have to be done to harmonize `NoiseOutput.session`

* Add precise type for UnparsedPublicKey

* Update data structures/functions to match new snow's API

* Delete diff.diff

Remove accidentally committed diff file

* Remove commented lines in identity/rsa.rs

* Bump libsecp256k1 to 0.3.1
This commit is contained in:
Ross Schulman
2019-10-11 04:19:35 -04:00
committed by Pierre Krieger
parent 11c2e5fbc5
commit d683828f37
11 changed files with 65 additions and 28 deletions

View File

@ -25,6 +25,7 @@ pub mod handshake;
use futures::Poll;
use log::{debug, trace};
use snow;
use snow::error::{StateProblem, Error as SnowError};
use std::{fmt, io};
use tokio_io::{AsyncRead, AsyncWrite};
@ -55,12 +56,48 @@ impl Buffer {
}
}
/// A passthrough enum for the two kinds of state machines in `snow`
pub(crate) enum SnowState {
Transport(snow::TransportState),
Handshake(snow::HandshakeState)
}
impl SnowState {
pub fn read_message(&mut self, message: &[u8], payload: &mut [u8]) -> Result<usize, SnowError> {
match self {
SnowState::Handshake(session) => session.read_message(message, payload),
SnowState::Transport(session) => session.read_message(message, payload),
}
}
pub fn write_message(&mut self, message: &[u8], payload: &mut [u8]) -> Result<usize, SnowError> {
match self {
SnowState::Handshake(session) => session.write_message(message, payload),
SnowState::Transport(session) => session.write_message(message, payload),
}
}
pub fn get_remote_static(&self) -> Option<&[u8]> {
match self {
SnowState::Handshake(session) => session.get_remote_static(),
SnowState::Transport(session) => session.get_remote_static(),
}
}
pub fn into_transport_mode(self) -> Result<snow::TransportState, SnowError> {
match self {
SnowState::Handshake(session) => session.into_transport_mode(),
SnowState::Transport(_) => Err(SnowError::State(StateProblem::HandshakeAlreadyFinished)),
}
}
}
/// A noise session to a remote.
///
/// `T` is the type of the underlying I/O resource.
pub struct NoiseOutput<T> {
io: T,
session: snow::Session,
session: SnowState,
buffer: Buffer,
read_state: ReadState,
write_state: WriteState
@ -76,9 +113,10 @@ impl<T> fmt::Debug for NoiseOutput<T> {
}
impl<T> NoiseOutput<T> {
fn new(io: T, session: snow::Session) -> Self {
fn new(io: T, session: SnowState) -> Self {
NoiseOutput {
io, session,
io,
session,
buffer: Buffer { inner: Box::new([0; TOTAL_BUFFER_LEN]) },
read_state: ReadState::Init,
write_state: WriteState::Init