Skip to content

Commit 9cf9abf

Browse files
committed
standardize MSRV for clippy
1 parent 67ea00c commit 9cf9abf

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
with:
2727
toolchain: ${{ matrix.rust }}
2828
components: clippy
29+
- uses: Swatinem/rust-cache@v2
2930
- name: Install LLVM and Clang
3031
if: startsWith(matrix.os, 'windows')
3132
uses: KyleMayes/install-llvm-action@v2

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ serde = "1.0"
102102
serde_json = "1.0"
103103
serde_derive = "1.0"
104104
hex = "0.4"
105-
lazy_static = "1.4"
106105
x25519-dalek = "2.0"
107106
# TODO: Waiting on https://github.com/RustCrypto/traits/issues/1642
108107
rand = "0.8"

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msrv = "1.81.0"

examples/oneway.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@
1010
//! as `cargo run --example oneway` to see the magic happen.
1111
1212
use hex::FromHex;
13-
use lazy_static::lazy_static;
1413
use snow::{params::NoiseParams, Builder, Keypair};
1514
use std::{
1615
io::{self, Read, Write},
1716
net::{TcpListener, TcpStream},
17+
sync::LazyLock,
1818
};
1919

2020
static SECRET: &[u8; 32] = b"i don't care for fidget spinners";
21-
lazy_static! {
22-
static ref PARAMS: NoiseParams = "Noise_Xpsk1_25519_ChaChaPoly_BLAKE2s".parse().unwrap();
23-
// The responder key is static in this example because the X pattern means
24-
// the initiator has pre-handshake knowledge of the responder's public key
25-
// (and of course both share the same psk `SECRET`)
26-
static ref RESPONDER: Keypair = Keypair {
27-
private: Vec::from_hex("52fbe3721d1adbe312d270ca2db5ce5bd39ddc206075f3a8f06d422619c8eb5d").expect("valid hex"),
28-
public: Vec::from_hex("435ce8a8415ccd44de5e207581ac7207b416683028bcaecc9eb38d944e6f900c").expect("valid hex"),
29-
};
30-
}
21+
static PARAMS: LazyLock<NoiseParams> =
22+
LazyLock::new(|| "Noise_Xpsk1_25519_ChaChaPoly_BLAKE2s".parse().unwrap());
23+
// The responder key is static in this example because the X pattern means
24+
// the initiator has pre-handshake knowledge of the responder's public key
25+
// (and of course both share the same psk `SECRET`)
26+
static RESPONDER: LazyLock<Keypair> = LazyLock::new(|| Keypair {
27+
private: Vec::from_hex("52fbe3721d1adbe312d270ca2db5ce5bd39ddc206075f3a8f06d422619c8eb5d")
28+
.expect("valid hex"),
29+
public: Vec::from_hex("435ce8a8415ccd44de5e207581ac7207b416683028bcaecc9eb38d944e6f900c")
30+
.expect("valid hex"),
31+
});
3132

3233
#[cfg(any(feature = "default-resolver", feature = "ring-accelerated"))]
3334
fn main() {

examples/simple.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
//! Run the server a-like-a-so `cargo run --example simple -- -s`, then run the client
1010
//! as `cargo run --example simple` to see the magic happen.
1111
12-
use lazy_static::lazy_static;
1312
use snow::{params::NoiseParams, Builder};
1413
use std::{
1514
io::{self, Read, Write},
1615
net::{TcpListener, TcpStream},
16+
sync::LazyLock,
1717
};
1818

1919
static SECRET: &[u8; 32] = b"i don't care for fidget spinners";
20-
lazy_static! {
21-
static ref PARAMS: NoiseParams = "Noise_XXpsk3_25519_ChaChaPoly_BLAKE2s".parse().unwrap();
22-
}
20+
static PARAMS: LazyLock<NoiseParams> =
21+
LazyLock::new(|| "Noise_XXpsk3_25519_ChaChaPoly_BLAKE2s".parse().unwrap());
2322

2423
#[cfg(any(feature = "default-resolver", feature = "ring-accelerated"))]
2524
fn main() {

tests/vectors.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use serde::{
1212
use snow::{params::*, Builder, HandshakeState};
1313
use std::{
1414
fmt,
15+
fmt::Write as _,
1516
fs::{File, OpenOptions},
1617
io::Read,
1718
marker::PhantomData,
@@ -21,7 +22,7 @@ use std::{
2122
#[derive(Clone)]
2223
struct HexBytes<T> {
2324
original: String,
24-
payload: T,
25+
payload: T,
2526
}
2627

2728
impl<T: AsRef<[u8]>> From<T> for HexBytes<T> {
@@ -82,7 +83,7 @@ impl<T: AsRef<[u8]>> Serialize for HexBytes<T> {
8283

8384
#[derive(Serialize, Deserialize)]
8485
struct TestMessage {
85-
payload: HexBytes<Vec<u8>>,
86+
payload: HexBytes<Vec<u8>>,
8687
ciphertext: HexBytes<Vec<u8>>,
8788
}
8889

@@ -125,13 +126,13 @@ struct TestVector {
125126
#[serde(skip_serializing_if = "Option::is_none")]
126127
init_remote_static: Option<HexBytes<Vec<u8>>>,
127128

128-
resp_prologue: HexBytes<Vec<u8>>,
129+
resp_prologue: HexBytes<Vec<u8>>,
129130
#[serde(skip_serializing_if = "Option::is_none")]
130-
resp_psks: Option<Vec<HexBytes<[u8; 32]>>>,
131+
resp_psks: Option<Vec<HexBytes<[u8; 32]>>>,
131132
#[serde(skip_serializing_if = "Option::is_none")]
132-
resp_static: Option<HexBytes<Vec<u8>>>,
133+
resp_static: Option<HexBytes<Vec<u8>>>,
133134
#[serde(skip_serializing_if = "Option::is_none")]
134-
resp_ephemeral: Option<HexBytes<Vec<u8>>>,
135+
resp_ephemeral: Option<HexBytes<Vec<u8>>>,
135136
#[serde(skip_serializing_if = "Option::is_none")]
136137
resp_remote_static: Option<HexBytes<Vec<u8>>>,
137138

@@ -218,10 +219,10 @@ fn confirm_message_vectors(
218219
.map_err(|_| format!("read_message failed on message {i}"))?;
219220
if sendbuf[..len] != (*message.ciphertext)[..] || *message.payload != recvbuf[..recv_len] {
220221
let mut s = String::new();
221-
s.push_str(&format!("message {i}"));
222-
s.push_str(&format!("plaintext: {}\n", hex::encode(&*message.payload)));
223-
s.push_str(&format!("expected: {}\n", hex::encode(&*message.ciphertext)));
224-
s.push_str(&format!("actual: {}", hex::encode(&sendbuf[..len])));
222+
writeln!(&mut s, "message {i}").unwrap();
223+
writeln!(&mut s, "plaintext: {}", hex::encode(&*message.payload)).unwrap();
224+
writeln!(&mut s, "expected: {}", hex::encode(&*message.ciphertext)).unwrap();
225+
writeln!(&mut s, "actual: {}", hex::encode(&sendbuf[..len])).unwrap();
225226
return Err(s);
226227
}
227228
}
@@ -236,14 +237,16 @@ fn confirm_message_vectors(
236237
let recv_len = recv.read_message(&sendbuf[..len], &mut recvbuf).unwrap();
237238
if sendbuf[..len] != (*message.ciphertext)[..] || *message.payload != recvbuf[..recv_len] {
238239
let mut s = String::new();
239-
s.push_str(&format!("message {i}"));
240-
s.push_str(&format!("plaintext : {}\n", hex::encode(&*message.payload)));
241-
s.push_str(&format!("expected ciphertext: {}\n", hex::encode(&*message.ciphertext)));
242-
s.push_str(&format!(
243-
"actual ciphertext : {}\n",
240+
writeln!(&mut s, "message {i}").unwrap();
241+
writeln!(&mut s, "plaintext : {}", hex::encode(&*message.payload)).unwrap();
242+
writeln!(&mut s, "expected ciphertext: {}", hex::encode(&*message.ciphertext)).unwrap();
243+
writeln!(
244+
&mut s,
245+
"actual ciphertext : {}",
244246
hex::encode(&sendbuf[..message.ciphertext.len()])
245-
));
246-
s.push_str(&format!("actual plaintext : {}", hex::encode(&recvbuf[..recv_len])));
247+
)
248+
.unwrap();
249+
writeln!(&mut s, "actual plaintext : {}", hex::encode(&recvbuf[..recv_len])).unwrap();
247250
return Err(s);
248251
}
249252
}
@@ -375,7 +378,7 @@ fn generate_vector(params: NoiseParams) -> TestVector {
375378
let payload = random_vec(32);
376379
let len = init.write_message(&payload, &mut ibuf).unwrap();
377380
messages.push(TestMessage {
378-
payload: payload.clone().into(),
381+
payload: payload.clone().into(),
379382
ciphertext: ibuf[..len].to_vec().into(),
380383
});
381384
let _ = resp.read_message(&ibuf[..len], &mut obuf).unwrap();
@@ -387,7 +390,7 @@ fn generate_vector(params: NoiseParams) -> TestVector {
387390
let payload = random_vec(32);
388391
let len = resp.write_message(&payload, &mut ibuf).unwrap();
389392
messages.push(TestMessage {
390-
payload: payload.clone().into(),
393+
payload: payload.clone().into(),
391394
ciphertext: ibuf[..len].to_vec().into(),
392395
});
393396
let _ = init.read_message(&ibuf[..len], &mut obuf).unwrap();

0 commit comments

Comments
 (0)