From b5983b3112a7e6e0514b87da898ee133f99db4c1 Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Wed, 21 Feb 2024 16:11:58 -0500 Subject: [PATCH 1/2] lib: always avoid std prelude Instead, in tests manually import the prelude when needed. This also implies separate imports for macros. --- src/alg_tests.rs | 2 ++ src/cert.rs | 1 + src/crl/mod.rs | 6 +++--- src/crl/types.rs | 2 ++ src/der.rs | 1 + src/end_entity.rs | 1 + src/lib.rs | 5 ++++- src/test_utils.rs | 1 + src/verify_cert.rs | 2 ++ 9 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/alg_tests.rs b/src/alg_tests.rs index 52a6e6a7..e9224938 100644 --- a/src/alg_tests.rs +++ b/src/alg_tests.rs @@ -14,6 +14,8 @@ #![allow(clippy::duplicate_mod)] +use std::prelude::v1::*; + use base64::{engine::general_purpose, Engine as _}; use crate::error::{DerTypeId, Error}; diff --git a/src/cert.rs b/src/cert.rs index 1021cf4c..5851fadd 100644 --- a/src/cert.rs +++ b/src/cert.rs @@ -347,6 +347,7 @@ mod tests { use crate::error::Error; #[cfg(feature = "alloc")] use crate::subject_name::GeneralName; + use std::prelude::v1::*; #[test] // Note: cert::parse_cert is crate-local visibility, and EndEntityCert doesn't expose the diff --git a/src/crl/mod.rs b/src/crl/mod.rs index 2ac9241d..b0a49e3e 100644 --- a/src/crl/mod.rs +++ b/src/crl/mod.rs @@ -250,7 +250,7 @@ mod tests { #[cfg(feature = "alloc")] { let err = result.unwrap_err(); - println!("{:?}", err.clone()); + std::println!("{:?}", err.clone()); } // It should be possible to build a revocation options builder with defaults. @@ -263,7 +263,7 @@ mod tests { #[cfg(feature = "alloc")] { // The builder should be debug, and clone when alloc is enabled - println!("{:?}", builder); + std::println!("{:?}", builder); _ = builder.clone(); } let opts = builder.build(); @@ -313,7 +313,7 @@ mod tests { // Built revocation options should be debug and clone when alloc is enabled. #[cfg(feature = "alloc")] { - println!("{:?}", opts.clone()); + std::println!("{:?}", opts.clone()); } } } diff --git a/src/crl/types.rs b/src/crl/types.rs index 148dcf4a..25769661 100644 --- a/src/crl/types.rs +++ b/src/crl/types.rs @@ -900,6 +900,8 @@ impl TryFrom for RevocationReason { #[cfg(test)] mod tests { use pki_types::CertificateDer; + use std::prelude::v1::*; + use std::println; use super::*; use crate::cert::Cert; diff --git a/src/der.rs b/src/der.rs index 38a0001a..aebc5133 100644 --- a/src/der.rs +++ b/src/der.rs @@ -423,6 +423,7 @@ macro_rules! oid { #[cfg(test)] mod tests { use super::DerTypeId; + use std::prelude::v1::*; #[test] fn test_optional_boolean() { diff --git a/src/end_entity.rs b/src/end_entity.rs index 41a9efa0..605f0227 100644 --- a/src/end_entity.rs +++ b/src/end_entity.rs @@ -186,6 +186,7 @@ impl<'a> Deref for EndEntityCert<'a> { mod tests { use super::*; use crate::test_utils; + use std::prelude::v1::*; // This test reproduces https://github.com/rustls/webpki/issues/167 --- an // end-entity cert where the common name is a `PrintableString` rather than diff --git a/src/lib.rs b/src/lib.rs index d1ebb982..5d2fc9dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ //! | `ring` | Enable use of the *ring* crate for cryptography. | //! | `aws_lc_rs` | Enable use of the aws-lc-rs crate for cryptography. | -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![warn(unreachable_pub)] #![deny(missing_docs, clippy::as_conversions)] #![allow( @@ -40,6 +40,9 @@ // Enable documentation for all features on docs.rs #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#[cfg(any(feature = "std", test))] +extern crate std; + #[cfg(any(test, feature = "alloc"))] #[cfg_attr(test, macro_use)] extern crate alloc; diff --git a/src/test_utils.rs b/src/test_utils.rs index 9685bcf7..0b5dd7ef 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,4 +1,5 @@ #![cfg(feature = "alloc")] +use std::prelude::v1::*; use crate::types::CertificateDer; diff --git a/src/verify_cert.rs b/src/verify_cert.rs index 657926dd..5fc18196 100644 --- a/src/verify_cert.rs +++ b/src/verify_cert.rs @@ -705,6 +705,8 @@ mod tests { use super::*; use crate::test_utils::{issuer_params, make_end_entity, make_issuer}; use crate::trust_anchor::anchor_from_trusted_cert; + use std::dbg; + use std::prelude::v1::*; #[test] fn eku_key_purpose_id() { From f2fdd3de9bbf7de873a20dfc3141ceb1525e682a Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Wed, 21 Feb 2024 16:16:50 -0500 Subject: [PATCH 2/2] fix redundant import clippy findings --- src/alg_tests.rs | 1 - src/cert.rs | 4 ---- src/verify_cert.rs | 1 - 3 files changed, 6 deletions(-) diff --git a/src/alg_tests.rs b/src/alg_tests.rs index e9224938..4d2ade9b 100644 --- a/src/alg_tests.rs +++ b/src/alg_tests.rs @@ -21,7 +21,6 @@ use base64::{engine::general_purpose, Engine as _}; use crate::error::{DerTypeId, Error}; use crate::verify_cert::Budget; use crate::{der, signed_data}; -use alloc::{string::String, vec::Vec}; use super::{ INVALID_SIGNATURE_FOR_RSA_KEY, OK_IF_RSA_AVAILABLE, SUPPORTED_ALGORITHMS_IN_TESTS, diff --git a/src/cert.rs b/src/cert.rs index 5851fadd..4e280b13 100644 --- a/src/cert.rs +++ b/src/cert.rs @@ -343,10 +343,6 @@ mod tests { use super::*; #[cfg(feature = "alloc")] use crate::crl::RevocationReason; - #[cfg(feature = "alloc")] - use crate::error::Error; - #[cfg(feature = "alloc")] - use crate::subject_name::GeneralName; use std::prelude::v1::*; #[test] diff --git a/src/verify_cert.rs b/src/verify_cert.rs index 5fc18196..6cc6d779 100644 --- a/src/verify_cert.rs +++ b/src/verify_cert.rs @@ -12,7 +12,6 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use core::default::Default; use core::ops::ControlFlow; use pki_types::{CertificateDer, SignatureVerificationAlgorithm, TrustAnchor, UnixTime};