Skip to content

Commit

Permalink
Trivial RustRover cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed May 7, 2024
1 parent 9aec497 commit eebbafa
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 86 deletions.
2 changes: 1 addition & 1 deletion aws-lc-rs-testing/benches/kem_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn bench_kem_keygen(c: &mut Criterion) {
let mut group = c.benchmark_group(bench_group_name);
group.bench_function("AWS-LC", |b| {
b.iter(|| {
aws_lc_rs::kem::DecapsulationKey::generate(ele).unwrap();
DecapsulationKey::generate(ele).unwrap();
});
});
}
Expand Down
48 changes: 24 additions & 24 deletions aws-lc-rs/src/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,12 @@ mod tests {
use crate::encoding::{
AsBigEndian, AsDer, Curve25519SeedBin, EcPrivateKeyBin, EcPrivateKeyRfc5915Der,
};
use crate::{agreement, rand, test};
use crate::{rand, test};

#[test]
fn test_agreement_x25519() {
let alg = &agreement::X25519;
let peer_public = agreement::UnparsedPublicKey::new(
let alg = &X25519;
let peer_public = UnparsedPublicKey::new(
alg,
test::from_dirty_hex(
"e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c",
Expand Down Expand Up @@ -803,7 +803,7 @@ mod tests {
let be_private_key =
PrivateKey::from_private_key(&X25519, be_private_key_buffer.as_ref()).unwrap();
{
let result = agreement::agree(&be_private_key, &peer_public, (), |key_material| {
let result = agree(&be_private_key, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -815,14 +815,14 @@ mod tests {

assert_eq!(computed_public.algorithm(), alg);
{
let result = agreement::agree(&my_private, &peer_public, (), |key_material| {
let result = agree(&my_private, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
assert_eq!(result, Ok(()));
}
{
let result = agreement::agree(&my_private, &peer_public, (), |key_material| {
let result = agree(&my_private, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand Down Expand Up @@ -862,8 +862,8 @@ mod tests {

#[test]
fn test_agreement_ecdh_p256() {
let alg = &agreement::ECDH_P256;
let peer_public = agreement::UnparsedPublicKey::new(
let alg = &ECDH_P256;
let peer_public = UnparsedPublicKey::new(
alg,
test::from_dirty_hex(
"04D12DFB5289C8D4F81208B70270398C342296970A0BCCB74C736FC7554494BF6356FBF3CA366CC23E8157854C13C58D6AAC23F046ADA30F8353E74F33039872AB",
Expand Down Expand Up @@ -894,7 +894,7 @@ mod tests {
let be_private_key =
PrivateKey::from_private_key(&ECDH_P256, be_private_key_buffer.as_ref()).unwrap();
{
let result = agreement::agree(&be_private_key, &peer_public, (), |key_material| {
let result = agree(&be_private_key, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -905,7 +905,7 @@ mod tests {
let der_private_key =
PrivateKey::from_private_key_der(&ECDH_P256, der_private_key_buffer.as_ref()).unwrap();
{
let result = agreement::agree(&der_private_key, &peer_public, (), |key_material| {
let result = agree(&der_private_key, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -918,15 +918,15 @@ mod tests {
assert_eq!(computed_public.algorithm(), alg);

{
let result = agreement::agree(&my_private, &peer_public, (), |key_material| {
let result = agree(&my_private, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
assert_eq!(result, Ok(()));
}

{
let result = agreement::agree(&my_private, &peer_public, (), |key_material| {
let result = agree(&my_private, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -936,8 +936,8 @@ mod tests {

#[test]
fn test_agreement_ecdh_p384() {
let alg = &agreement::ECDH_P384;
let peer_public = agreement::UnparsedPublicKey::new(
let alg = &ECDH_P384;
let peer_public = UnparsedPublicKey::new(
alg,
test::from_dirty_hex(
"04E558DBEF53EECDE3D3FCCFC1AEA08A89A987475D12FD950D83CFA41732BC509D0D1AC43A0336DEF96FDA41D0774A3571DCFBEC7AACF3196472169E838430367F66EEBE3C6E70C416DD5F0C68759DD1FFF83FA40142209DFF5EAAD96DB9E6386C",
Expand Down Expand Up @@ -966,7 +966,7 @@ mod tests {
let be_private_key =
PrivateKey::from_private_key(&ECDH_P384, be_private_key_buffer.as_ref()).unwrap();
{
let result = agreement::agree(&be_private_key, &peer_public, (), |key_material| {
let result = agree(&be_private_key, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -977,7 +977,7 @@ mod tests {
let der_private_key =
PrivateKey::from_private_key_der(&ECDH_P384, der_private_key_buffer.as_ref()).unwrap();
{
let result = agreement::agree(&der_private_key, &peer_public, (), |key_material| {
let result = agree(&der_private_key, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -990,7 +990,7 @@ mod tests {
assert_eq!(computed_public.algorithm(), alg);

{
let result = agreement::agree(&my_private, &peer_public, (), |key_material| {
let result = agree(&my_private, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -1000,8 +1000,8 @@ mod tests {

#[test]
fn test_agreement_ecdh_p521() {
let alg = &agreement::ECDH_P521;
let peer_public = agreement::UnparsedPublicKey::new(
let alg = &ECDH_P521;
let peer_public = UnparsedPublicKey::new(
alg,
test::from_dirty_hex(
"0401a32099b02c0bd85371f60b0dd20890e6c7af048c8179890fda308b359dbbc2b7a832bb8c6526c4af99a7ea3f0b3cb96ae1eb7684132795c478ad6f962e4a6f446d017627357b39e9d7632a1370b3e93c1afb5c851b910eb4ead0c9d387df67cde85003e0e427552f1cd09059aad0262e235cce5fba8cedc4fdc1463da76dcd4b6d1a46",
Expand All @@ -1014,7 +1014,7 @@ mod tests {

let my_private = {
let rng = test::rand::FixedSliceRandom { bytes: &my_private };
agreement::PrivateKey::generate_for_test(alg, &rng).unwrap()
PrivateKey::generate_for_test(alg, &rng).unwrap()
};

let my_public = test::from_dirty_hex(
Expand All @@ -1030,7 +1030,7 @@ mod tests {
let be_private_key =
PrivateKey::from_private_key(&ECDH_P521, be_private_key_buffer.as_ref()).unwrap();
{
let result = agreement::agree(&be_private_key, &peer_public, (), |key_material| {
let result = agree(&be_private_key, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -1041,7 +1041,7 @@ mod tests {
let der_private_key =
PrivateKey::from_private_key_der(&ECDH_P521, der_private_key_buffer.as_ref()).unwrap();
{
let result = agreement::agree(&der_private_key, &peer_public, (), |key_material| {
let result = agree(&der_private_key, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand All @@ -1053,14 +1053,14 @@ mod tests {

assert_eq!(computed_public.algorithm(), alg);
{
let result = agreement::agree(&my_private, &peer_public, (), |key_material| {
let result = agree(&my_private, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
assert_eq!(result, Ok(()));
}
{
let result = agreement::agree(&my_private, &peer_public, (), |key_material| {
let result = agree(&my_private, &peer_public, (), |key_material| {
assert_eq!(key_material, &output[..]);
Ok(())
});
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/cipher/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod tests {

for alignment in 0..=MAX_ALIGNMENT {
buf[..alignment].fill(ARBITRARY);
let buf = &mut buf[..(input.len())];
let buf = &mut buf[..input.len()];
buf.copy_from_slice(input);
let nonce = &nonce;

Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ mod tests {
digest::Context {
algorithm: alg,
digest_ctx: DigestContext::new(alg).unwrap(),
msg_len: (alg.max_input_len - block_len + 1),
msg_len: alg.max_input_len - block_len + 1,
max_input_reached: false,
}
}
Expand Down
7 changes: 2 additions & 5 deletions aws-lc-rs/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,9 @@ fn ecdsa_asn1_to_fixed(alg_id: &'static AlgorithmID, sig: &[u8]) -> Result<Signa
let s_buffer = s_bn.to_be_bytes();

Ok(Signature::new(|slice| {
let (r_start, r_end) = (
(expected_number_size - r_buffer.len()),
expected_number_size,
);
let (r_start, r_end) = (expected_number_size - r_buffer.len(), expected_number_size);
let (s_start, s_end) = (
(2 * expected_number_size - s_buffer.len()),
2 * expected_number_size - s_buffer.len(),
2 * expected_number_size,
);

Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ mod tests {

#[test]
fn std_error() {
let key_rejected = super::KeyRejected::wrong_algorithm();
let key_rejected = KeyRejected::wrong_algorithm();
assert!(key_rejected.cause().is_none());
assert_eq!("WrongAlgorithm", key_rejected.description());

Expand Down
6 changes: 3 additions & 3 deletions aws-lc-rs/src/fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ pub(crate) mod indicator {
}

pub fn set_approved() {
STATUS_INDICATOR.with(|v| v.set(Some(true)));
STATUS_INDICATOR.set(Some(true));
}

pub fn set_unapproved() {
STATUS_INDICATOR.with(|v| v.set(Some(false)));
STATUS_INDICATOR.set(Some(false));
}

pub fn clear() {
STATUS_INDICATOR.with(|v| v.set(None));
STATUS_INDICATOR.set(None);
}
}

Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/hkdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl PrkMode {
}
}

impl core::fmt::Debug for PrkMode {
impl fmt::Debug for PrkMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Expand { .. } => f.debug_struct("Expand").finish_non_exhaustive(),
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/io/der.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ mod tests {
positive_integer(input)?
.big_endian_without_leading_zero_as_input()
.as_slice_less_safe(),
untrusted::Input::from(&test_out[..]).as_slice_less_safe()
Input::from(&test_out[..]).as_slice_less_safe()
);
Ok(())
});
Expand Down
10 changes: 4 additions & 6 deletions aws-lc-rs/src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
//! let random_array = rand::generate(&rng).unwrap();
//! let more_rand_bytes: [u8; 64] = random_array.expose();
//! ```
use aws_lc::RAND_bytes;
use core::fmt::Debug;

use crate::error;
use crate::error::Unspecified;
use crate::fips::indicator_check;
use aws_lc::RAND_bytes;
use core::fmt::Debug;

/// A secure random number generator.
pub trait SecureRandom: sealed::SecureRandom {
Expand Down Expand Up @@ -146,7 +144,7 @@ impl Default for SystemRandom {

impl sealed::SecureRandom for SystemRandom {
#[inline]
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), Unspecified> {
fill(dest)
}
}
Expand All @@ -158,7 +156,7 @@ impl sealed::SecureRandom for SystemRandom {
//
/// # Errors
/// `error::Unspecified` if unable to fill `dest`.
pub fn fill(dest: &mut [u8]) -> Result<(), error::Unspecified> {
pub fn fill(dest: &mut [u8]) -> Result<(), Unspecified> {
if 1 != indicator_check!(unsafe { RAND_bytes(dest.as_mut_ptr(), dest.len()) }) {
return Err(Unspecified);
}
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/rsa/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl KeyPair {
match self.evp_pkey.get_rsa() {
Ok(rsa) => {
// https://github.com/awslabs/aws-lc/blob/main/include/openssl/rsa.h#L99
unsafe { (RSA_size(*rsa)) as usize }
unsafe { RSA_size(*rsa) as usize }
}
Err(_) => verify_unreachable!(),
}
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/rsa/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub(crate) fn verify_rsa_signature(
return Err(Unspecified);
}

let mut md_ctx = digest::digest_ctx::DigestContext::new_uninit();
let mut md_ctx = DigestContext::new_uninit();
let digest = digest::match_digest_type(&algorithm.id);

let mut pctx = null_mut::<EVP_PKEY_CTX>();
Expand Down
4 changes: 2 additions & 2 deletions aws-lc-rs/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ fn parse_test_case(
is_first_line = false;

let parts: Vec<&str> = line.splitn(2, " = ").collect();
assert!(parts.len() == 2, "Syntax error: Expected Key = Value.");
assert_eq!(parts.len(), 2, "Syntax error: Expected Key = Value.");

let key = parts[0].trim();
let value = parts[1].trim();
Expand Down Expand Up @@ -636,7 +636,7 @@ mod tests {
let mut n = 0;
test::run(test_file!("test/test_3_tests.txt"), |_, test_case| {
test_case.consume_string("Key");
assert!(n != test_to_fail, "Oh Noes!");
assert_ne!(n, test_to_fail, "Oh Noes!");
n += 1;
Ok(())
});
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/unstable/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl crate::kem::AlgorithmIdentifier for AlgorithmId {
impl crate::sealed::Sealed for AlgorithmId {}

/// Retrieve an unstable KEM [`Algorithm`] using the [`AlgorithmId`] specified by `id`.
/// May return [`Option::None`] if support for the algorithm has been removed from the unstable module.
/// May return [`None`] if support for the algorithm has been removed from the unstable module.
#[must_use]
pub const fn get_algorithm(id: AlgorithmId) -> Option<&'static Algorithm<AlgorithmId>> {
match id {
Expand Down
Loading

0 comments on commit eebbafa

Please sign in to comment.