Skip to content

Commit 91689c4

Browse files
authored
MSRV cleanup; Remove mirai-annotations dependency (#609)
* Revert MSRV violations * Remove mirai_annotations dependency * Clippy fixes * Remove unsustainable test
1 parent 9648464 commit 91689c4

File tree

13 files changed

+25
-126
lines changed

13 files changed

+25
-126
lines changed

.github/workflows/analysis.yml

-34
Original file line numberDiff line numberDiff line change
@@ -205,40 +205,6 @@ jobs:
205205
exit 0
206206
}
207207
208-
mirai-analysis:
209-
if: github.repository_owner == 'aws'
210-
runs-on: ubuntu-latest
211-
steps:
212-
- uses: actions/checkout@v3
213-
with:
214-
submodules: 'recursive'
215-
lfs: true
216-
217-
- uses: dtolnay/rust-toolchain@master
218-
id: toolchain
219-
with:
220-
toolchain: ${{ env.MIRAI_TOOLCHAIN }}
221-
components: rust-src, rustc-dev, llvm-tools-preview
222-
- name: Set Rust toolchain override
223-
run: rustup override set ${{ steps.toolchain.outputs.name }}
224-
225-
# https://github.com/facebookexperimental/MIRAI/blob/main/documentation/InstallationGuide.md#installing-mirai-into-cargo
226-
- name: Install MIRAI
227-
run: |
228-
MIRAI_TMP_SRC=$(mktemp -d)
229-
git clone --depth 1 --branch ${{ env.MIRAI_TAG }} https://github.com/facebookexperimental/MIRAI.git ${MIRAI_TMP_SRC}
230-
pushd ${MIRAI_TMP_SRC}
231-
cargo install --locked --force --path ./checker --no-default-features
232-
popd
233-
rm -rf ${MIRAI_TMP_SRC}
234-
235-
- name: Run MIRAI
236-
working-directory: ./aws-lc-rs
237-
run: |
238-
cargo update
239-
cargo update -p clap --precise 4.4.18
240-
cargo mirai
241-
242208
minimal-versions:
243209
if: github.repository_owner == 'aws'
244210
name: Resolve the dependencies to the minimum SemVer version

aws-lc-fips-sys/builder/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
// SPDX-License-Identifier: Apache-2.0 OR ISC
55

6+
// Needed until MSRV >= 1.70
7+
#![allow(clippy::unnecessary_map_or)]
68
#![allow(clippy::ref_option)]
79
// Clippy can only be run on nightly toolchain
810
#![cfg_attr(clippy, feature(custom_inner_attributes))]
@@ -550,7 +552,7 @@ fn setup_include_paths(out_dir: &Path, manifest_dir: &Path) -> PathBuf {
550552
// iterate over all the include paths and copy them into the final output
551553
for path in include_paths {
552554
for child in std::fs::read_dir(path).into_iter().flatten().flatten() {
553-
if child.file_type().is_ok_and(|t| t.is_file()) {
555+
if child.file_type().map_or(false, |t| t.is_file()) {
554556
let _ = std::fs::copy(
555557
child.path(),
556558
include_dir.join(child.path().file_name().unwrap()),

aws-lc-rs/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ untrusted = { version = "0.7.1", optional = true }
5050
aws-lc-sys = { version = "0.23.0", path = "../aws-lc-sys", optional = true }
5151
aws-lc-fips-sys = { version = "0.12.0", path = "../aws-lc-fips-sys", optional = true }
5252
zeroize = "1.7"
53-
mirai-annotations = "1.12.0"
5453
paste = "1.0.11"
5554

5655
[dev-dependencies]

aws-lc-rs/src/bn.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use crate::ptr::{ConstPointer, DetachableLcPtr, LcPtr};
55
use aws_lc::{BN_bin2bn, BN_bn2bin, BN_new, BN_num_bits, BN_num_bytes, BN_set_u64, BIGNUM};
66
use core::ptr::null_mut;
7-
use mirai_annotations::unrecoverable;
87

98
impl TryFrom<&[u8]> for LcPtr<BIGNUM> {
109
type Error = ();
@@ -56,9 +55,7 @@ impl ConstPointer<BIGNUM> {
5655
let bn_bytes = BN_num_bytes(**self);
5756
let mut byte_vec = Vec::with_capacity(bn_bytes as usize);
5857
let out_bytes = BN_bn2bin(**self, byte_vec.as_mut_ptr());
59-
if out_bytes != (bn_bytes as usize) {
60-
unrecoverable!("More bytes written than allocated.");
61-
}
58+
debug_assert_eq!(out_bytes, bn_bytes as usize);
6259
byte_vec.set_len(out_bytes);
6360
byte_vec
6461
}

aws-lc-rs/src/ptr.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use aws_lc::{
1010
RSA,
1111
};
1212

13-
use mirai_annotations::verify_unreachable;
14-
1513
pub(crate) type LcPtr<T> = ManagedPointer<*mut T>;
1614
pub(crate) type DetachableLcPtr<T> = DetachablePointer<*mut T>;
1715

@@ -100,7 +98,7 @@ impl<P: Pointer> Deref for DetachablePointer<P> {
10098
Some(pointer) => pointer,
10199
None => {
102100
// Safety: pointer is only None when DetachableLcPtr is detached or dropped
103-
verify_unreachable!()
101+
unreachable!()
104102
}
105103
}
106104
}
@@ -131,7 +129,7 @@ impl<P: Pointer> From<DetachablePointer<P>> for ManagedPointer<P> {
131129
Some(pointer) => ManagedPointer { pointer },
132130
None => {
133131
// Safety: pointer is only None when DetachableLcPtr is detached or dropped
134-
verify_unreachable!()
132+
unreachable!()
135133
}
136134
}
137135
}

aws-lc-rs/src/rsa/encryption/oaep.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use aws_lc::{
1616
EVP_PKEY_CTX, RSA_PKCS1_OAEP_PADDING,
1717
};
1818
use core::{fmt::Debug, mem::size_of_val, ptr::null_mut};
19-
use mirai_annotations::verify_unreachable;
2019

2120
/// RSA-OAEP with SHA1 Hash and SHA1 MGF1
2221
pub const OAEP_SHA1_MGF1SHA1: OaepAlgorithm = OaepAlgorithm {
@@ -163,7 +162,7 @@ impl OaepPublicEncryptingKey {
163162
EncryptionAlgorithmId::OaepSha256Mgf1sha256 => 32,
164163
EncryptionAlgorithmId::OaepSha384Mgf1sha384 => 48,
165164
EncryptionAlgorithmId::OaepSha512Mgf1sha512 => 64,
166-
_ => verify_unreachable!(),
165+
_ => unreachable!(),
167166
};
168167

169168
// The RSA-OAEP algorithms we support use the hashing algorithm for the hash and mgf1 functions.

aws-lc-rs/src/rsa/key.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use core::{
4040
// use core::ffi::c_int;
4141
use std::os::raw::c_int;
4242

43-
use mirai_annotations::verify_unreachable;
4443
#[cfg(feature = "ring-io")]
4544
use untrusted::Input;
4645
use zeroize::Zeroize;
@@ -263,7 +262,7 @@ impl KeyPair {
263262
// https://github.com/awslabs/aws-lc/blob/main/include/openssl/rsa.h#L99
264263
unsafe { RSA_size(*rsa.as_const()) as usize }
265264
}
266-
Err(_) => verify_unreachable!(),
265+
Err(_) => unreachable!(),
267266
}
268267
}
269268
}

aws-lc-rs/src/test.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112

113113
extern crate alloc;
114114

115-
use mirai_annotations::unrecoverable;
116115
use std::error::Error;
117116

118117
use crate::{digest, error};
@@ -183,7 +182,7 @@ impl TestCase {
183182
"SHA3_256" => Some(&digest::SHA3_256),
184183
"SHA3_384" => Some(&digest::SHA3_384),
185184
"SHA3_512" => Some(&digest::SHA3_512),
186-
_ => unrecoverable!("Unsupported digest algorithm: {}", name),
185+
_ => unreachable!("Unsupported digest algorithm: {}", name),
187186
}
188187
}
189188

@@ -213,20 +212,19 @@ impl TestCase {
213212
Some(b't') => b'\t',
214213
Some(b'n') => b'\n',
215214
_ => {
216-
unrecoverable!("Invalid hex escape sequence in string.");
215+
panic!("Invalid hex escape sequence in string.");
217216
}
218217
}
219218
}
220219
Some(b'"') => {
221-
if s.next().is_some() {
222-
unrecoverable!(
223-
"characters after the closing quote of a quoted string."
224-
);
225-
}
220+
assert!(
221+
s.next().is_none(),
222+
"characters after the closing quote of a quoted string."
223+
);
226224
break;
227225
}
228226
Some(b) => *b,
229-
None => unrecoverable!("Missing terminating '\"' in string literal."),
227+
None => panic!("Missing terminating '\"' in string literal."),
230228
};
231229
bytes.push(b);
232230
}
@@ -236,7 +234,7 @@ impl TestCase {
236234
match from_hex(&s) {
237235
Ok(s) => s,
238236
Err(err_str) => {
239-
unrecoverable!("{} in {}", err_str, s);
237+
panic!("{err_str} in {s}");
240238
}
241239
}
242240
};

aws-lc-rs/tests/aead_test.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use aws_lc_rs::{aead, error, test, test_file};
77

88
use aws_lc_rs::aead::{Nonce, NONCE_LEN};
99
use core::ops::RangeFrom;
10-
use mirai_annotations::unrecoverable;
1110

1211
#[test]
1312
fn aead_aes_gcm_128() {
@@ -230,7 +229,7 @@ fn test_aead<Seal, Open>(
230229
assert_eq!(Err(error::Unspecified), o_result);
231230
}
232231
Some(error) => {
233-
unrecoverable!("Unexpected error test case: {}", error);
232+
panic!("Unexpected error test case: {error}");
234233
}
235234
};
236235
}

aws-lc-rs/tests/ecdsa_tests.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use aws_lc_rs::{
1010
signature::{self, EcdsaKeyPair, KeyPair, Signature, UnparsedPublicKey},
1111
test, test_file,
1212
};
13-
use mirai_annotations::unrecoverable;
1413

1514
#[test]
1615
fn ecdsa_traits() {
@@ -93,9 +92,9 @@ fn ecdsa_from_pkcs8_test() {
9392
match (EcdsaKeyPair::from_pkcs8(this_asn1, &input), error) {
9493
(Ok(_), None) => (),
9594
(Err(e), None) => {
96-
unrecoverable!("Failed with error \"{}\", but expected to succeed", e);
95+
panic!("Failed with error \"{e}\", but expected to succeed");
9796
}
98-
(Ok(_), Some(e)) => unrecoverable!("Succeeded, but expected error \"{}\"", e),
97+
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{e}\""),
9998
(Err(actual), Some(expected)) => assert_eq!(format!("{actual}"), expected),
10099
};
101100

@@ -230,7 +229,7 @@ fn test_signature_ecdsa_verify_fixed(data_file: test::File) {
230229
("secp256k1", "SHA256") => &signature::ECDSA_P256K1_SHA256_FIXED,
231230
("secp256k1", "SHA3-256") => &signature::ECDSA_P256K1_SHA3_256_FIXED,
232231
_ => {
233-
unrecoverable!("Unsupported curve+digest: {}+{}", curve_name, digest_name);
232+
panic!("Unsupported curve+digest: {curve_name}+{digest_name}");
234233
}
235234
};
236235

aws-lc-rs/tests/pbkdf2_test.rs

-60
Original file line numberDiff line numberDiff line change
@@ -52,63 +52,3 @@ fn pbkdf2_tests() {
5252
Ok(())
5353
});
5454
}
55-
56-
/// The API documentation specifies that derive/verify should panic, if the designated output length
57-
/// is too long. Ring checks for an output array length while pbkdf2 is being ran, while we check
58-
/// the array length before everything is processed.
59-
/// Most platforms will fail to allocate this much memory, so we only test on platforms which can.
60-
#[cfg(all(target_arch = "x86_64", target_vendor = "apple"))]
61-
#[cfg(test)]
62-
mod tests {
63-
use aws_lc_rs::{digest, pbkdf2};
64-
use core::num::NonZeroU32;
65-
use mirai_annotations::assume;
66-
67-
#[test]
68-
#[should_panic(expected = "derived key too long")]
69-
fn pbkdf2_derive_too_long() {
70-
let iterations = NonZeroU32::new(1_u32).unwrap();
71-
let max_usize32 = u32::MAX as usize;
72-
for &alg in &[
73-
pbkdf2::PBKDF2_HMAC_SHA1,
74-
pbkdf2::PBKDF2_HMAC_SHA256,
75-
pbkdf2::PBKDF2_HMAC_SHA384,
76-
pbkdf2::PBKDF2_HMAC_SHA512,
77-
] {
78-
let output_len = match_pbkdf2_digest(&alg).output_len;
79-
assume!(output_len < 2048);
80-
let mut out = vec![0u8; max_usize32 * output_len + 1];
81-
pbkdf2::derive(alg, iterations, b"salt", b"password", &mut out);
82-
}
83-
}
84-
85-
#[test]
86-
#[should_panic(expected = "derived key too long")]
87-
fn pbkdf2_verify_too_long() {
88-
let iterations = NonZeroU32::new(1_u32).unwrap();
89-
let max_usize32 = u32::MAX as usize;
90-
for &alg in &[
91-
pbkdf2::PBKDF2_HMAC_SHA1,
92-
pbkdf2::PBKDF2_HMAC_SHA256,
93-
pbkdf2::PBKDF2_HMAC_SHA384,
94-
pbkdf2::PBKDF2_HMAC_SHA512,
95-
] {
96-
let out = vec![0u8; max_usize32 * match_pbkdf2_digest(&alg).output_len + 1];
97-
pbkdf2::verify(alg, iterations, b"salt", b"password", &out).unwrap();
98-
}
99-
}
100-
101-
fn match_pbkdf2_digest(&algorithm: &pbkdf2::Algorithm) -> &digest::Algorithm {
102-
if algorithm == pbkdf2::PBKDF2_HMAC_SHA1 {
103-
&digest::SHA1_FOR_LEGACY_USE_ONLY
104-
} else if algorithm == pbkdf2::PBKDF2_HMAC_SHA256 {
105-
&digest::SHA256
106-
} else if algorithm == pbkdf2::PBKDF2_HMAC_SHA384 {
107-
&digest::SHA384
108-
} else if algorithm == pbkdf2::PBKDF2_HMAC_SHA512 {
109-
&digest::SHA512
110-
} else {
111-
unreachable!()
112-
}
113-
}
114-
}

aws-lc-sys/builder/cc_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl CcBuilder {
227227
let source_path = self.manifest_dir.join("aws-lc").join(source);
228228
let is_asm = std::path::Path::new(source)
229229
.extension()
230-
.is_some_and(|ext| ext.eq("S"));
230+
.map_or(false, |ext| ext.eq("S"));
231231
if is_asm && target_vendor() == "apple" && target_arch() == "aarch64" {
232232
let mut cc_preprocessor = self.create_builder();
233233
cc_preprocessor.file(source_path);

aws-lc-sys/builder/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
// SPDX-License-Identifier: Apache-2.0 OR ISC
55

6+
// Needed until MSRV >= 1.70
7+
#![allow(clippy::unnecessary_map_or)]
68
#![allow(clippy::ref_option)]
79
// Clippy can only be run on nightly toolchain
810
#![cfg_attr(clippy, feature(custom_inner_attributes))]
@@ -481,6 +483,7 @@ fn is_no_asm() -> bool {
481483
unsafe { AWS_LC_SYS_NO_ASM }
482484
}
483485

486+
#[allow(unknown_lints)]
484487
#[allow(static_mut_refs)]
485488
fn get_cflags() -> &'static str {
486489
unsafe { AWS_LC_SYS_CFLAGS.as_str() }
@@ -656,7 +659,7 @@ fn setup_include_paths(out_dir: &Path, manifest_dir: &Path) -> PathBuf {
656659
// iterate over all the include paths and copy them into the final output
657660
for path in include_paths {
658661
for child in std::fs::read_dir(path).into_iter().flatten().flatten() {
659-
if child.file_type().is_ok_and(|t| t.is_file()) {
662+
if child.file_type().map_or(false, |t| t.is_file()) {
660663
let _ = std::fs::copy(
661664
child.path(),
662665
include_dir.join(child.path().file_name().unwrap()),

0 commit comments

Comments
 (0)