Repository: cloudflare/boringtun (language: rust)

Issue:
2018 edition



Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index e209d970..cd62eb5a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,6 +6,7 @@ authors = ["Vlad Krasnov <vlad@cloudflare.com>"]
 license = "BSD-3-Clause"
 readme = "README.md"
 repository = "https://github.com/cloudflare/boringtun"
+edition = "2018"
 
 [dependencies]
 base64 = "0.9.2"
diff --git a/benches/mod.rs b/benches/mod.rs
index 204fff99..c0e3f3e9 100644
--- a/benches/mod.rs
+++ b/benches/mod.rs
@@ -2,7 +2,6 @@
 // SPDX-License-Identifier: BSD-3-Clause
 
 #![feature(test)]
-extern crate boringtun;
 extern crate test;
 
 #[cfg(test)]
diff --git a/src/benchmarks_example.rs b/src/benchmarks_example.rs
index 3d1a98ea..49ec495e 100644
--- a/src/benchmarks_example.rs
+++ b/src/benchmarks_example.rs
@@ -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;
diff --git a/src/crypto/blake2s/mod.rs b/src/crypto/blake2s/mod.rs
index a95aa705..1417539d 100644
--- a/src/crypto/blake2s/mod.rs
+++ b/src/crypto/blake2s/mod.rs
@@ -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;
diff --git a/src/crypto/chacha20poly1305/mod.rs b/src/crypto/chacha20poly1305/mod.rs
index cd2f8c61..ee6a7f34 100644
--- a/src/crypto/chacha20poly1305/mod.rs
+++ b/src/crypto/chacha20poly1305/mod.rs
@@ -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;
diff --git a/src/crypto/x25519/mod.rs b/src/crypto/x25519/mod.rs
index 5f1384c7..2b229654 100644
--- a/src/crypto/x25519/mod.rs
+++ b/src/crypto/x25519/mod.rs
@@ -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;
diff --git a/src/device/allowed_ips.rs b/src/device/allowed_ips.rs
index 28cdccc6..1f00beaf 100644
--- a/src/device/allowed_ips.rs
+++ b/src/device/allowed_ips.rs
@@ -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;
 
diff --git a/src/device/api.rs b/src/device/api.rs
index a6311f63..7d96e827 100644
--- a/src/device/api.rs
+++ b/src/device/api.rs
@@ -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};
diff --git a/src/device/drop_privileges.rs b/src/device/drop_privileges.rs
index 9d0ba004..b454d528 100644
--- a/src/device/drop_privileges.rs
+++ b/src/device/drop_privileges.rs
@@ -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> {
diff --git a/src/device/mod.rs b/src/device/mod.rs
index 27ed0701..418f634e 100644
--- a/src/device/mod.rs
+++ b/src/device/mod.rs
@@ -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};
@@ -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
diff --git a/src/device/peer.rs b/src/device/peer.rs
index dd4f9504..d9ecc061 100644
--- a/src/device/peer.rs
+++ b/src/device/peer.rs
@@ -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;
diff --git a/src/ffi/benchmark.rs b/src/ffi/benchmark.rs
index 4448aa24..cf9f1ba4 100644
--- a/src/ffi/benchmark.rs
+++ b/src/ffi/benchmark.rs
@@ -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"))]
diff --git a/src/lib.rs b/src/lib.rs
index 8029392a..64dbccf4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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;
diff --git a/src/main.rs b/src/main.rs
index 2d37ed56..c8134756 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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;
 
diff --git a/src/noise/handshake.rs b/src/noise/handshake.rs
index 9a59d7dd..dcd90bf2 100644
--- a/src/noise/handshake.rs
+++ b/src/noise/handshake.rs
@@ -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};
 
diff --git a/src/noise/mod.rs b/src/noise/mod.rs
index 21b669ab..8aa63c00 100644
--- a/src/noise/mod.rs
+++ b/src/noise/mod.rs
@@ -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;
diff --git a/src/noise/session.rs b/src/noise/session.rs
index cb5cea26..b1a096e4 100644
--- a/src/noise/session.rs
+++ b/src/noise/session.rs
@@ -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};
diff --git a/src/noise/timers.rs b/src/noise/timers.rs
index bd9a5fcb..54d83547 100644
--- a/src/noise/timers.rs
+++ b/src/noise/timers.rs
@@ -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};


Test patch:
diff --git a/src/device/integration_tests/mod.rs b/src/device/integration_tests/mod.rs
index c384183c..563e053e 100644
--- a/src/device/integration_tests/mod.rs
+++ b/src/device/integration_tests/mod.rs
@@ -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::*;
diff --git a/src/noise/tests/mod.rs b/src/noise/tests/mod.rs
index 7b92dc39..3cbd6f33 100644
--- a/src/noise/tests/mod.rs
+++ b/src/noise/tests/mod.rs
@@ -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;