Skip to content

Commit

Permalink
Fix error caused by check_for_redundant_imports clippy logic
Browse files Browse the repository at this point in the history
Signed-off-by: OuyangHang33 <[email protected]>
  • Loading branch information
OuyangHang33 authored and jyao1 committed Mar 14, 2024
1 parent 8ebd487 commit 2c4e480
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 25 deletions.
4 changes: 3 additions & 1 deletion executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// SPDX-License-Identifier: Apache-2.0 or MIT
//

#![cfg_attr(any(target_os = "uefi", target_os = "none"), no_std)]
#![no_std]
#[cfg(feature = "std")]
extern crate std;

mod executor;
use crate::executor::*;
Expand Down
11 changes: 6 additions & 5 deletions spdmlib/src/common/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ impl SpdmSession {

#[cfg(test)]
mod tests_session {
extern crate std;
use super::*;

#[test]
Expand All @@ -1110,7 +1111,7 @@ mod tests_session {
SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE,
);
session.set_session_state(crate::common::session::SpdmSessionState::SpdmSessionHandshaking);
println!("session.session_id::{:?}", session.session_id);
std::println!("session.session_id::{:?}", session.session_id);
assert!(session
.set_dhe_secret(
SpdmVersion::SpdmVersion12,
Expand Down Expand Up @@ -1177,7 +1178,7 @@ mod tests_session {
SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE,
);
session.set_session_state(crate::common::session::SpdmSessionState::SpdmSessionHandshaking);
println!("session.session_id::{:?}", session.session_id);
std::println!("session.session_id::{:?}", session.session_id);
assert!(session
.set_dhe_secret(
SpdmVersion::SpdmVersion12,
Expand Down Expand Up @@ -1244,7 +1245,7 @@ mod tests_session {
SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE,
);
session.set_session_state(crate::common::session::SpdmSessionState::SpdmSessionHandshaking);
println!("session.session_id::{:?}", session.session_id);
std::println!("session.session_id::{:?}", session.session_id);
assert!(session
.set_dhe_secret(
SpdmVersion::SpdmVersion12,
Expand Down Expand Up @@ -1312,7 +1313,7 @@ mod tests_session {
SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE,
);
session.set_session_state(crate::common::session::SpdmSessionState::SpdmSessionHandshaking);
println!("session.session_id::{:?}", session.session_id);
std::println!("session.session_id::{:?}", session.session_id);
assert!(session
.set_dhe_secret(
SpdmVersion::SpdmVersion12,
Expand Down Expand Up @@ -1451,7 +1452,7 @@ mod tests_session {
);
session.set_session_state(crate::common::session::SpdmSessionState::SpdmSessionHandshaking);
session.transport_param.sequence_number_count = 1;
println!("session.session_id::{:?}", session.session_id);
std::println!("session.session_id::{:?}", session.session_id);
assert!(session
.set_dhe_secret(
SpdmVersion::SpdmVersion12,
Expand Down
5 changes: 4 additions & 1 deletion spdmlib/src/crypto/crypto_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//
// SPDX-License-Identifier: Apache-2.0 or MIT

extern crate std;
use std::{boxed::Box, string::String, vec::Vec};

use super::aead::{decrypt, encrypt};
#[cfg(feature = "hashed-transcript-data")]
use super::hash;
Expand Down Expand Up @@ -217,5 +220,5 @@ fn from_hex_digit(d: u8) -> Result<u8, String> {
return Ok(d - range.start() + offset);
}
}
Err(format!("Invalid hex digit '{}'", d as char))
Err(std::format!("Invalid hex digit '{}'", d as char))
}
12 changes: 7 additions & 5 deletions spdmlib/src/crypto/spdm_ring/aead_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ fn make_key<K: ring::aead::BoundKey<OneNonceSequence>>(
mod tests {
use super::*;
use crate::protocol::*;
extern crate std;
use std::boxed::Box;

#[test]
fn test_case0_encrypt() {
Expand Down Expand Up @@ -216,7 +218,7 @@ mod tests {
let aad = &mut [100u8; 16];
let cipher_text = &mut [100u8; 16];
let ret_tag_size = encrypt(aead_algo, key, iv, aad, plain_text, tag, cipher_text);
println!("ret_tag_size{:?}", ret_tag_size);
std::println!("ret_tag_size{:?}", ret_tag_size);
}
#[test]
fn test_case3_encrypt() {
Expand All @@ -234,7 +236,7 @@ mod tests {
let aad = &mut [100u8; 16];
let cipher_text = &mut [100u8; 16];
let ret_tag_size = encrypt(aead_algo, key, iv, aad, plain_text, tag, cipher_text);
println!("ret_tag_size{:?}", ret_tag_size);
std::println!("ret_tag_size{:?}", ret_tag_size);
}
#[test]
fn test_case4_encrypt() {
Expand All @@ -252,7 +254,7 @@ mod tests {
let aad = &mut [100u8; 16];
let cipher_text = &mut [100u8; 16];
let ret_tag_size = encrypt(aead_algo, key, iv, aad, plain_text, tag, cipher_text);
println!("ret_tag_size{:?}", ret_tag_size);
std::println!("ret_tag_size{:?}", ret_tag_size);
}
#[test]
fn test_case5_encrypt() {
Expand All @@ -270,7 +272,7 @@ mod tests {
let aad = &mut [100u8; 16];
let cipher_text = &mut [100u8; 1];
let ret_tag_size = encrypt(aead_algo, key, iv, aad, plain_text, tag, cipher_text);
println!("ret_tag_size{:?}", ret_tag_size);
std::println!("ret_tag_size{:?}", ret_tag_size);
}
#[test]
fn test_case6_encrypt() {
Expand All @@ -288,7 +290,7 @@ mod tests {
let aad = &mut [100u8; 16];
let cipher_text = &mut [100u8; 1];
let ret_tag_size = encrypt(aead_algo, key, iv, aad, plain_text, tag, cipher_text);
println!("ret_tag_size{:?}", ret_tag_size);
std::println!("ret_tag_size{:?}", ret_tag_size);
}
#[test]
#[should_panic]
Expand Down
3 changes: 2 additions & 1 deletion spdmlib/src/crypto/spdm_ring/hkdf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ impl ring::hkdf::KeyType for SpdmCryptoHkdfKeyLen {
#[cfg(test)]
mod tests {
use crate::protocol::SPDM_MAX_HASH_SIZE;

extern crate alloc;
use super::*;
use alloc::boxed::Box;

#[test]
fn test_case0_hkdf_expand() {
Expand Down
3 changes: 2 additions & 1 deletion spdmlib/src/crypto/spdm_ring/hmac_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ fn hmac_verify(
#[cfg(test)]
mod tests {
use crate::protocol::{SpdmFinishedKeyStruct, SPDM_MAX_HASH_SIZE};

extern crate alloc;
use super::*;
use alloc::boxed::Box;

#[test]
fn test_case0_hmac_verify() {
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/crypto/spdm_ring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pub mod hash_impl;
pub mod hkdf_impl;
pub mod hmac_impl;
pub mod rand_impl;
extern crate alloc;
1 change: 1 addition & 0 deletions spdmlib/src/crypto/x509v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ pub fn check_leaf_certificate(cert: &[u8], is_alias_cert_model: bool) -> SpdmRes

#[cfg(test)]
mod tests {
extern crate std;
use super::*;

#[test]
Expand Down
5 changes: 4 additions & 1 deletion spdmlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
//
// SPDX-License-Identifier: Apache-2.0 or MIT

#![no_std]
#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(stmt_expr_attributes)]
#![feature(try_trait_v2)]

#[cfg(feature = "std")]
extern crate std;

#[macro_use]
extern crate log;

Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ mod tests {
use crate::protocol::*;
use testlib::{create_spdm_context, DeviceIO, TransportEncap};
extern crate alloc;
use alloc::boxed::Box;

#[test]
fn test_case0_spdm_challenge_request_payload() {
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ mod tests {
use crate::protocol::*;
use testlib::{create_spdm_context, DeviceIO, TransportEncap};
extern crate alloc;
use alloc::boxed::Box;

#[test]
fn test_case0_spdm_digests_response_payload() {
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/finish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ mod tests {
use crate::protocol::*;
use testlib::{create_spdm_context, DeviceIO, TransportEncap};
extern crate alloc;
use alloc::boxed::Box;

#[test]
fn test_case0_spdm_finish_request_payload() {
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/key_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ mod tests {
use crate::protocol::*;
use testlib::{create_spdm_context, DeviceIO, TransportEncap};
extern crate alloc;
use alloc::boxed::Box;

#[test]
fn test_case0_spdm_key_exchange_mut_auth_attributes() {
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ mod tests {
use codec::u24;
use testlib::{create_spdm_context, new_spdm_message, DeviceIO, TransportEncap};
extern crate alloc;
use alloc::boxed::Box;

#[test]
fn test_case0_spdm_message_header() {
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/mod_test.common.inc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::message::SpdmMessage;
use codec::{Reader, Writer};
use spin::Mutex;
extern crate alloc;
use alloc::boxed::Box;
use alloc::sync::Arc;

#[allow(unused, unused_mut)]
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/psk_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ mod tests {
use crate::protocol::*;
use testlib::{create_spdm_context, DeviceIO, TransportEncap};
extern crate alloc;
use alloc::boxed::Box;

#[test]
fn test_case0_spdm_psk_exchange_request_payload() {
Expand Down
1 change: 1 addition & 0 deletions spdmlib/src/message/psk_finish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod tests {
use crate::protocol::*;
use testlib::{create_spdm_context, DeviceIO, TransportEncap};
extern crate alloc;
use alloc::boxed::Box;

#[test]
fn test_case0_spdm_psk_finish_request_payload() {
Expand Down
1 change: 0 additions & 1 deletion spdmlib/src/protocol/algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::config;
use crate::crypto::bytes_mut_scrubbed::BytesMutStrubbed;
use bytes::BytesMut;
use codec::{enum_builder, u24, Codec, Reader, Writer};
use core::convert::From;
extern crate alloc;
use alloc::boxed::Box;
use zeroize::{Zeroize, ZeroizeOnDrop};
Expand Down
8 changes: 7 additions & 1 deletion spdmlib_crypto_mbedtls/src/aead_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[cfg(feature = "std")]
use std::vec::Vec;

use mbedtls::cipher::{raw, Authenticated, Cipher, Decryption, Encryption, Fresh};
use spdmlib::crypto::SpdmAead;
use spdmlib::error::{SpdmResult, SPDM_STATUS_INVALID_PARAMETER};
Expand Down Expand Up @@ -130,6 +133,9 @@ mod test {
SpdmAeadIvStruct, SpdmAeadKeyStruct, SPDM_MAX_AEAD_IV_SIZE, SPDM_MAX_AEAD_KEY_SIZE,
},
};
extern crate std;
use std::{boxed::Box, string::String};

#[test]
fn test_case_gcm256() {
// Test vector from GCM Test Vectors (SP 800-38D)
Expand Down Expand Up @@ -234,6 +240,6 @@ mod test {
return Ok(d - range.start() + offset);
}
}
Err(format!("Invalid hex digit '{}'", d as char))
Err(std::format!("Invalid hex digit '{}'", d as char))
}
}
3 changes: 3 additions & 0 deletions spdmlib_crypto_mbedtls/src/dhe_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, vec::Vec};

#[cfg(feature = "std")]
use std::{boxed::Box, vec::Vec};

use mbedtls::ecp::EcPoint;
use mbedtls::pk::{EcGroup, EcGroupId, Pk};
use mbedtls::rng::RngCallback;
Expand Down
8 changes: 4 additions & 4 deletions spdmlib_crypto_mbedtls/src/hash_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ pub use hash_ext::DEFAULT;
mod hash_ext {
extern crate alloc;
use super::*;
use alloc::boxed::Box;
use alloc::collections::BTreeMap;
use alloc::{boxed::Box, collections::BTreeMap};
use lazy_static::lazy_static;
use spdmlib::error::{SpdmResult, SPDM_STATUS_CRYPTO_ERROR};
use spin::Mutex;
Expand Down Expand Up @@ -106,8 +105,9 @@ fn hash_all(base_hash_algo: SpdmBaseHashAlgo, data: &[u8]) -> Option<SpdmDigestS

#[test]
fn test_case1_hash_all() {
extern crate std;
use std::fmt::Write;
use std::string::String;
use std::string::{String, ToString};
let base_hash_algo = SpdmBaseHashAlgo::TPM_ALG_SHA_256;
let data = &b"hello"[..];

Expand All @@ -116,7 +116,7 @@ fn test_case1_hash_all() {
for d in hash_all.as_ref() {
let _ = write!(&mut res, "{:02x}", d);
}
println!("res: {}", String::from_utf8_lossy(res.as_ref()));
std::println!("res: {}", String::from_utf8_lossy(res.as_ref()));
assert_eq!(hash_all.data_size, 32);

assert_eq!(
Expand Down
2 changes: 2 additions & 0 deletions spdmlib_crypto_mbedtls/src/hkdf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ fn hkdf_expand(

#[cfg(test)]
mod tests {
extern crate std;
use super::*;
use spdmlib::protocol::{SpdmBaseHashAlgo, SPDM_MAX_HASH_SIZE};
use std::boxed::Box;
#[test]
fn test_case0_hkdf_expand() {
let base_hash_algo = SpdmBaseHashAlgo::TPM_ALG_SHA_256;
Expand Down
3 changes: 2 additions & 1 deletion spdmlib_crypto_mbedtls/src/hmac_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ fn hmac_verify(
#[cfg(test)]
mod tests {
use spdmlib::protocol::{SpdmFinishedKeyStruct, SPDM_MAX_HASH_SIZE};

extern crate std;
use super::*;
use std::boxed::Box;
#[test]
fn test_case_rfc4231_2() {
let key = &mut SpdmFinishedKeyStruct {
Expand Down
5 changes: 4 additions & 1 deletion spdmlib_crypto_mbedtls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
//
// SPDX-License-Identifier: Apache-2.0 or MIT

#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

#[cfg(not(feature = "std"))]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

pub mod aead_impl;

pub mod dhe_impl;
Expand Down
2 changes: 0 additions & 2 deletions test/spdm-emu/src/async_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0 or MIT

extern crate alloc;
use alloc::boxed::Box;
use core::{future::Future, pin::Pin};

// Run async task
Expand Down

0 comments on commit 2c4e480

Please sign in to comment.