diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index 3ae42b89..d4431c5c 100644 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -11,7 +11,6 @@ pub use signer::*; #[cfg(feature = "rustcrypto")] pub use crate::rustcrypto::*; -pub use signer::*; #[cfg(feature = "openssl")] pub mod openssl; diff --git a/platform/src/default.rs b/platform/src/default.rs index ea51275d..a998b527 100644 --- a/platform/src/default.rs +++ b/platform/src/default.rs @@ -4,17 +4,6 @@ use crate::{Platform, PlatformError, MAX_CHUNK_SIZE, MAX_SN_SIZE}; use cfg_if::cfg_if; use core::cmp::min; -cfg_if! { - if #[cfg(feature = "openssl")] { - use openssl::x509::X509; - } else if #[cfg(feature = "rustcrypto")] { - use x509_cert::{ - certificate::Certificate, - der::{DecodePem, Encode}, - }; - } -} - pub struct DefaultPlatform; pub const AUTO_INIT_LOCALITY: u32 = 0; @@ -34,45 +23,56 @@ pub const TEST_CERT_PEM: &[u8] = include_bytes!("test_data/cert_256.pem"); #[cfg(feature = "dpe_profile_p384_sha384")] pub const TEST_CERT_PEM: &[u8] = include_bytes!("test_data/cert_384.pem"); -impl DefaultPlatform { - cfg_if! { - if #[cfg(feature = "openssl")] { - fn parse_issuer_name() -> Vec { - X509::from_pem(TEST_CERT_PEM) - .unwrap() - .subject_name() - .to_der() - .unwrap() - }} else if #[cfg(feature = "rustcrypto")] { - fn parse_issuer_name() -> Vec { - Certificate::from_pem(TEST_CERT_PEM) - .unwrap() - .tbs_certificate - .subject - .to_der() - .unwrap() - } - }} - - cfg_if! { - if #[cfg(feature = "openssl")] { - fn parse_issuer_sn() -> Vec { - X509::from_pem(TEST_CERT_PEM) - .unwrap() - .serial_number() - .to_bn() - .unwrap() - .to_vec() - } - } else if #[cfg(feature = "rustcrypto")] { - fn parse_issuer_sn() -> Vec { - Certificate::from_pem(TEST_CERT_PEM) - .unwrap() - .tbs_certificate - .serial_number - .as_bytes() - .to_vec() +cfg_if! { + if #[cfg(feature = "openssl")] { + mod parse { + use super::*; + use openssl::x509::X509; + pub struct DefaultPlatform; + impl DefaultPlatform { + pub fn parse_issuer_name() -> Vec { + X509::from_pem(TEST_CERT_PEM) + .unwrap() + .subject_name() + .to_der() + .unwrap() + } + pub fn parse_issuer_sn() -> Vec { + X509::from_pem(TEST_CERT_PEM) + .unwrap() + .serial_number() + .to_bn() + .unwrap() + .to_vec() + } + } } + } else if #[cfg(feature = "rustcrypto")] { + mod parse { + use super::*; + use x509_cert::{ + certificate::Certificate, + der::{DecodePem, Encode}, + }; + pub struct DefaultPlatform; + impl DefaultPlatform { + pub fn parse_issuer_name() -> Vec { + Certificate::from_pem(TEST_CERT_PEM) + .unwrap() + .tbs_certificate + .subject + .to_der() + .unwrap() + } + pub fn parse_issuer_sn() -> Vec { + Certificate::from_pem(TEST_CERT_PEM) + .unwrap() + .tbs_certificate + .serial_number + .as_bytes() + .to_vec() + } + } } } } @@ -101,7 +101,7 @@ impl Platform for DefaultPlatform { } fn get_issuer_name(&mut self, out: &mut [u8; MAX_CHUNK_SIZE]) -> Result { - let issuer_name = DefaultPlatform::parse_issuer_name(); + let issuer_name = parse::DefaultPlatform::parse_issuer_name(); if issuer_name.len() > out.len() { return Err(PlatformError::IssuerNameError(0)); } @@ -110,7 +110,7 @@ impl Platform for DefaultPlatform { } fn get_issuer_sn(&mut self, out: &mut [u8; MAX_SN_SIZE]) -> Result { - let sn = DefaultPlatform::parse_issuer_sn(); + let sn = parse::DefaultPlatform::parse_issuer_sn(); if sn.len() > out.len() { return Err(PlatformError::IssuerNameError(0)); }