Skip to content

Code improvements suggested by Clippy 1.85. #326

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

Merged
merged 5 commits into from
Mar 18, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
rust: [1.73.0, stable, beta, nightly]
rust: [1.81.0, stable, beta, nightly]
steps:
- name: Checkout repository
uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rpki"
version = "0.18.5"
edition = "2021"
rust-version = "1.73"
rust-version = "1.81"
authors = ["NLnet Labs <[email protected]>"]
description = "A library for validating and creating RPKI data."
documentation = "https://docs.rs/rpki/"
Expand Down
22 changes: 18 additions & 4 deletions src/repository/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,12 @@ impl ManifestHash {
&self,
t: T
) -> Result<(), ManifestHashMismatch> {
ring::constant_time::verify_slices_are_equal(
self.hash.as_ref(),
self.algorithm.digest(t.as_ref()).as_ref()
).map_err(|_| ManifestHashMismatch(()))
if self.hash.as_ref() != self.algorithm.digest(t.as_ref()).as_ref() {
Err(ManifestHashMismatch(()))
}
else {
Ok(())
}
}

/// Returns the digest algorithm of the hash.
Expand Down Expand Up @@ -546,6 +548,18 @@ mod test {
assert!(obj.validate_at(&issuer, false, at).is_err());
}

#[test]
fn verify_manifest_hash() {
let alg = DigestAlgorithm::sha256();
let hash = ManifestHash::new(
Bytes::copy_from_slice(alg.digest(b"foobar").as_ref()),
alg
);

assert!(hash.verify(b"foobar").is_ok());
assert!(hash.verify(b"barfoo").is_err());
}

#[test]
#[cfg(feature = "serde")]
fn compat_de_manifest() {
Expand Down
6 changes: 3 additions & 3 deletions src/repository/resources/choice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// An enum offering the choice between inherited and included resources.
///
/// This is a private module used only internally.
//! An enum offering the choice between inherited and included resources.
//!
//! This is a private module used only internally.

use std::fmt;

Expand Down
2 changes: 1 addition & 1 deletion src/repository/sigobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl SignedObject {
) -> Result<ResourceCert, ValidationError> {
self.inspect(strict)?;
self.verify(strict)?;
self.cert.validate_ee_at(issuer, strict, now).map_err(Into::into)
self.cert.validate_ee_at(issuer, strict, now)
}

/// Validates that the signed object complies with the specification.
Expand Down
2 changes: 1 addition & 1 deletion src/resources/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ mod test {

assert_eq!(
Ipv4Addr::from(Bits::from(
(192u128 << 24 | (168 << 16) | (10 << 8) | 20) << 96
((192u128 << 24) | (168 << 16) | (10 << 8) | 20) << 96
)),
Ipv4Addr::new(192, 168, 10, 20),
);
Expand Down
2 changes: 1 addition & 1 deletion src/rrdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ impl str::FromStr for Hash {
)?.to_digit(16).ok_or(
ParseHashError::BAD_CHARS
)?;
*octet = (first << 4 | second) as u8;
*octet = ((first << 4) | second) as u8;
}
Ok(Hash(res))
}
Expand Down
26 changes: 13 additions & 13 deletions src/rtr/pdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ macro_rules! concrete {

/// A serial notify informs a client that a cache has new data.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
#[allow(dead_code)]
pub struct SerialNotify {
header: Header,
Expand Down Expand Up @@ -211,7 +211,7 @@ concrete!(SerialNotify);

/// A serial query requests all updates since a router’s last update.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
#[allow(dead_code)]
pub struct SerialQuery {
header: Header,
Expand Down Expand Up @@ -242,7 +242,7 @@ concrete!(SerialQuery);
///
/// This the serial query PDU without the header.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
pub struct SerialQueryPayload {
serial: u32
}
Expand Down Expand Up @@ -277,7 +277,7 @@ common!(SerialQueryPayload);

/// A reset query requests the complete current set of data.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
pub struct ResetQuery {
header: Header
}
Expand All @@ -301,7 +301,7 @@ concrete!(ResetQuery);

/// The cache response starts a sequence of payload PDUs with data.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
pub struct CacheResponse {
header: Header
}
Expand All @@ -325,7 +325,7 @@ concrete!(CacheResponse);

/// An IPv4 prefix is the payload PDU for route origin authorisation in IPv4.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
#[allow(dead_code)]
pub struct Ipv4Prefix {
header: Header,
Expand Down Expand Up @@ -397,7 +397,7 @@ concrete!(Ipv4Prefix);

/// An IPv6 prefix is the payload PDU for route origin authorisation in IPv6.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
#[allow(dead_code)]
pub struct Ipv6Prefix {
header: Header,
Expand Down Expand Up @@ -475,7 +475,7 @@ pub struct RouterKey {
}

#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
struct RouterKeyFixed {
header: Header,
key_identifier: [u8; 20],
Expand Down Expand Up @@ -784,7 +784,7 @@ pub struct Aspa {
}

#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
struct AspaFixed {
header: Header,
customer: u32,
Expand Down Expand Up @@ -1394,7 +1394,7 @@ impl AsMut<[u8]> for EndOfData {
///
/// This type is the version used in protocol version 0.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
pub struct EndOfDataV0 {
header: Header,
serial: u32
Expand Down Expand Up @@ -1427,7 +1427,7 @@ concrete!(EndOfDataV0);
///
/// This type is the version used beginning with protocol version 1.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
pub struct EndOfDataV1 {
header: Header,
serial: u32,
Expand Down Expand Up @@ -1481,7 +1481,7 @@ concrete!(EndOfDataV1);
/// serial number indicated in the serial query, it responds with a cache
/// reset.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
pub struct CacheReset {
header: Header
}
Expand Down Expand Up @@ -1595,7 +1595,7 @@ impl AsMut<[u8]> for Error {

/// The header portion of an RTR PDU.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(packed)]
#[repr(C, packed)]
pub struct Header {
/// The version of the PDU.
version: u8,
Expand Down