Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade rust toolchain to 1.51 #315

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"yamux",
"secio",
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ fmt:
cargo fmt --all -- --check

clippy:
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo clippy --all --tests --features ws,unstable -- -D clippy::let_underscore_must_use
$(Change_Work_Path) && RUSTFLAGS='-W warnings' cargo clippy --all --tests --features ws,unstable -- -D clippy::let_underscore_must_use

test:
$(Change_Work_Path) && RUSTFLAGS='-F warnings' RUST_BACKTRACE=full cargo test --all --features ws,unstable
$(Change_Work_Path) && RUSTFLAGS='-W warnings' RUST_BACKTRACE=full cargo test --all --features ws,unstable

fuzz:
cargo +nightly fuzz run secio_crypto_decrypt_cipher -- -max_total_time=60
Expand All @@ -32,14 +32,12 @@ examples:

features-check:
# remove yamux default features
sed -i 's/"tokio-timer"//g' yamux/Cargo.toml
$(Change_Work_Path) && cargo build --features unstable
$(Change_Work_Path) && cargo build --features tokio-runtime,generic-timer,unstable --no-default-features
$(Change_Work_Path) && cargo build --features async-runtime,generic-timer,unstable --no-default-features
$(Change_Work_Path) && cargo build --features async-runtime,async-timer,unstable --no-default-features
# required wasm32-unknown-unknown target
$(Change_Work_Path) && cargo build --features wasm-timer,unstable --no-default-features --target=wasm32-unknown-unknown
git checkout .

bench_p2p:
cd bench && cargo run --release
Expand Down
20 changes: 10 additions & 10 deletions multiaddr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Multiaddr {
/// use tentacle_multiaddr::{Multiaddr, Protocol};
///
/// let mut address: Multiaddr = "/ip4/127.0.0.1".parse().unwrap();
/// address.push(Protocol::TCP(10000));
/// address.push(Protocol::Tcp(10000));
/// println!("{}", address);
/// assert_eq!(address, "/ip4/127.0.0.1/tcp/10000".parse().unwrap());
/// ```
Expand All @@ -70,8 +70,8 @@ impl Multiaddr {
///
/// let mut address: Multiaddr = "/ip4/127.0.0.1/tcp/5678".parse().unwrap();
///
/// assert_eq!(address.pop().unwrap(), Protocol::TCP(5678));
/// assert_eq!(address.pop().unwrap(), Protocol::IP4(Ipv4Addr::new(127, 0, 0, 1)));
/// assert_eq!(address.pop().unwrap(), Protocol::Tcp(5678));
/// assert_eq!(address.pop().unwrap(), Protocol::Ip4(Ipv4Addr::new(127, 0, 0, 1)));
/// ```
///
pub fn pop<'a>(&mut self) -> Option<Protocol<'a>> {
Expand Down Expand Up @@ -100,8 +100,8 @@ impl Multiaddr {
/// let address: Multiaddr = "/ip4/127.0.0.1/tcp/5678".parse().unwrap();
///
/// let components = address.iter().collect::<Vec<_>>();
/// assert_eq!(components[0], Protocol::IP4(Ipv4Addr::new(127, 0, 0, 1)));
/// assert_eq!(components[1], Protocol::TCP(5678));
/// assert_eq!(components[0], Protocol::Ip4(Ipv4Addr::new(127, 0, 0, 1)));
/// assert_eq!(components[1], Protocol::Tcp(5678));
/// ```
///
pub fn iter(&self) -> Iter<'_> {
Expand Down Expand Up @@ -264,13 +264,13 @@ impl From<IpAddr> for Multiaddr {

impl From<Ipv4Addr> for Multiaddr {
fn from(v: Ipv4Addr) -> Multiaddr {
Protocol::IP4(v).into()
Protocol::Ip4(v).into()
}
}

impl From<Ipv6Addr> for Multiaddr {
fn from(v: Ipv6Addr) -> Multiaddr {
Protocol::IP6(v).into()
Protocol::Ip6(v).into()
}
}

Expand Down Expand Up @@ -340,7 +340,7 @@ impl<'de> Deserialize<'de> for Multiaddr {
{
struct Visitor {
is_human_readable: bool,
};
}

impl<'de> de::Visitor<'de> for Visitor {
type Value = Multiaddr;
Expand Down Expand Up @@ -401,7 +401,7 @@ impl<'de> Deserialize<'de> for Multiaddr {
///
/// ```rust
/// # use tentacle_multiaddr::multiaddr;
/// let addr = multiaddr!(IP4([127, 0, 0, 1]), TCP(10500u16));
/// let addr = multiaddr!(Ip4([127, 0, 0, 1]), Tcp(10500u16));
/// ```
///
/// Each element passed to `multiaddr!` should be a variant of the `Protocol` enum. The
Expand Down Expand Up @@ -433,7 +433,7 @@ mod test {
#[test]
fn compatibility_test() {
let mut address: Multiaddr = "/ip4/127.0.0.1".parse().unwrap();
address.push(Protocol::TCP(10000));
address.push(Protocol::Tcp(10000));
assert_eq!(address, "/ip4/127.0.0.1/tcp/10000".parse().unwrap());

let _address: Multiaddr = "/ip4/127.0.0.1/tcp/20/tls/main".parse().unwrap();
Expand Down
80 changes: 40 additions & 40 deletions multiaddr/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const SHA256_SIZE: u8 = 32;
/// `Protocol` describes all possible multiaddress protocols.
#[derive(PartialEq, Eq, Clone, Debug)]
pub enum Protocol<'a> {
DNS4(Cow<'a, str>),
DNS6(Cow<'a, str>),
IP4(Ipv4Addr),
IP6(Ipv6Addr),
Dns4(Cow<'a, str>),
Dns6(Cow<'a, str>),
Ip4(Ipv4Addr),
Ip6(Ipv6Addr),
P2P(Cow<'a, [u8]>),
TCP(u16),
TLS(Cow<'a, str>),
Tcp(u16),
Tls(Cow<'a, str>),
Ws,
Wss,
}
Expand All @@ -50,23 +50,23 @@ impl<'a> Protocol<'a> {
match iter.next().ok_or(Error::InvalidProtocolString)? {
"dns4" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
Ok(Protocol::DNS4(Cow::Borrowed(s)))
Ok(Protocol::Dns4(Cow::Borrowed(s)))
}
"dns6" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
Ok(Protocol::DNS6(Cow::Borrowed(s)))
Ok(Protocol::Dns6(Cow::Borrowed(s)))
}
"ip4" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
Ok(Protocol::IP4(Ipv4Addr::from_str(s)?))
Ok(Protocol::Ip4(Ipv4Addr::from_str(s)?))
}
"ip6" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
Ok(Protocol::IP6(Ipv6Addr::from_str(s)?))
Ok(Protocol::Ip6(Ipv6Addr::from_str(s)?))
}
"tls" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
Ok(Protocol::TLS(Cow::Borrowed(s)))
Ok(Protocol::Tls(Cow::Borrowed(s)))
}
"p2p" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
Expand All @@ -76,7 +76,7 @@ impl<'a> Protocol<'a> {
}
"tcp" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
Ok(Protocol::TCP(s.parse()?))
Ok(Protocol::Tcp(s.parse()?))
}
"ws" => Ok(Protocol::Ws),
"wss" => Ok(Protocol::Wss),
Expand All @@ -99,17 +99,17 @@ impl<'a> Protocol<'a> {
DNS4 => {
let (n, input) = decode::usize(input)?;
let (data, rest) = split_header(n, input)?;
Ok((Protocol::DNS4(Cow::Borrowed(str::from_utf8(data)?)), rest))
Ok((Protocol::Dns4(Cow::Borrowed(str::from_utf8(data)?)), rest))
}
DNS6 => {
let (n, input) = decode::usize(input)?;
let (data, rest) = split_header(n, input)?;
Ok((Protocol::DNS6(Cow::Borrowed(str::from_utf8(data)?)), rest))
Ok((Protocol::Dns6(Cow::Borrowed(str::from_utf8(data)?)), rest))
}
IP4 => {
let (data, rest) = split_header(4, input)?;
Ok((
Protocol::IP4(Ipv4Addr::new(data[0], data[1], data[2], data[3])),
Protocol::Ip4(Ipv4Addr::new(data[0], data[1], data[2], data[3])),
rest,
))
}
Expand All @@ -126,12 +126,12 @@ impl<'a> Protocol<'a> {
seg[0], seg[1], seg[2], seg[3], seg[4], seg[5], seg[6], seg[7],
);

Ok((Protocol::IP6(addr), rest))
Ok((Protocol::Ip6(addr), rest))
}
TLS => {
let (n, input) = decode::usize(input)?;
let (data, rest) = split_header(n, input)?;
Ok((Protocol::TLS(Cow::Borrowed(str::from_utf8(data)?)), rest))
Ok((Protocol::Tls(Cow::Borrowed(str::from_utf8(data)?)), rest))
}
P2P => {
let (n, input) = decode::usize(input)?;
Expand All @@ -143,7 +143,7 @@ impl<'a> Protocol<'a> {
let (data, rest) = split_header(2, input)?;
let mut rdr = Cursor::new(data);
let num = rdr.get_u16();
Ok((Protocol::TCP(num), rest))
Ok((Protocol::Tcp(num), rest))
}
WS => Ok((Protocol::Ws, input)),
WSS => Ok((Protocol::Wss, input)),
Expand All @@ -157,33 +157,33 @@ impl<'a> Protocol<'a> {
use unsigned_varint::encode;
let mut buf = encode::u32_buffer();
match self {
Protocol::DNS4(s) => {
Protocol::Dns4(s) => {
w.put(encode::u32(DNS4, &mut buf));
let bytes = s.as_bytes();
w.put(encode::usize(bytes.len(), &mut encode::usize_buffer()));
w.put(bytes)
}
Protocol::DNS6(s) => {
Protocol::Dns6(s) => {
w.put(encode::u32(DNS6, &mut buf));
let bytes = s.as_bytes();
w.put(encode::usize(bytes.len(), &mut encode::usize_buffer()));
w.put(bytes)
}
Protocol::IP4(addr) => {
Protocol::Ip4(addr) => {
w.put(encode::u32(IP4, &mut buf));
w.put(&addr.octets()[..])
}
Protocol::IP6(addr) => {
Protocol::Ip6(addr) => {
w.put(encode::u32(IP6, &mut buf));
for &segment in &addr.segments() {
w.put_u16(segment)
}
}
Protocol::TCP(port) => {
Protocol::Tcp(port) => {
w.put(encode::u32(TCP, &mut buf));
w.put_u16(*port)
}
Protocol::TLS(s) => {
Protocol::Tls(s) => {
w.put(encode::u32(TLS, &mut buf));
let bytes = s.as_bytes();
w.put(encode::usize(bytes.len(), &mut encode::usize_buffer()));
Expand All @@ -202,12 +202,12 @@ impl<'a> Protocol<'a> {
/// Turn this `Protocol` into one that owns its data, thus being valid for any lifetime.
pub fn acquire<'b>(self) -> Protocol<'b> {
match self {
Protocol::DNS4(s) => Protocol::DNS4(Cow::Owned(s.into_owned())),
Protocol::DNS6(s) => Protocol::DNS6(Cow::Owned(s.into_owned())),
Protocol::IP4(addr) => Protocol::IP4(addr),
Protocol::IP6(addr) => Protocol::IP6(addr),
Protocol::TCP(port) => Protocol::TCP(port),
Protocol::TLS(s) => Protocol::TLS(Cow::Owned(s.into_owned())),
Protocol::Dns4(s) => Protocol::Dns4(Cow::Owned(s.into_owned())),
Protocol::Dns6(s) => Protocol::Dns6(Cow::Owned(s.into_owned())),
Protocol::Ip4(addr) => Protocol::Ip4(addr),
Protocol::Ip6(addr) => Protocol::Ip6(addr),
Protocol::Tcp(port) => Protocol::Tcp(port),
Protocol::Tls(s) => Protocol::Tls(Cow::Owned(s.into_owned())),
Protocol::P2P(s) => Protocol::P2P(Cow::Owned(s.into_owned())),
Protocol::Ws => Protocol::Ws,
Protocol::Wss => Protocol::Wss,
Expand All @@ -219,13 +219,13 @@ impl<'a> fmt::Display for Protocol<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::Protocol::*;
match self {
DNS4(s) => write!(f, "/dns4/{}", s),
DNS6(s) => write!(f, "/dns6/{}", s),
IP4(addr) => write!(f, "/ip4/{}", addr),
IP6(addr) => write!(f, "/ip6/{}", addr),
Dns4(s) => write!(f, "/dns4/{}", s),
Dns6(s) => write!(f, "/dns6/{}", s),
Ip4(addr) => write!(f, "/ip4/{}", addr),
Ip6(addr) => write!(f, "/ip6/{}", addr),
P2P(c) => write!(f, "/p2p/{}", bs58::encode(c).into_string()),
TCP(port) => write!(f, "/tcp/{}", port),
TLS(s) => write!(f, "/tls/{}", s),
Tcp(port) => write!(f, "/tcp/{}", port),
Tls(s) => write!(f, "/tls/{}", s),
Ws => write!(f, "/ws"),
Wss => write!(f, "/wss"),
}
Expand All @@ -236,23 +236,23 @@ impl<'a> From<IpAddr> for Protocol<'a> {
#[inline]
fn from(addr: IpAddr) -> Self {
match addr {
IpAddr::V4(addr) => Protocol::IP4(addr),
IpAddr::V6(addr) => Protocol::IP6(addr),
IpAddr::V4(addr) => Protocol::Ip4(addr),
IpAddr::V6(addr) => Protocol::Ip6(addr),
}
}
}

impl<'a> From<Ipv4Addr> for Protocol<'a> {
#[inline]
fn from(addr: Ipv4Addr) -> Self {
Protocol::IP4(addr)
Protocol::Ip4(addr)
}
}

impl<'a> From<Ipv6Addr> for Protocol<'a> {
#[inline]
fn from(addr: Ipv6Addr) -> Self {
Protocol::IP6(addr)
Protocol::Ip6(addr)
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.46.0
1.51.0
3 changes: 1 addition & 2 deletions secio/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::env;

#[allow(clippy::inconsistent_digit_grouping)]
fn main() {
if let Ok(v) = env::var("DEP_OPENSSL_VERSION_NUMBER") {
let version = u64::from_str_radix(&v, 16).unwrap();

if version >= 0x1_01_00_00_0 {
if version >= 0x1010_0000 {
println!("cargo:rustc-cfg=ossl110");
}
}
Expand Down
12 changes: 6 additions & 6 deletions secio/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum CryptoMode {
#[doc(hidden)]
#[cfg(all(ossl110, unix))]
pub fn new_stream(t: cipher::CipherType, key: &[u8], _mode: CryptoMode) -> BoxStreamCipher {
Box::new(openssl_impl::OpenSSLCrypt::new(t, key))
Box::new(openssl_impl::OpenSsLCrypt::new(t, key))
}

/// Generate a specific Cipher with key and initialize vector
Expand All @@ -59,7 +59,7 @@ pub fn new_stream(t: cipher::CipherType, key: &[u8], mode: CryptoMode) -> BoxStr
use cipher::CipherType::*;

match t {
Aes128Gcm | Aes256Gcm => Box::new(openssl_impl::OpenSSLCrypt::new(t, key)),
Aes128Gcm | Aes256Gcm => Box::new(openssl_impl::OpenSsLCrypt::new(t, key)),
ChaCha20Poly1305 => Box::new(ring_impl::RingAeadCipher::new(t, key, mode)),
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ fn nonce_advance(nonce: &mut [u8]) {
#[cfg(all(test, unix))]
mod test {
use super::{
cipher::CipherType, openssl_impl::OpenSSLCrypt, ring_impl::RingAeadCipher,
cipher::CipherType, openssl_impl::OpenSsLCrypt, ring_impl::RingAeadCipher,
wasm_compat::WasmCrypt, CryptoMode,
};

Expand All @@ -109,7 +109,7 @@ mod test {
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();

let mut openssl_encrypt = OpenSSLCrypt::new(cipher, &key);
let mut openssl_encrypt = OpenSsLCrypt::new(cipher, &key);
let mut ring_decrypt = RingAeadCipher::new(cipher, &key, CryptoMode::Decrypt);

// first time
Expand All @@ -135,7 +135,7 @@ mod test {
.collect::<Vec<_>>();

let mut ring_encrypt = RingAeadCipher::new(cipher, &key, CryptoMode::Encrypt);
let mut openssl_decrypt = OpenSSLCrypt::new(cipher, &key);
let mut openssl_decrypt = OpenSsLCrypt::new(cipher, &key);

// first time
let message = b"HELLO WORLD";
Expand Down Expand Up @@ -185,7 +185,7 @@ mod test {
.collect::<Vec<_>>();

let mut wasm_encrypt = WasmCrypt::new(cipher, &key);
let mut openssl_decrypt = OpenSSLCrypt::new(cipher, &key);
let mut openssl_decrypt = OpenSsLCrypt::new(cipher, &key);

// first time
let message = b"HELLO WORLD";
Expand Down
Loading