Skip to content

Commit 7b63e9e

Browse files
committed
ssh-derive: configure and apply workspace-level lints
Adds the workspace-level config from RustCrypto/utils#1411 to this repo and applies it to `ssh-derive`. Also includes some clippy fixups for `ssh-cipher`.
1 parent c1b1bc6 commit 7b63e9e

9 files changed

Lines changed: 68 additions & 30 deletions

File tree

.clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
allow-unwrap-in-consts = true
2+
allow-unwrap-in-tests = true

.github/workflows/workspace.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
- uses: actions/checkout@v6
2222
- uses: dtolnay/rust-toolchain@stable
2323
with:
24-
toolchain: 1.92 # pinned to prevent breakages when new rust versions are released
24+
toolchain: 1.95 # pinned to prevent breakages when new rust versions are released
2525
components: clippy
26-
- run: cargo clippy --all-features
26+
- run: cargo clippy --all-features --all-targets
2727

2828
doc:
2929
runs-on: ubuntu-latest
@@ -33,7 +33,7 @@ jobs:
3333
- uses: dtolnay/rust-toolchain@stable
3434
with:
3535
toolchain: stable
36-
- run: cargo doc --workspace --all-features
36+
- run: cargo doc --workspace --all-features --no-deps
3737

3838
rustfmt:
3939
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,53 @@ members = [
88
"ssh-protocol",
99
]
1010

11-
[profile.dev]
12-
opt-level = 2
13-
1411
[patch.crates-io]
1512
ssh-cipher = { path = "./ssh-cipher" }
1613
ssh-derive = { path = "./ssh-derive" }
1714
ssh-encoding = { path = "./ssh-encoding" }
1815
ssh-key = { path = "./ssh-key" }
16+
17+
[profile.dev]
18+
opt-level = 2
19+
20+
[workspace.lints.clippy]
21+
as_conversions = "warn"
22+
borrow_as_ptr = "warn"
23+
cast_lossless = "warn"
24+
cast_possible_truncation = "warn"
25+
cast_possible_wrap = "warn"
26+
cast_precision_loss = "warn"
27+
cast_sign_loss = "warn"
28+
checked_conversions = "warn"
29+
from_iter_instead_of_collect = "warn"
30+
implicit_saturating_sub = "warn"
31+
integer_division_remainder_used = "warn"
32+
manual_assert = "warn"
33+
map_unwrap_or = "warn"
34+
missing_errors_doc = "warn"
35+
missing_panics_doc = "warn"
36+
mod_module_files = "warn"
37+
must_use_candidate = "warn"
38+
needless_range_loop = "allow"
39+
ptr_as_ptr = "warn"
40+
redundant_closure_for_method_calls = "warn"
41+
ref_as_ptr = "warn"
42+
return_self_not_must_use = "warn"
43+
semicolon_if_nothing_returned = "warn"
44+
trivially_copy_pass_by_ref = "warn"
45+
std_instead_of_alloc = "warn"
46+
std_instead_of_core = "warn"
47+
undocumented_unsafe_blocks = "warn"
48+
unnecessary_safety_comment = "warn"
49+
unwrap_used = "warn"
50+
51+
[workspace.lints.rust]
52+
missing_copy_implementations = "warn"
53+
missing_debug_implementations = "warn"
54+
missing_docs = "warn"
55+
trivial_casts = "warn"
56+
trivial_numeric_casts = "warn"
57+
unreachable_pub = "warn"
58+
unsafe_code = "forbid"
59+
unused_lifetimes = "warn"
60+
unused_qualifications = "warn"

ssh-cipher/src/chacha20poly1305.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ fn compute_mac(mut mac: Poly1305, aad: &[u8], buffer: &[u8]) -> Result<Tag> {
166166
#[cfg(test)]
167167
mod tests {
168168
use super::{AeadInOut, ChaCha20Poly1305, KeyInit, Poly1305, compute_mac};
169-
use aead::array::AsArrayRef;
170169
use hex_literal::hex;
171170

172171
#[test]
@@ -179,18 +178,18 @@ mod tests {
179178
const CT: [u8; 24] = hex!("6dcfb03be8a55e7f0220465672edd921489ea0171198e8a7");
180179
const TAG: [u8; 16] = hex!("3e82fe0a2db7128d58ef8d9047963ca3");
181180

182-
let cipher = ChaCha20Poly1305::new(KEY.as_array_ref());
183-
let mut buffer = PT.clone();
181+
let cipher = ChaCha20Poly1305::new(&KEY.into());
182+
let mut buffer = PT;
184183
let actual_tag = cipher
185-
.encrypt_inout_detached(NONCE.as_array_ref(), &AAD, buffer.as_mut_slice().into())
184+
.encrypt_inout_detached(&NONCE.into(), &AAD, buffer.as_mut_slice().into())
186185
.unwrap();
187186

188187
assert_eq!(buffer, CT);
189188
assert_eq!(actual_tag, TAG);
190189

191190
cipher
192191
.decrypt_inout_detached(
193-
NONCE.as_array_ref(),
192+
&NONCE.into(),
194193
&AAD,
195194
buffer.as_mut_slice().into(),
196195
&actual_tag,
@@ -216,7 +215,7 @@ mod tests {
216215
buffer[..aad_len].copy_from_slice(aad);
217216
buffer[aad_len..eob].copy_from_slice(pt);
218217

219-
let poly = Poly1305::new(KEY.as_array_ref());
218+
let poly = Poly1305::new(KEY.into());
220219
let expected_mac = poly.clone().compute_unpadded(&buffer[..eob]);
221220
let actual_mac = compute_mac(poly, aad, pt).unwrap();
222221

ssh-derive/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ readme = "README.md"
1212
edition = "2024"
1313
rust-version = "1.85"
1414

15-
[lib]
16-
proc-macro = true
17-
1815
[dependencies]
1916
proc-macro2 = "1"
2017
quote = "1"
2118
syn = { version = "2", features = ["extra-traits"] }
19+
20+
[lib]
21+
proc-macro = true
22+
23+
[lints]
24+
workspace = true

ssh-derive/src/encode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ fn fields_variables(fields: &syn::Fields, use_self: bool) -> Vec<TokenStream> {
222222

223223
#[cfg(test)]
224224
mod tests {
225-
#![allow(clippy::unwrap_used)]
226225
use super::*;
226+
use core::iter;
227227
use proc_macro2::Span;
228228
use quote::quote;
229229

@@ -322,7 +322,7 @@ mod tests {
322322
discriminant_type: None,
323323
length_prefixed: false,
324324
};
325-
let err = derive_for_variants(&container_attributes, std::iter::once(&variant), &enum_name)
325+
let err = derive_for_variants(&container_attributes, iter::once(&variant), &enum_name)
326326
.unwrap_err();
327327
assert_eq!(
328328
err.to_string(),
@@ -338,7 +338,7 @@ mod tests {
338338
discriminant_type: Some(quote! { u8 }),
339339
length_prefixed: false,
340340
};
341-
let err = derive_for_variants(&container_attributes, std::iter::once(&variant), &enum_name)
341+
let err = derive_for_variants(&container_attributes, iter::once(&variant), &enum_name)
342342
.unwrap_err();
343343
assert_eq!(
344344
err.to_string(),

ssh-derive/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![crate_type = "proc-macro"]
12
#![doc = include_str!("../README.md")]
23

34
//! ## About
@@ -9,15 +10,6 @@
910
//!
1011
//! [`ssh-encoding`]: ../ssh-encoding
1112
12-
#![crate_type = "proc-macro"]
13-
#![forbid(unsafe_code)]
14-
#![warn(
15-
clippy::unwrap_used,
16-
rust_2018_idioms,
17-
trivial_casts,
18-
unused_qualifications
19-
)]
20-
2113
macro_rules! abort {
2214
( $tokens:expr, $message:expr $(,)? ) => {
2315
return Err(syn::Error::new_spanned($tokens, $message))

ssh-key/tests/private_key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ssh_key::EcdsaCurve;
99
#[cfg(feature = "alloc")]
1010
use ssh_key::LineEnding;
1111

12-
#[cfg(all(feature = "std"))]
12+
#[cfg(feature = "std")]
1313
use {
1414
ssh_key::PublicKey,
1515
std::{io, path::PathBuf, process},
@@ -685,7 +685,7 @@ fn round_trip_test(private_key: &str) -> PrivateKey {
685685
}
686686

687687
/// Parse PEM encoded using `PrivateKey::to_openssh` using the `ssh-keygen` utility.
688-
#[cfg(all(feature = "std"))]
688+
#[cfg(feature = "std")]
689689
fn encoding_integration_test(private_key: PrivateKey) {
690690
let fingerprint = private_key
691691
.fingerprint(Default::default())

ssh-key/tests/public_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn new_sk_ed25519_openssh() {
359359
assert_eq!(&sk_key, ed25519_key);
360360
}
361361

362-
#[cfg(all(feature = "alloc"))]
362+
#[cfg(feature = "alloc")]
363363
#[test]
364364
fn decode_custom_algorithm_openssh() {
365365
let key = PublicKey::from_openssh(OPENSSH_OPAQUE_EXAMPLE).unwrap();

0 commit comments

Comments
 (0)