Skip to content

Commit 23685fb

Browse files
authored
Various code impovements with MSRV now 1.81. (#326)
1 parent 3cbda55 commit 23685fb

File tree

8 files changed

+39
-25
lines changed

8 files changed

+39
-25
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
os: [ubuntu-latest, windows-latest, macOS-latest]
10-
rust: [1.73.0, stable, beta, nightly]
10+
rust: [1.81.0, stable, beta, nightly]
1111
steps:
1212
- name: Checkout repository
1313
uses: actions/checkout@v1

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rpki"
33
version = "0.18.5"
44
edition = "2021"
5-
rust-version = "1.73"
5+
rust-version = "1.81"
66
authors = ["NLnet Labs <[email protected]>"]
77
description = "A library for validating and creating RPKI data."
88
documentation = "https://docs.rs/rpki/"

src/repository/manifest.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,12 @@ impl ManifestHash {
482482
&self,
483483
t: T
484484
) -> Result<(), ManifestHashMismatch> {
485-
ring::constant_time::verify_slices_are_equal(
486-
self.hash.as_ref(),
487-
self.algorithm.digest(t.as_ref()).as_ref()
488-
).map_err(|_| ManifestHashMismatch(()))
485+
if self.hash.as_ref() != self.algorithm.digest(t.as_ref()).as_ref() {
486+
Err(ManifestHashMismatch(()))
487+
}
488+
else {
489+
Ok(())
490+
}
489491
}
490492

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

551+
#[test]
552+
fn verify_manifest_hash() {
553+
let alg = DigestAlgorithm::sha256();
554+
let hash = ManifestHash::new(
555+
Bytes::copy_from_slice(alg.digest(b"foobar").as_ref()),
556+
alg
557+
);
558+
559+
assert!(hash.verify(b"foobar").is_ok());
560+
assert!(hash.verify(b"barfoo").is_err());
561+
}
562+
549563
#[test]
550564
#[cfg(feature = "serde")]
551565
fn compat_de_manifest() {

src/repository/resources/choice.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/// An enum offering the choice between inherited and included resources.
2-
///
3-
/// This is a private module used only internally.
1+
//! An enum offering the choice between inherited and included resources.
2+
//!
3+
//! This is a private module used only internally.
44
55
use std::fmt;
66

src/repository/sigobj.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl SignedObject {
231231
) -> Result<ResourceCert, ValidationError> {
232232
self.inspect(strict)?;
233233
self.verify(strict)?;
234-
self.cert.validate_ee_at(issuer, strict, now).map_err(Into::into)
234+
self.cert.validate_ee_at(issuer, strict, now)
235235
}
236236

237237
/// Validates that the signed object complies with the specification.

src/resources/addr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ mod test {
950950

951951
assert_eq!(
952952
Ipv4Addr::from(Bits::from(
953-
(192u128 << 24 | (168 << 16) | (10 << 8) | 20) << 96
953+
((192u128 << 24) | (168 << 16) | (10 << 8) | 20) << 96
954954
)),
955955
Ipv4Addr::new(192, 168, 10, 20),
956956
);

src/rrdp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ impl str::FromStr for Hash {
13681368
)?.to_digit(16).ok_or(
13691369
ParseHashError::BAD_CHARS
13701370
)?;
1371-
*octet = (first << 4 | second) as u8;
1371+
*octet = ((first << 4) | second) as u8;
13721372
}
13731373
Ok(Hash(res))
13741374
}

src/rtr/pdu.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ macro_rules! concrete {
182182

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

212212
/// A serial query requests all updates since a router’s last update.
213213
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
214-
#[repr(packed)]
214+
#[repr(C, packed)]
215215
#[allow(dead_code)]
216216
pub struct SerialQuery {
217217
header: Header,
@@ -242,7 +242,7 @@ concrete!(SerialQuery);
242242
///
243243
/// This the serial query PDU without the header.
244244
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
245-
#[repr(packed)]
245+
#[repr(C, packed)]
246246
pub struct SerialQueryPayload {
247247
serial: u32
248248
}
@@ -277,7 +277,7 @@ common!(SerialQueryPayload);
277277

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

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

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

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

477477
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
478-
#[repr(packed)]
478+
#[repr(C, packed)]
479479
struct RouterKeyFixed {
480480
header: Header,
481481
key_identifier: [u8; 20],
@@ -784,7 +784,7 @@ pub struct Aspa {
784784
}
785785

786786
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
787-
#[repr(packed)]
787+
#[repr(C, packed)]
788788
struct AspaFixed {
789789
header: Header,
790790
customer: u32,
@@ -1394,7 +1394,7 @@ impl AsMut<[u8]> for EndOfData {
13941394
///
13951395
/// This type is the version used in protocol version 0.
13961396
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
1397-
#[repr(packed)]
1397+
#[repr(C, packed)]
13981398
pub struct EndOfDataV0 {
13991399
header: Header,
14001400
serial: u32
@@ -1427,7 +1427,7 @@ concrete!(EndOfDataV0);
14271427
///
14281428
/// This type is the version used beginning with protocol version 1.
14291429
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
1430-
#[repr(packed)]
1430+
#[repr(C, packed)]
14311431
pub struct EndOfDataV1 {
14321432
header: Header,
14331433
serial: u32,
@@ -1481,7 +1481,7 @@ concrete!(EndOfDataV1);
14811481
/// serial number indicated in the serial query, it responds with a cache
14821482
/// reset.
14831483
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
1484-
#[repr(packed)]
1484+
#[repr(C, packed)]
14851485
pub struct CacheReset {
14861486
header: Header
14871487
}
@@ -1595,7 +1595,7 @@ impl AsMut<[u8]> for Error {
15951595

15961596
/// The header portion of an RTR PDU.
15971597
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
1598-
#[repr(packed)]
1598+
#[repr(C, packed)]
15991599
pub struct Header {
16001600
/// The version of the PDU.
16011601
version: u8,

0 commit comments

Comments
 (0)