Skip to content

Commit

Permalink
2018 edition (cloudflare#21)
Browse files Browse the repository at this point in the history
* feat(edition): cargo fix --edition

* fix: variable does not need to be mutable

* feat(edition): edition=2018, remove externs

* fix(style): appease cargo fmt

* fix(imports): prepend crate::

* fix(edition): extern macro -> use

* feat(edition): remove last externs

* fix(edition): un-break cargo bench
  • Loading branch information
ashleygwilliams authored Mar 26, 2019
1 parent 3ec431d commit 34cc88c
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 77 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["Vlad Krasnov <[email protected]>"]
license = "BSD-3-Clause"
readme = "README.md"
repository = "https://github.com/cloudflare/boringtun"
edition = "2018"

[dependencies]
base64 = "0.9.2"
Expand Down
1 change: 0 additions & 1 deletion benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: BSD-3-Clause

#![feature(test)]
extern crate boringtun;
extern crate test;

#[cfg(test)]
Expand Down
8 changes: 0 additions & 8 deletions src/benchmarks_example.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// Copyright (c) 2019 Cloudflare, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

#![allow(warnings)]
extern crate base64;
extern crate hex;
extern crate libc;
extern crate ring;
extern crate spin;

mod crypto;
mod ffi;
mod noise;
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/blake2s/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: BSD-3-Clause

mod tests;
use noise::errors::*;
use noise::make_array;
use crate::noise::errors::*;
use crate::noise::make_array;
use std;
use std::mem;
use std::ops::AddAssign;
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/chacha20poly1305/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ mod poly1305;
mod tests;

use self::poly1305::*;
use noise::errors::*;
use noise::make_array;
use crate::noise::errors::*;
use crate::noise::make_array;
use std::ops::AddAssign;
use std::ops::BitXorAssign;
use std::ops::ShlAssign;
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/x25519/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

mod tests;

use crate::noise::errors::WireGuardError;
use crate::noise::make_array;
use base64::decode;
use noise::errors::WireGuardError;
use noise::make_array;
#[cfg(not(target_arch = "arm"))]
use ring::rand::*;
use std::ops::Add;
Expand Down
2 changes: 1 addition & 1 deletion src/device/allowed_ips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ macro_rules! build_iter {
ref left,
ref right,
}) => {
let (mut key, mut bits) = self.key_hlp.pop().unwrap();
let (key, mut bits) = self.key_hlp.pop().unwrap();
let cur_key = key ^ (cur_key >> bits);
bits += cur_bits;

Expand Down
6 changes: 3 additions & 3 deletions src/device/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: BSD-3-Clause

use super::{make_array, AllowedIP, Device, Error, SocketAddr, X25519PublicKey, X25519SecretKey};
use dev_lock::LockReadGuard;
use device::drop_privileges::*;
use device::Action;
use crate::dev_lock::LockReadGuard;
use crate::device::drop_privileges::*;
use crate::device::Action;
use hex::encode as encode_hex;
use libc::*;
use std::fs::{create_dir, remove_file};
Expand Down
4 changes: 2 additions & 2 deletions src/device/drop_privileges.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2019 Cloudflare, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

use device::errno_str;
use device::Error;
use crate::device::errno_str;
use crate::device::Error;
use libc::*;

pub fn get_saved_ids() -> Result<(uid_t, gid_t), Error> {
Expand Down
4 changes: 2 additions & 2 deletions src/device/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Those tests require docker and sudo priviliges to run
#[cfg(test)]
mod tests {
use crate::crypto::x25519::*;
use crate::device::*;
use base64::encode as base64encode;
use crypto::x25519::*;
use device::*;
use hex::encode;
#[cfg(not(target_arch = "arm"))]
use ring::rand::*;
Expand Down
20 changes: 10 additions & 10 deletions src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub mod tun;
#[path = "udp_unix.rs"]
pub mod udp;

use crypto::x25519::*;
use noise::handshake::parse_handshake_anon;
use crate::crypto::x25519::*;
use crate::noise::handshake::parse_handshake_anon;
use std::collections::HashMap;
use std::convert::From;
use std::net::{IpAddr, SocketAddr};
Expand All @@ -39,14 +39,14 @@ use std::sync::Arc;
use std::thread;
use std::thread::JoinHandle;

use allowed_ips::*;
use dev_lock::*;
use noise::errors::*;
use noise::*;
use peer::*;
use poll::*;
use tun::*;
use udp::*;
use crate::allowed_ips::*;
use crate::dev_lock::*;
use crate::noise::errors::*;
use crate::noise::*;
use crate::peer::*;
use crate::poll::*;
use crate::tun::*;
use crate::udp::*;

const MAX_UDP_SIZE: usize = (1 << 16) - 1;
const MAX_ITR: usize = 100; // Number of packets to handle per handler call
Expand Down
6 changes: 3 additions & 3 deletions src/device/peer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2019 Cloudflare, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

use device::udp::UDPSocket;
use device::*;
use noise::errors::WireGuardError;
use crate::device::udp::UDPSocket;
use crate::device::*;
use crate::noise::errors::WireGuardError;
use std::net::IpAddr;
use std::net::SocketAddr;
use std::str::FromStr;
Expand Down
6 changes: 3 additions & 3 deletions src/ffi/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: BSD-3-Clause

/// This module implements benchmarking code for use with the FFI bindings
use crypto::blake2s::*;
use crypto::chacha20poly1305::*;
use crypto::x25519::*;
use crate::crypto::blake2s::*;
use crate::crypto::chacha20poly1305::*;
use crate::crypto::x25519::*;
#[cfg(not(target_arch = "arm"))]
use ring::aead::*;
#[cfg(not(target_arch = "arm"))]
Expand Down
9 changes: 1 addition & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
// SPDX-License-Identifier: BSD-3-Clause

/// Simple implementation of the client side of the WireGuard protocol
extern crate base64;
extern crate hex;
#[cfg(target_os = "android")]
extern crate jni;
extern crate libc;
#[cfg(not(target_arch = "arm"))]
extern crate ring;
extern crate spin;
extern crate untrusted;
use jni;

#[cfg(target_os = "android")]
pub mod cfjni;
Expand Down
19 changes: 4 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
// Copyright (c) 2019 Cloudflare, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

extern crate base64;
extern crate chrono;
#[macro_use]
extern crate clap;
extern crate daemonize;
extern crate hex;
extern crate libc;
#[cfg(not(target_arch = "arm"))]
extern crate ring;
extern crate spin;

pub mod crypto;
mod device;
pub mod ffi;
pub mod noise;

use clap::{App, Arg};
use crate::device::drop_privileges::*;
use crate::device::*;
use crate::noise::Verbosity;
use clap::{value_t, App, Arg};
use daemonize::Daemonize;
use device::drop_privileges::*;
use device::*;
use noise::Verbosity;
use std::fs::File;
use std::os::unix::net::UnixDatagram;

Expand Down
12 changes: 6 additions & 6 deletions src/noise/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) 2019 Cloudflare, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

use crypto::blake2s::{constant_time_mac_check, Blake2s};
use crypto::chacha20poly1305::ChaCha20Poly1305;
use crypto::x25519::*;
use noise::errors::WireGuardError;
use noise::make_array;
use noise::session::Session;
use crate::crypto::blake2s::{constant_time_mac_check, Blake2s};
use crate::crypto::chacha20poly1305::ChaCha20Poly1305;
use crate::crypto::x25519::*;
use crate::noise::errors::WireGuardError;
use crate::noise::make_array;
use crate::noise::session::Session;
use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime};

Expand Down
8 changes: 4 additions & 4 deletions src/noise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ mod session;
mod tests;
mod timers;

use crypto::x25519::*;
use noise::errors::WireGuardError;
use noise::handshake::Handshake;
use noise::timers::{TimerName, Timers};
use crate::crypto::x25519::*;
use crate::noise::errors::WireGuardError;
use crate::noise::handshake::Handshake;
use crate::noise::timers::{TimerName, Timers};
use std::collections::VecDeque;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::str::FromStr;
Expand Down
6 changes: 3 additions & 3 deletions src/noise/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: BSD-3-Clause

#[cfg(target_arch = "arm")]
use crypto::chacha20poly1305::*;
use noise::errors::WireGuardError;
use noise::make_array;
use crate::crypto::chacha20poly1305::*;
use crate::noise::errors::WireGuardError;
use crate::noise::make_array;
#[cfg(not(target_arch = "arm"))]
use ring::aead::*;
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down
2 changes: 1 addition & 1 deletion src/noise/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#[cfg(test)]
mod tests {
use super::super::*;
use crate::crypto::x25519::*;
use base64::encode;
use crypto::x25519::*;
use std::fs;
use std::fs::File;
use std::io::prelude::Write;
Expand Down
2 changes: 1 addition & 1 deletion src/noise/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use self::TimerName::*;
use super::errors::WireGuardError;
use noise::{Tunn, TunnResult, Verbosity};
use crate::noise::{Tunn, TunnResult, Verbosity};
use std::ops::Index;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
Expand Down

0 comments on commit 34cc88c

Please sign in to comment.