Skip to content

Commit

Permalink
Formatting: Change import granularity to "Module" (#672)
Browse files Browse the repository at this point in the history
* Change import granularity to Module

* Use 'Module' granularity
  • Loading branch information
justsmth authored Jan 28, 2025
1 parent 76bcc06 commit e4f44ab
Show file tree
Hide file tree
Showing 41 changed files with 201 additions and 263 deletions.
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imports_granularity = "Module"
5 changes: 1 addition & 4 deletions aws-lc-rs-testing/benches/kem_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

use aws_lc_rs::{
kem::DecapsulationKey,
kem::{Algorithm, ML_KEM_1024, ML_KEM_512, ML_KEM_768},
};
use aws_lc_rs::kem::{Algorithm, DecapsulationKey, ML_KEM_1024, ML_KEM_512, ML_KEM_768};
use criterion::{criterion_group, criterion_main, Criterion};

const KEM_ALGORITHMS: &[Algorithm; 3] = &[ML_KEM_512, ML_KEM_768, ML_KEM_1024];
Expand Down
13 changes: 5 additions & 8 deletions aws-lc-rs/examples/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
//! $ cargo run --example cipher -- decrypt --mode cbc --key 6489d8ce0c4facf18b872705a05d5ee4 --iv 5cd56fb752830ec2459889226c5431bd 6311c14e8104730be124ce1e57e51fe3
//! Hello World
//! ```
use aws_lc_rs::{
cipher::{
DecryptingKey, DecryptionContext, EncryptingKey, EncryptionContext,
PaddedBlockDecryptingKey, PaddedBlockEncryptingKey, UnboundCipherKey, AES_128,
AES_128_KEY_LEN, AES_192, AES_192_KEY_LEN, AES_256, AES_256_KEY_LEN, AES_CBC_IV_LEN,
AES_CTR_IV_LEN,
},
iv::FixedLength,
use aws_lc_rs::cipher::{
DecryptingKey, DecryptionContext, EncryptingKey, EncryptionContext, PaddedBlockDecryptingKey,
PaddedBlockEncryptingKey, UnboundCipherKey, AES_128, AES_128_KEY_LEN, AES_192, AES_192_KEY_LEN,
AES_256, AES_256_KEY_LEN, AES_CBC_IV_LEN, AES_CTR_IV_LEN,
};
use aws_lc_rs::iv::FixedLength;
use clap::{Parser, Subcommand, ValueEnum};

#[derive(Parser)]
Expand Down
24 changes: 13 additions & 11 deletions aws-lc-rs/src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@
//! # }
//! ```
use crate::{derive_debug_via_id, error::Unspecified, hkdf};
use crate::error::Unspecified;
use crate::{derive_debug_via_id, hkdf};
use aead_ctx::AeadCtx;
use core::{fmt::Debug, ops::RangeFrom, stringify};
use core::fmt::Debug;
use core::ops::RangeFrom;
use core::stringify;
use paste::paste;

mod aead_ctx;
Expand All @@ -197,14 +200,12 @@ mod rand_nonce;
mod tls;
mod unbound_key;

pub use self::{
aes_gcm::{AES_128_GCM, AES_128_GCM_SIV, AES_192_GCM, AES_256_GCM, AES_256_GCM_SIV},
chacha::CHACHA20_POLY1305,
nonce::{Nonce, NONCE_LEN},
rand_nonce::RandomizedNonceKey,
tls::{TlsProtocolId, TlsRecordOpeningKey, TlsRecordSealingKey},
unbound_key::UnboundKey,
};
pub use self::aes_gcm::{AES_128_GCM, AES_128_GCM_SIV, AES_192_GCM, AES_256_GCM, AES_256_GCM_SIV};
pub use self::chacha::CHACHA20_POLY1305;
pub use self::nonce::{Nonce, NONCE_LEN};
pub use self::rand_nonce::RandomizedNonceKey;
pub use self::tls::{TlsProtocolId, TlsRecordOpeningKey, TlsRecordSealingKey};
pub use self::unbound_key::UnboundKey;

/// A sequences of unique nonces.
///
Expand Down Expand Up @@ -1019,7 +1020,8 @@ mod tests {
use nonce_sequence::Counter32Builder;

use super::*;
use crate::{iv::FixedLength, test::from_hex};
use crate::iv::FixedLength;
use crate::test::from_hex;

#[cfg(feature = "fips")]
mod fips;
Expand Down
3 changes: 2 additions & 1 deletion aws-lc-rs/src/aead/chacha20_poly1305_openssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
use super::{poly1305, Nonce, Tag};
use crate::cipher::block::BLOCK_LEN;
use crate::cipher::chacha::{self, ChaCha20Key};
use crate::endian::BigEndian;
use crate::iv::FixedLength;
use crate::{constant_time, endian::BigEndian, error};
use crate::{constant_time, error};

/// A key for sealing packets.
pub struct SealingKey {
Expand Down
9 changes: 4 additions & 5 deletions aws-lc-rs/src/aead/rand_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
use crate::error::Unspecified;
use core::fmt::Debug;

use super::{aead_ctx::AeadCtx, Aad, Algorithm, AlgorithmID, Nonce, Tag, UnboundKey};
use super::aead_ctx::AeadCtx;
use super::{Aad, Algorithm, AlgorithmID, Nonce, Tag, UnboundKey};

/// AEAD Cipher key using a randomized nonce.
///
Expand Down Expand Up @@ -148,10 +149,8 @@ impl Debug for RandomizedNonceKey {
#[cfg(test)]
mod tests {
use super::{Aad, RandomizedNonceKey};
use crate::{
aead::{AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305},
test::from_hex,
};
use crate::aead::{AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305};
use crate::test::from_hex;
use paste::paste;

const TEST_128_BIT_KEY: &[u8] = &[
Expand Down
13 changes: 6 additions & 7 deletions aws-lc-rs/src/aead/tests/fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
mod chacha20_poly1305_openssh;
mod quic;

use crate::{
aead::{
nonce_sequence::Counter64Builder, Aad, BoundKey, Nonce, OpeningKey, RandomizedNonceKey,
SealingKey, TlsProtocolId, TlsRecordOpeningKey, TlsRecordSealingKey, UnboundKey,
AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305,
},
fips::{assert_fips_status_indicator, FipsServiceStatus},
use crate::aead::nonce_sequence::Counter64Builder;
use crate::aead::{
Aad, BoundKey, Nonce, OpeningKey, RandomizedNonceKey, SealingKey, TlsProtocolId,
TlsRecordOpeningKey, TlsRecordSealingKey, UnboundKey, AES_128_GCM, AES_256_GCM,
CHACHA20_POLY1305,
};
use crate::fips::{assert_fips_status_indicator, FipsServiceStatus};

const TEST_KEY_128_BIT: [u8; 16] = [
0x9f, 0xd9, 0x41, 0xc3, 0xa6, 0xfe, 0xb9, 0x26, 0x2a, 0x35, 0xa7, 0x44, 0xbb, 0xc0, 0x3a, 0x6a,
Expand Down
6 changes: 2 additions & 4 deletions aws-lc-rs/src/aead/tests/fips/chacha20_poly1305_openssh.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

use crate::{
aead::chacha20_poly1305_openssh::{OpeningKey, SealingKey},
fips::{assert_fips_status_indicator, FipsServiceStatus},
};
use crate::aead::chacha20_poly1305_openssh::{OpeningKey, SealingKey};
use crate::fips::{assert_fips_status_indicator, FipsServiceStatus};

use super::TEST_MESSAGE;

Expand Down
6 changes: 2 additions & 4 deletions aws-lc-rs/src/aead/tests/fips/quic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

use crate::{
aead::quic::{HeaderProtectionKey, AES_128, AES_256, CHACHA20},
fips::{assert_fips_status_indicator, FipsServiceStatus},
};
use crate::aead::quic::{HeaderProtectionKey, AES_128, AES_256, CHACHA20};
use crate::fips::{assert_fips_status_indicator, FipsServiceStatus};

use super::{TEST_KEY_128_BIT, TEST_KEY_256_BIT};

Expand Down
13 changes: 4 additions & 9 deletions aws-lc-rs/src/aead/tls.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

use super::{
aead_ctx::{self, AeadCtx},
Aad, Algorithm, AlgorithmID, Nonce, Tag, UnboundKey,
};
use super::aead_ctx::{self, AeadCtx};
use super::{Aad, Algorithm, AlgorithmID, Nonce, Tag, UnboundKey};
use crate::error::Unspecified;
use core::fmt::Debug;
use core::ops::RangeFrom;
Expand Down Expand Up @@ -298,11 +296,8 @@ impl Debug for TlsRecordOpeningKey {
#[cfg(test)]
mod tests {
use super::{TlsProtocolId, TlsRecordOpeningKey, TlsRecordSealingKey};
use crate::{
aead::Aad,
aead::{Nonce, AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305},
test::from_hex,
};
use crate::aead::{Aad, Nonce, AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305};
use crate::test::from_hex;
use paste::paste;

const TEST_128_BIT_KEY: &[u8] = &[
Expand Down
13 changes: 9 additions & 4 deletions aws-lc-rs/src/aead/unbound_key.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

use super::{aead_ctx::AeadCtx, Algorithm, Nonce, MAX_KEY_LEN, MAX_TAG_LEN, NONCE_LEN};
use super::aead_ctx::AeadCtx;
use super::{
Tag, AES_128_GCM, AES_128_GCM_SIV, AES_192_GCM, AES_256_GCM, AES_256_GCM_SIV, CHACHA20_POLY1305,
Algorithm, Nonce, Tag, AES_128_GCM, AES_128_GCM_SIV, AES_192_GCM, AES_256_GCM, AES_256_GCM_SIV,
CHACHA20_POLY1305, MAX_KEY_LEN, MAX_TAG_LEN, NONCE_LEN,
};
use crate::aws_lc::{
EVP_AEAD_CTX_open, EVP_AEAD_CTX_open_gather, EVP_AEAD_CTX_seal, EVP_AEAD_CTX_seal_scatter,
};
use crate::error::Unspecified;
use crate::fips::indicator_check;
use crate::hkdf;
use crate::iv::FixedLength;
use crate::{error::Unspecified, fips::indicator_check, hkdf};
use core::fmt::Debug;
use core::{mem::MaybeUninit, ops::RangeFrom, ptr::null};
use core::mem::MaybeUninit;
use core::ops::RangeFrom;
use core::ptr::null;

/// The maximum length of a nonce returned by our AEAD API.
const MAX_NONCE_LEN: usize = NONCE_LEN;
Expand Down
3 changes: 1 addition & 2 deletions aws-lc-rs/src/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,7 @@ mod tests {
#[test]
fn agreement_traits() {
use crate::test;
use regex;
use regex::Regex;
use regex::{self, Regex};

let rng = rand::SystemRandom::new();
let private_key = PrivateKey::generate_for_test(&ECDH_P256, &rng).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion aws-lc-rs/src/cipher/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::aws_lc::{
AES_cbc_encrypt, AES_cfb128_encrypt, AES_ctr128_encrypt, AES_ecb_encrypt, AES_DECRYPT,
AES_ENCRYPT, AES_KEY,
};
use crate::{cipher::block::Block, error::Unspecified, fips::indicator_check};
use crate::cipher::block::Block;
use crate::error::Unspecified;
use crate::fips::indicator_check;
use zeroize::Zeroize;

use super::{DecryptionContext, EncryptionContext, OperatingMode, SymmetricCipherKey};
Expand Down
5 changes: 3 additions & 2 deletions aws-lc-rs/src/cipher/padded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ impl Debug for PaddedBlockDecryptingKey {

#[cfg(test)]
mod tests {
use crate::cipher::padded::PaddingStrategy;
use crate::cipher::{
padded::PaddingStrategy, Algorithm, EncryptionContext, OperatingMode,
PaddedBlockDecryptingKey, PaddedBlockEncryptingKey, UnboundCipherKey, AES_128, AES_256,
Algorithm, EncryptionContext, OperatingMode, PaddedBlockDecryptingKey,
PaddedBlockEncryptingKey, UnboundCipherKey, AES_128, AES_256,
};
use crate::iv::FixedLength;
use crate::test::from_hex;
Expand Down
11 changes: 4 additions & 7 deletions aws-lc-rs/src/cipher/tests/fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

#![cfg(debug_assertions)]

use crate::{
cipher::{
DecryptingKey, EncryptingKey, PaddedBlockDecryptingKey, PaddedBlockEncryptingKey,
StreamingDecryptingKey, StreamingEncryptingKey, UnboundCipherKey, AES_128, AES_192,
AES_256,
},
fips::{assert_fips_status_indicator, FipsServiceStatus},
use crate::cipher::{
DecryptingKey, EncryptingKey, PaddedBlockDecryptingKey, PaddedBlockEncryptingKey,
StreamingDecryptingKey, StreamingEncryptingKey, UnboundCipherKey, AES_128, AES_192, AES_256,
};
use crate::fips::{assert_fips_status_indicator, FipsServiceStatus};

const TEST_KEY_128_BIT: [u8; 16] = [
0x9f, 0xd9, 0x41, 0xc3, 0xa6, 0xfe, 0xb9, 0x26, 0x2a, 0x35, 0xa7, 0x44, 0xbb, 0xc0, 0x3a, 0x6a,
Expand Down
10 changes: 4 additions & 6 deletions aws-lc-rs/src/digest/tests/fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

#![cfg(debug_assertions)]

use crate::{
digest::{
Context, SHA1_FOR_LEGACY_USE_ONLY, SHA224, SHA256, SHA384, SHA3_256, SHA3_384, SHA3_512,
SHA512, SHA512_256,
},
fips::{assert_fips_status_indicator, FipsServiceStatus},
use crate::digest::{
Context, SHA1_FOR_LEGACY_USE_ONLY, SHA224, SHA256, SHA384, SHA3_256, SHA3_384, SHA3_512,
SHA512, SHA512_256,
};
use crate::fips::{assert_fips_status_indicator, FipsServiceStatus};

const TEST_MESSAGE: &str = "test message";

Expand Down
9 changes: 5 additions & 4 deletions aws-lc-rs/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

use crate::ec::signature::AlgorithmID;
use core::mem::MaybeUninit;
use core::ptr::null;
use core::ptr::null_mut;
use core::ptr::{null, null_mut};
// TODO: Uncomment when MSRV >= 1.64
// use core::ffi::c_int;
use std::os::raw::c_int;
Expand Down Expand Up @@ -427,8 +426,10 @@ mod tests {
use crate::encoding::{
AsBigEndian, AsDer, EcPublicKeyCompressedBin, EcPublicKeyUncompressedBin, PublicKeyX509Der,
};
use crate::signature::{EcdsaKeyPair, UnparsedPublicKey, ECDSA_P256_SHA256_FIXED};
use crate::signature::{KeyPair, ECDSA_P256_SHA256_FIXED_SIGNING};
use crate::signature::{
EcdsaKeyPair, KeyPair, UnparsedPublicKey, ECDSA_P256_SHA256_FIXED,
ECDSA_P256_SHA256_FIXED_SIGNING,
};
use crate::test::from_dirty_hex;
use crate::{signature, test};

Expand Down
8 changes: 3 additions & 5 deletions aws-lc-rs/src/hkdf/tests/fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

#![cfg(debug_assertions)]

use crate::{
fips::{assert_fips_status_indicator, FipsServiceStatus},
hkdf::{
KeyType, Prk, Salt, HKDF_SHA1_FOR_LEGACY_USE_ONLY, HKDF_SHA256, HKDF_SHA384, HKDF_SHA512,
},
use crate::fips::{assert_fips_status_indicator, FipsServiceStatus};
use crate::hkdf::{
KeyType, Prk, Salt, HKDF_SHA1_FOR_LEGACY_USE_ONLY, HKDF_SHA256, HKDF_SHA384, HKDF_SHA512,
};

const TEST_KEY_128_BIT: [u8; 16] = [
Expand Down
14 changes: 6 additions & 8 deletions aws-lc-rs/src/hmac/tests/fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

#![cfg(debug_assertions)]

use crate::{
digest::{SHA1_OUTPUT_LEN, SHA224_OUTPUT_LEN, SHA256_OUTPUT_LEN, SHA512_OUTPUT_LEN},
fips::{assert_fips_status_indicator, FipsServiceStatus},
hmac::{
sign, verify, Key, HMAC_SHA1_FOR_LEGACY_USE_ONLY, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384,
HMAC_SHA512,
},
rand::{self, SystemRandom},
use crate::digest::{SHA1_OUTPUT_LEN, SHA224_OUTPUT_LEN, SHA256_OUTPUT_LEN, SHA512_OUTPUT_LEN};
use crate::fips::{assert_fips_status_indicator, FipsServiceStatus};
use crate::hmac::{
sign, verify, Key, HMAC_SHA1_FOR_LEGACY_USE_ONLY, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384,
HMAC_SHA512,
};
use crate::rand::{self, SystemRandom};

const TEST_MESSAGE: &str = "test message";

Expand Down
4 changes: 2 additions & 2 deletions aws-lc-rs/src/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ pub use sskdf::{

#[cfg(test)]
mod tests {
use crate::kdf::sskdf::SskdfHmacAlgorithmId;
use crate::kdf::{
get_kbkdf_ctr_hmac_algorithm, get_sskdf_digest_algorithm, get_sskdf_hmac_algorithm,
kbkdf_ctr_hmac, sskdf::SskdfHmacAlgorithmId, sskdf_digest, sskdf_hmac,
KbkdfCtrHmacAlgorithmId, SskdfDigestAlgorithmId,
kbkdf_ctr_hmac, sskdf_digest, sskdf_hmac, KbkdfCtrHmacAlgorithmId, SskdfDigestAlgorithmId,
};

#[test]
Expand Down
11 changes: 4 additions & 7 deletions aws-lc-rs/src/kdf/kbkdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

#![allow(clippy::module_name_repetitions)]

use crate::aws_lc::KBKDF_ctr_hmac;
use crate::aws_lc::EVP_MD;
use crate::aws_lc::{KBKDF_ctr_hmac, EVP_MD};

use crate::{
digest::{match_digest_type, AlgorithmID},
error::Unspecified,
ptr::ConstPointer,
};
use crate::digest::{match_digest_type, AlgorithmID};
use crate::error::Unspecified;
use crate::ptr::ConstPointer;

/// KBKDF in Counter Mode with HMAC-SHA224
#[allow(dead_code)]
Expand Down
11 changes: 4 additions & 7 deletions aws-lc-rs/src/kdf/sskdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

#![allow(clippy::module_name_repetitions)]

use crate::aws_lc::EVP_MD;
use crate::aws_lc::{SSKDF_digest, SSKDF_hmac};
use crate::aws_lc::{SSKDF_digest, SSKDF_hmac, EVP_MD};

use crate::{
digest::{match_digest_type, AlgorithmID},
error::Unspecified,
ptr::ConstPointer,
};
use crate::digest::{match_digest_type, AlgorithmID};
use crate::error::Unspecified;
use crate::ptr::ConstPointer;

/// SSKDF with HMAC-SHA224
#[allow(dead_code)]
Expand Down
Loading

0 comments on commit e4f44ab

Please sign in to comment.