Skip to content

Commit d7c3813

Browse files
esmusickjhand2
authored andcommitted
Minor updates to RustCrypto impl
* Remove redundant `use` in crypto * Reorganize default platform parsing options
1 parent 229cafb commit d7c3813

File tree

2 files changed

+51
-52
lines changed

2 files changed

+51
-52
lines changed

crypto/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub use signer::*;
1111

1212
#[cfg(feature = "rustcrypto")]
1313
pub use crate::rustcrypto::*;
14-
pub use signer::*;
1514

1615
#[cfg(feature = "openssl")]
1716
pub mod openssl;

platform/src/default.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ use crate::{Platform, PlatformError, MAX_CHUNK_SIZE, MAX_SN_SIZE};
44
use cfg_if::cfg_if;
55
use core::cmp::min;
66

7-
cfg_if! {
8-
if #[cfg(feature = "openssl")] {
9-
use openssl::x509::X509;
10-
} else if #[cfg(feature = "rustcrypto")] {
11-
use x509_cert::{
12-
certificate::Certificate,
13-
der::{DecodePem, Encode},
14-
};
15-
}
16-
}
17-
187
pub struct DefaultPlatform;
198

209
pub const AUTO_INIT_LOCALITY: u32 = 0;
@@ -34,45 +23,56 @@ pub const TEST_CERT_PEM: &[u8] = include_bytes!("test_data/cert_256.pem");
3423
#[cfg(feature = "dpe_profile_p384_sha384")]
3524
pub const TEST_CERT_PEM: &[u8] = include_bytes!("test_data/cert_384.pem");
3625

37-
impl DefaultPlatform {
38-
cfg_if! {
39-
if #[cfg(feature = "openssl")] {
40-
fn parse_issuer_name() -> Vec<u8> {
41-
X509::from_pem(TEST_CERT_PEM)
42-
.unwrap()
43-
.subject_name()
44-
.to_der()
45-
.unwrap()
46-
}} else if #[cfg(feature = "rustcrypto")] {
47-
fn parse_issuer_name() -> Vec<u8> {
48-
Certificate::from_pem(TEST_CERT_PEM)
49-
.unwrap()
50-
.tbs_certificate
51-
.subject
52-
.to_der()
53-
.unwrap()
54-
}
55-
}}
56-
57-
cfg_if! {
58-
if #[cfg(feature = "openssl")] {
59-
fn parse_issuer_sn() -> Vec<u8> {
60-
X509::from_pem(TEST_CERT_PEM)
61-
.unwrap()
62-
.serial_number()
63-
.to_bn()
64-
.unwrap()
65-
.to_vec()
66-
}
67-
} else if #[cfg(feature = "rustcrypto")] {
68-
fn parse_issuer_sn() -> Vec<u8> {
69-
Certificate::from_pem(TEST_CERT_PEM)
70-
.unwrap()
71-
.tbs_certificate
72-
.serial_number
73-
.as_bytes()
74-
.to_vec()
26+
cfg_if! {
27+
if #[cfg(feature = "openssl")] {
28+
mod parse {
29+
use super::*;
30+
use openssl::x509::X509;
31+
pub struct DefaultPlatform;
32+
impl DefaultPlatform {
33+
pub fn parse_issuer_name() -> Vec<u8> {
34+
X509::from_pem(TEST_CERT_PEM)
35+
.unwrap()
36+
.subject_name()
37+
.to_der()
38+
.unwrap()
39+
}
40+
pub fn parse_issuer_sn() -> Vec<u8> {
41+
X509::from_pem(TEST_CERT_PEM)
42+
.unwrap()
43+
.serial_number()
44+
.to_bn()
45+
.unwrap()
46+
.to_vec()
47+
}
48+
}
7549
}
50+
} else if #[cfg(feature = "rustcrypto")] {
51+
mod parse {
52+
use super::*;
53+
use x509_cert::{
54+
certificate::Certificate,
55+
der::{DecodePem, Encode},
56+
};
57+
pub struct DefaultPlatform;
58+
impl DefaultPlatform {
59+
pub fn parse_issuer_name() -> Vec<u8> {
60+
Certificate::from_pem(TEST_CERT_PEM)
61+
.unwrap()
62+
.tbs_certificate
63+
.subject
64+
.to_der()
65+
.unwrap()
66+
}
67+
pub fn parse_issuer_sn() -> Vec<u8> {
68+
Certificate::from_pem(TEST_CERT_PEM)
69+
.unwrap()
70+
.tbs_certificate
71+
.serial_number
72+
.as_bytes()
73+
.to_vec()
74+
}
75+
}
7676
}
7777
}
7878
}
@@ -101,7 +101,7 @@ impl Platform for DefaultPlatform {
101101
}
102102

103103
fn get_issuer_name(&mut self, out: &mut [u8; MAX_CHUNK_SIZE]) -> Result<usize, PlatformError> {
104-
let issuer_name = DefaultPlatform::parse_issuer_name();
104+
let issuer_name = parse::DefaultPlatform::parse_issuer_name();
105105
if issuer_name.len() > out.len() {
106106
return Err(PlatformError::IssuerNameError(0));
107107
}
@@ -110,7 +110,7 @@ impl Platform for DefaultPlatform {
110110
}
111111

112112
fn get_issuer_sn(&mut self, out: &mut [u8; MAX_SN_SIZE]) -> Result<usize, PlatformError> {
113-
let sn = DefaultPlatform::parse_issuer_sn();
113+
let sn = parse::DefaultPlatform::parse_issuer_sn();
114114
if sn.len() > out.len() {
115115
return Err(PlatformError::IssuerNameError(0));
116116
}

0 commit comments

Comments
 (0)