From 07495564727ec693575bf4a2cf548047cf580779 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 20 Nov 2024 18:03:57 -0500 Subject: [PATCH] Remove mirai_annotations dependency --- .github/workflows/analysis.yml | 34 ---------------------------- aws-lc-rs/Cargo.toml | 1 - aws-lc-rs/src/bn.rs | 5 +--- aws-lc-rs/src/ptr.rs | 6 ++--- aws-lc-rs/src/rsa/encryption/oaep.rs | 3 +-- aws-lc-rs/src/rsa/key.rs | 3 +-- aws-lc-rs/src/test.rs | 13 ++++------- aws-lc-rs/tests/aead_test.rs | 3 +-- aws-lc-rs/tests/ecdsa_tests.rs | 7 +++--- 9 files changed, 14 insertions(+), 61 deletions(-) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 3012055557b..2920c632f7f 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -205,40 +205,6 @@ jobs: exit 0 } - mirai-analysis: - if: github.repository_owner == 'aws' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - lfs: true - - - uses: dtolnay/rust-toolchain@master - id: toolchain - with: - toolchain: ${{ env.MIRAI_TOOLCHAIN }} - components: rust-src, rustc-dev, llvm-tools-preview - - name: Set Rust toolchain override - run: rustup override set ${{ steps.toolchain.outputs.name }} - - # https://github.com/facebookexperimental/MIRAI/blob/main/documentation/InstallationGuide.md#installing-mirai-into-cargo - - name: Install MIRAI - run: | - MIRAI_TMP_SRC=$(mktemp -d) - git clone --depth 1 --branch ${{ env.MIRAI_TAG }} https://github.com/facebookexperimental/MIRAI.git ${MIRAI_TMP_SRC} - pushd ${MIRAI_TMP_SRC} - cargo install --locked --force --path ./checker --no-default-features - popd - rm -rf ${MIRAI_TMP_SRC} - - - name: Run MIRAI - working-directory: ./aws-lc-rs - run: | - cargo update - cargo update -p clap --precise 4.4.18 - cargo mirai - minimal-versions: if: github.repository_owner == 'aws' name: Resolve the dependencies to the minimum SemVer version diff --git a/aws-lc-rs/Cargo.toml b/aws-lc-rs/Cargo.toml index 5ea2e0e1095..66dfd2fb1b5 100644 --- a/aws-lc-rs/Cargo.toml +++ b/aws-lc-rs/Cargo.toml @@ -50,7 +50,6 @@ untrusted = { version = "0.7.1", optional = true } aws-lc-sys = { version = "0.23.0", path = "../aws-lc-sys", optional = true } aws-lc-fips-sys = { version = "0.12.0", path = "../aws-lc-fips-sys", optional = true } zeroize = "1.7" -mirai-annotations = "1.12.0" paste = "1.0.11" [dev-dependencies] diff --git a/aws-lc-rs/src/bn.rs b/aws-lc-rs/src/bn.rs index 7deef7bda4a..b00cf263f29 100644 --- a/aws-lc-rs/src/bn.rs +++ b/aws-lc-rs/src/bn.rs @@ -4,7 +4,6 @@ use crate::ptr::{ConstPointer, DetachableLcPtr, LcPtr}; use aws_lc::{BN_bin2bn, BN_bn2bin, BN_new, BN_num_bits, BN_num_bytes, BN_set_u64, BIGNUM}; use core::ptr::null_mut; -use mirai_annotations::unrecoverable; impl TryFrom<&[u8]> for LcPtr { type Error = (); @@ -56,9 +55,7 @@ impl ConstPointer { let bn_bytes = BN_num_bytes(**self); let mut byte_vec = Vec::with_capacity(bn_bytes as usize); let out_bytes = BN_bn2bin(**self, byte_vec.as_mut_ptr()); - if out_bytes != (bn_bytes as usize) { - unrecoverable!("More bytes written than allocated."); - } + debug_assert_eq!(out_bytes, bn_bytes as usize); byte_vec.set_len(out_bytes); byte_vec } diff --git a/aws-lc-rs/src/ptr.rs b/aws-lc-rs/src/ptr.rs index d6063e5edb6..f0b146adb3f 100644 --- a/aws-lc-rs/src/ptr.rs +++ b/aws-lc-rs/src/ptr.rs @@ -10,8 +10,6 @@ use aws_lc::{ RSA, }; -use mirai_annotations::verify_unreachable; - pub(crate) type LcPtr = ManagedPointer<*mut T>; pub(crate) type DetachableLcPtr = DetachablePointer<*mut T>; @@ -100,7 +98,7 @@ impl Deref for DetachablePointer

{ Some(pointer) => pointer, None => { // Safety: pointer is only None when DetachableLcPtr is detached or dropped - verify_unreachable!() + unreachable!() } } } @@ -131,7 +129,7 @@ impl From> for ManagedPointer

{ Some(pointer) => ManagedPointer { pointer }, None => { // Safety: pointer is only None when DetachableLcPtr is detached or dropped - verify_unreachable!() + unreachable!() } } } diff --git a/aws-lc-rs/src/rsa/encryption/oaep.rs b/aws-lc-rs/src/rsa/encryption/oaep.rs index 45d4e723a71..4f8184cbfb7 100644 --- a/aws-lc-rs/src/rsa/encryption/oaep.rs +++ b/aws-lc-rs/src/rsa/encryption/oaep.rs @@ -16,7 +16,6 @@ use aws_lc::{ EVP_PKEY_CTX, RSA_PKCS1_OAEP_PADDING, }; use core::{fmt::Debug, mem::size_of_val, ptr::null_mut}; -use mirai_annotations::verify_unreachable; /// RSA-OAEP with SHA1 Hash and SHA1 MGF1 pub const OAEP_SHA1_MGF1SHA1: OaepAlgorithm = OaepAlgorithm { @@ -163,7 +162,7 @@ impl OaepPublicEncryptingKey { EncryptionAlgorithmId::OaepSha256Mgf1sha256 => 32, EncryptionAlgorithmId::OaepSha384Mgf1sha384 => 48, EncryptionAlgorithmId::OaepSha512Mgf1sha512 => 64, - _ => verify_unreachable!(), + _ => unreachable!(), }; // The RSA-OAEP algorithms we support use the hashing algorithm for the hash and mgf1 functions. diff --git a/aws-lc-rs/src/rsa/key.rs b/aws-lc-rs/src/rsa/key.rs index be8d8b14bb4..0372d8343a6 100644 --- a/aws-lc-rs/src/rsa/key.rs +++ b/aws-lc-rs/src/rsa/key.rs @@ -40,7 +40,6 @@ use core::{ // use core::ffi::c_int; use std::os::raw::c_int; -use mirai_annotations::verify_unreachable; #[cfg(feature = "ring-io")] use untrusted::Input; use zeroize::Zeroize; @@ -263,7 +262,7 @@ impl KeyPair { // https://github.com/awslabs/aws-lc/blob/main/include/openssl/rsa.h#L99 unsafe { RSA_size(*rsa.as_const()) as usize } } - Err(_) => verify_unreachable!(), + Err(_) => unreachable!(), } } } diff --git a/aws-lc-rs/src/test.rs b/aws-lc-rs/src/test.rs index 735eb33a511..995a674cd3f 100644 --- a/aws-lc-rs/src/test.rs +++ b/aws-lc-rs/src/test.rs @@ -112,7 +112,6 @@ extern crate alloc; -use mirai_annotations::unrecoverable; use std::error::Error; use crate::{digest, error}; @@ -183,7 +182,7 @@ impl TestCase { "SHA3_256" => Some(&digest::SHA3_256), "SHA3_384" => Some(&digest::SHA3_384), "SHA3_512" => Some(&digest::SHA3_512), - _ => unrecoverable!("Unsupported digest algorithm: {}", name), + _ => unreachable!("Unsupported digest algorithm: {}", name), } } @@ -213,20 +212,18 @@ impl TestCase { Some(b't') => b'\t', Some(b'n') => b'\n', _ => { - unrecoverable!("Invalid hex escape sequence in string."); + panic!("Invalid hex escape sequence in string."); } } } Some(b'"') => { if s.next().is_some() { - unrecoverable!( - "characters after the closing quote of a quoted string." - ); + panic!("characters after the closing quote of a quoted string."); } break; } Some(b) => *b, - None => unrecoverable!("Missing terminating '\"' in string literal."), + None => panic!("Missing terminating '\"' in string literal."), }; bytes.push(b); } @@ -236,7 +233,7 @@ impl TestCase { match from_hex(&s) { Ok(s) => s, Err(err_str) => { - unrecoverable!("{} in {}", err_str, s); + panic!("{} in {}", err_str, s); } } }; diff --git a/aws-lc-rs/tests/aead_test.rs b/aws-lc-rs/tests/aead_test.rs index 05e67d4a8a7..f55cf3c45c9 100644 --- a/aws-lc-rs/tests/aead_test.rs +++ b/aws-lc-rs/tests/aead_test.rs @@ -7,7 +7,6 @@ use aws_lc_rs::{aead, error, test, test_file}; use aws_lc_rs::aead::{Nonce, NONCE_LEN}; use core::ops::RangeFrom; -use mirai_annotations::unrecoverable; #[test] fn aead_aes_gcm_128() { @@ -230,7 +229,7 @@ fn test_aead( assert_eq!(Err(error::Unspecified), o_result); } Some(error) => { - unrecoverable!("Unexpected error test case: {}", error); + panic!("Unexpected error test case: {}", error); } }; } diff --git a/aws-lc-rs/tests/ecdsa_tests.rs b/aws-lc-rs/tests/ecdsa_tests.rs index 66c8308d434..7d783030b1e 100644 --- a/aws-lc-rs/tests/ecdsa_tests.rs +++ b/aws-lc-rs/tests/ecdsa_tests.rs @@ -10,7 +10,6 @@ use aws_lc_rs::{ signature::{self, EcdsaKeyPair, KeyPair, Signature, UnparsedPublicKey}, test, test_file, }; -use mirai_annotations::unrecoverable; #[test] fn ecdsa_traits() { @@ -93,9 +92,9 @@ fn ecdsa_from_pkcs8_test() { match (EcdsaKeyPair::from_pkcs8(this_asn1, &input), error) { (Ok(_), None) => (), (Err(e), None) => { - unrecoverable!("Failed with error \"{}\", but expected to succeed", e); + panic!("Failed with error \"{}\", but expected to succeed", e); } - (Ok(_), Some(e)) => unrecoverable!("Succeeded, but expected error \"{}\"", e), + (Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e), (Err(actual), Some(expected)) => assert_eq!(format!("{actual}"), expected), }; @@ -230,7 +229,7 @@ fn test_signature_ecdsa_verify_fixed(data_file: test::File) { ("secp256k1", "SHA256") => &signature::ECDSA_P256K1_SHA256_FIXED, ("secp256k1", "SHA3-256") => &signature::ECDSA_P256K1_SHA3_256_FIXED, _ => { - unrecoverable!("Unsupported curve+digest: {}+{}", curve_name, digest_name); + panic!("Unsupported curve+digest: {}+{}", curve_name, digest_name); } };