Skip to content

Commit

Permalink
cargo fix --edition-idioms
Browse files Browse the repository at this point in the history
  • Loading branch information
mcginty committed Jun 22, 2019
1 parent 169d2f6 commit 56b26d7
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 64 deletions.
8 changes: 4 additions & 4 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#[macro_use]
extern crate criterion;

extern crate test;
extern crate rand;
extern crate snow;
extern crate x25519_dalek;





use criterion::{Benchmark, Criterion, Throughput};
use snow::*;
Expand Down
8 changes: 4 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//! as `cargo run --example simple` to see the magic happen.
#[macro_use] extern crate lazy_static;
extern crate clap;
extern crate snow;



use clap::App;
use snow::Builder;
Expand Down Expand Up @@ -35,7 +35,7 @@ fn run_server() {
let mut buf = vec![0u8; 65535];

// Initialize our responder NoiseSession using a builder.
let builder: Builder = Builder::new(PARAMS.clone());
let builder: Builder<'_> = Builder::new(PARAMS.clone());
let static_key = builder.generate_keypair().unwrap().private;
let mut noise = builder
.local_private_key(&static_key)
Expand Down Expand Up @@ -70,7 +70,7 @@ fn run_client() {
let mut buf = vec![0u8; 65535];

// Initialize our initiator NoiseSession using a builder.
let builder: Builder = Builder::new(PARAMS.clone());
let builder: Builder<'_> = Builder::new(PARAMS.clone());
let static_key = builder.generate_keypair().unwrap().private;
let mut noise = builder
.local_private_key(&static_key)
Expand Down
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl PartialEq for Keypair {
/// ```
pub struct Builder<'builder> {
params: NoiseParams,
resolver: Box<CryptoResolver>,
resolver: Box<dyn CryptoResolver>,
s: Option<&'builder [u8]>,
e_fixed: Option<&'builder [u8]>,
rs: Option<&'builder [u8]>,
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'builder> Builder<'builder> {
}

/// Create a Builder with a custom crypto resolver.
pub fn with_resolver(params: NoiseParams, resolver: Box<CryptoResolver>) -> Self {
pub fn with_resolver(params: NoiseParams, resolver: Box<dyn CryptoResolver>) -> Self {
Builder {
params,
resolver,
Expand Down
8 changes: 4 additions & 4 deletions src/cipherstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::error::{Error, InitStage, StateProblem};
use crate::types::Cipher;

pub struct CipherState {
cipher : Box<Cipher>,
cipher : Box<dyn Cipher>,
n : u64,
has_key : bool,
}

impl CipherState {
pub fn new(cipher: Box<Cipher>) -> Self {
pub fn new(cipher: Box<dyn Cipher>) -> Self {
Self {
cipher,
n: 0,
Expand Down Expand Up @@ -101,12 +101,12 @@ impl CipherStates {
}

pub struct StatelessCipherState {
cipher : Box<Cipher>,
cipher : Box<dyn Cipher>,
has_key : bool,
}

impl StatelessCipherState {
pub fn new(cipher: Box<Cipher>) -> Self {
pub fn new(cipher: Box<dyn Cipher>) -> Self {
Self {
cipher,
has_key: false
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl From<StateProblem> for Error {
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Pattern(reason) => write!(f, "pattern error: {:?}", reason),
Error::Init(reason) => write!(f, "initialization error: {:?}", reason),
Expand Down
16 changes: 8 additions & 8 deletions src/handshakestate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::{convert::TryInto, fmt};
///
/// See: http://noiseprotocol.org/noise.html#the-handshakestate-object
pub struct HandshakeState {
pub(crate) rng : Box<Random>,
pub(crate) rng : Box<dyn Random>,
pub(crate) symmetricstate : SymmetricState,
pub(crate) cipherstates : CipherStates,
pub(crate) s : Toggle<Box<Dh>>,
pub(crate) e : Toggle<Box<Dh>>,
pub(crate) s : Toggle<Box<dyn Dh>>,
pub(crate) e : Toggle<Box<dyn Dh>>,
pub(crate) fixed_ephemeral : bool,
pub(crate) rs : Toggle<[u8; MAXDHLEN]>,
pub(crate) re : Toggle<[u8; MAXDHLEN]>,
Expand All @@ -37,11 +37,11 @@ pub struct HandshakeState {
impl HandshakeState {
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
pub(crate) fn new(
rng : Box<Random>,
rng : Box<dyn Random>,
cipherstate : CipherState,
hasher : Box<Hash>,
s : Toggle<Box<Dh>>,
e : Toggle<Box<Dh>>,
hasher : Box<dyn Hash>,
s : Toggle<Box<dyn Dh>>,
e : Toggle<Box<dyn Dh>>,
fixed_ephemeral : bool,
rs : Toggle<[u8; MAXDHLEN]>,
re : Toggle<[u8; MAXDHLEN]>,
Expand Down Expand Up @@ -432,7 +432,7 @@ impl HandshakeState {
}

impl fmt::Debug for HandshakeState {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("HandshakeState").finish()
}
}
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
extern crate arrayref;

#[macro_use] extern crate static_slice;
extern crate byteorder;
extern crate smallvec;
extern crate rand_core;
extern crate subtle;





#[macro_use]
pub mod error;
Expand Down
22 changes: 11 additions & 11 deletions src/resolvers/default.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extern crate crypto;
extern crate blake2_rfc;
extern crate chacha20_poly1305_aead;
extern crate x25519_dalek;
extern crate rand;
use crypto;
use blake2_rfc;
use chacha20_poly1305_aead;
use x25519_dalek;
use rand;

use self::blake2_rfc::blake2b::Blake2b;
use self::blake2_rfc::blake2s::Blake2s;
Expand All @@ -29,21 +29,21 @@ use super::CryptoResolver;
pub struct DefaultResolver;

impl CryptoResolver for DefaultResolver {
fn resolve_rng(&self) -> Option<Box<Random>> {
fn resolve_rng(&self) -> Option<Box<dyn Random>> {
match OsRng::new() {
Ok(rng) => Some(Box::new(rng)),
_ => None
}
}

fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<Dh>> {
fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<dyn Dh>> {
match *choice {
DHChoice::Curve25519 => Some(Box::new(Dh25519::default())),
_ => None,
}
}

fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<Hash>> {
fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<dyn Hash>> {
match *choice {
HashChoice::SHA256 => Some(Box::new(HashSHA256::default())),
HashChoice::SHA512 => Some(Box::new(HashSHA512::default())),
Expand All @@ -52,7 +52,7 @@ impl CryptoResolver for DefaultResolver {
}
}

fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<Cipher>> {
fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<dyn Cipher>> {
match *choice {
CipherChoice::ChaChaPoly => Some(Box::new(CipherChaChaPoly::default())),
CipherChoice::AESGCM => Some(Box::new(CipherAESGCM::default())),
Expand Down Expand Up @@ -121,7 +121,7 @@ impl Dh for Dh25519 {
self.pubkey = x25519::x25519(self.privkey, x25519::X25519_BASEPOINT_BYTES);
}

fn generate(&mut self, rng: &mut Random) {
fn generate(&mut self, rng: &mut dyn Random) {
rng.fill_bytes(&mut self.privkey);
self.pubkey = x25519::x25519(self.privkey, x25519::X25519_BASEPOINT_BYTES);
}
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Hash for HashBLAKE2s {
#[cfg(test)]
mod tests {

extern crate hex;
use hex;

use crate::types::*;
use super::*;
Expand Down
22 changes: 11 additions & 11 deletions src/resolvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@ use crate::types::{Cipher, Dh, Hash, Random};
/// An object that resolves the providers of Noise crypto choices
pub trait CryptoResolver {
/// Provide an implementation of the Random trait or None if none available.
fn resolve_rng(&self) -> Option<Box<Random>>;
fn resolve_rng(&self) -> Option<Box<dyn Random>>;

/// Provide an implementation of the Dh trait for the given DHChoice or None if unavailable.
fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<Dh>>;
fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<dyn Dh>>;

/// Provide an implementation of the Hash trait for the given HashChoice or None if unavailable.
fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<Hash>>;
fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<dyn Hash>>;

/// Provide an implementation of the Cipher trait for the given CipherChoice or None if unavailable.
fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<Cipher>>;
fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<dyn Cipher>>;
}

/// A helper struct that helps to opportunistically use one resolver, but
/// can fallback to another if the first didn't have an implementation for
/// a given primitive.
pub struct FallbackResolver {
preferred: Box<CryptoResolver>,
fallback: Box<CryptoResolver>,
preferred: Box<dyn CryptoResolver>,
fallback: Box<dyn CryptoResolver>,
}

impl FallbackResolver {
/// Create a new `FallbackResolver` that holds the primary and secondary resolver.
pub fn new(preferred: Box<CryptoResolver>, fallback: Box<CryptoResolver>) -> Self {
pub fn new(preferred: Box<dyn CryptoResolver>, fallback: Box<dyn CryptoResolver>) -> Self {
Self { preferred, fallback }
}
}

impl CryptoResolver for FallbackResolver {
fn resolve_rng(&self) -> Option<Box<Random>> {
fn resolve_rng(&self) -> Option<Box<dyn Random>> {
self.preferred.resolve_rng().or_else(|| self.fallback.resolve_rng())
}

fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<Dh>> {
fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<dyn Dh>> {
self.preferred.resolve_dh(choice).or_else(|| self.fallback.resolve_dh(choice))
}

fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<Hash>> {
fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<dyn Hash>> {
self.preferred.resolve_hash(choice).or_else(|| self.fallback.resolve_hash(choice))
}

fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<Cipher>> {
fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<dyn Cipher>> {
self.preferred.resolve_cipher(choice).or_else(|| self.fallback.resolve_cipher(choice))
}
}
2 changes: 1 addition & 1 deletion src/stateless_transportstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl StatelessTransportState {
}

impl fmt::Debug for StatelessTransportState {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("StatelessTransportState").finish()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/symmetricstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct SymmetricState {
}

impl SymmetricState {
pub fn new(cipherstate: CipherState, hasher: Box<Hash>) -> SymmetricState {
pub fn new(cipherstate: CipherState, hasher: Box<dyn Hash>) -> SymmetricState {
SymmetricState {
cipherstate,
hasher,
Expand Down
2 changes: 1 addition & 1 deletion src/transportstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl TransportState {
}

impl fmt::Debug for TransportState {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("TransportState").finish()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait Dh : Send + Sync {
fn set(&mut self, privkey: &[u8]);

/// Generate a new private key
fn generate(&mut self, rng: &mut Random);
fn generate(&mut self, rng: &mut dyn Random);

/// Get the public key
fn pubkey(&self) -> &[u8];
Expand Down
22 changes: 11 additions & 11 deletions tests/general.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
#![allow(non_snake_case)]
extern crate hex;
extern crate snow;
extern crate x25519_dalek;
extern crate rand_core;
use hex;
use snow;
use x25519_dalek;
use rand_core;

use hex::FromHex;
use snow::{Builder, resolvers::{CryptoResolver, DefaultResolver}};
use snow::error::*;

use snow::params::*;
use snow::types::*;
use x25519_dalek as x25519;
Expand Down Expand Up @@ -64,20 +64,20 @@ impl TestResolver {
}

impl CryptoResolver for TestResolver {
fn resolve_rng(&self) -> Option<Box<Random>> {
fn resolve_rng(&self) -> Option<Box<dyn Random>> {
let rng = CountingRng(self.next_byte as u64);
Some(Box::new(rng))
}

fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<Dh>> {
fn resolve_dh(&self, choice: &DHChoice) -> Option<Box<dyn Dh>> {
self.parent.resolve_dh(choice)
}

fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<Hash>> {
fn resolve_hash(&self, choice: &HashChoice) -> Option<Box<dyn Hash>> {
self.parent.resolve_hash(choice)
}

fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<Cipher>> {
fn resolve_cipher(&self, choice: &CipherChoice) -> Option<Box<dyn Cipher>> {
self.parent.resolve_cipher(choice)
}
}
Expand Down Expand Up @@ -684,8 +684,8 @@ fn test_stateless_sanity_session() {
let len = h_r.write_message(b"defg", &mut buffer_msg).unwrap();
h_i.read_message(&buffer_msg[..len], &mut buffer_out).unwrap();

let mut h_i = h_i.into_stateless_transport_mode().unwrap();
let mut h_r = h_r.into_stateless_transport_mode().unwrap();
let h_i = h_i.into_stateless_transport_mode().unwrap();
let h_r = h_r.into_stateless_transport_mode().unwrap();

let len = h_i.write_message(1337, b"hack the planet", &mut buffer_msg).unwrap();
let len = h_r.read_message(1337, &buffer_msg[..len], &mut buffer_out).unwrap();
Expand Down

0 comments on commit 56b26d7

Please sign in to comment.