Skip to content

Commit ca4fe4a

Browse files
committed
Refactor crate modules and visibility
1 parent 5eb6492 commit ca4fe4a

File tree

11 files changed

+41
-56
lines changed

11 files changed

+41
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ For PEM-encoded certificates, use the [`pem`](https://docs.rs/x509-parser/latest
4040
Parsing a certificate in DER format:
4141

4242
```rust
43-
use x509_parser::{parse_x509_certificate, X509Version};
43+
use x509_parser::prelude::*;
4444

4545
static IGCA_DER: &[u8] = include_bytes!("../assets/IGC_A.der");
4646

examples/print-cert.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ use nom::HexDisplay;
33
use std::cmp::min;
44
use std::env;
55
use std::io;
6-
use x509_parser::extensions::*;
7-
use x509_parser::objects::*;
8-
use x509_parser::pem::parse_x509_pem;
9-
use x509_parser::X509Certificate;
10-
use x509_parser::{parse_x509_certificate, X509Extension};
6+
use x509_parser::prelude::*;
117

128
fn print_hex_dump(bytes: &[u8], max_len: usize) {
139
let m = min(bytes.len(), max_len);
@@ -57,7 +53,7 @@ fn print_x509_extension(oid: &Oid, ext: &X509Extension) {
5753
}
5854
}
5955

60-
fn print_x509_digest_algorithm(alg: &x509_parser::AlgorithmIdentifier, level: usize) {
56+
fn print_x509_digest_algorithm(alg: &AlgorithmIdentifier, level: usize) {
6157
println!(
6258
"{:indent$}Oid: {}",
6359
"",

examples/print-crl.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ use nom::HexDisplay;
33
use std::cmp::min;
44
use std::env;
55
use std::io;
6-
use x509_parser::extensions::*;
7-
use x509_parser::objects::*;
8-
use x509_parser::pem::parse_x509_pem;
9-
use x509_parser::CertificateRevocationList;
10-
use x509_parser::{parse_x509_crl, RevokedCertificate, X509Extension, X509Version};
6+
use x509_parser::prelude::*;
117

128
fn print_hex_dump(bytes: &[u8], max_len: usize) {
139
let m = min(bytes.len(), max_len);
@@ -87,7 +83,7 @@ fn print_x509_extension(oid: &Oid, ext: &X509Extension, level: usize) {
8783
}
8884
}
8985

90-
fn print_x509_digest_algorithm(alg: &x509_parser::AlgorithmIdentifier, level: usize) {
86+
fn print_x509_digest_algorithm(alg: &AlgorithmIdentifier, level: usize) {
9187
println!(
9288
"{:indent$}Oid: {}",
9389
"",

src/certificate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! X.509 Certificate object definitions and operations
2+
13
use std::collections::HashMap;
24

35
use der_parser::ber::*;
@@ -31,7 +33,7 @@ use crate::x509::{
3133
///
3234
/// ```rust
3335
/// # use x509_parser::parse_x509_certificate;
34-
/// # use x509_parser::X509Certificate;
36+
/// # use x509_parser::certificate::X509Certificate;
3537
/// #
3638
/// # static DER: &'static [u8] = include_bytes!("../assets/IGC_A.der");
3739
/// #

src/extensions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use num_bigint::BigUint;
1616
use oid_registry::*;
1717

1818
use crate::error::{X509Error, X509Result};
19-
use crate::time::der_to_utctime;
20-
use crate::{ASN1Time, ReasonCode, X509Name};
19+
use crate::time::{der_to_utctime, ASN1Time};
20+
use crate::x509::{ReasonCode, X509Name};
2121

2222
#[derive(Debug, PartialEq)]
2323
pub struct X509Extension<'a> {
@@ -62,7 +62,7 @@ impl<'a> X509Extension<'a> {
6262
/// # Example
6363
///
6464
/// ```rust
65-
/// # use x509_parser::{X509Extension, extensions::ParsedExtension};
65+
/// # use x509_parser::extensions::{X509Extension, ParsedExtension};
6666
/// #
6767
/// static DER: &[u8] = &[
6868
/// 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xA3, 0x05, 0x2F, 0x18,
@@ -1017,7 +1017,7 @@ mod tests {
10171017
assert!(!eku.email_protection);
10181018
assert!(eku.time_stamping);
10191019
assert!(!eku.ocscp_signing);
1020-
assert_eq!(eku.other, vec![oid!(1.2.3.4.0.42)]);
1020+
assert_eq!(eku.other, vec![oid!(1.2.3 .4 .0 .42)]);
10211021
}
10221022
assert_eq!(
10231023
tbs.policy_constraints().unwrap().1,
@@ -1049,10 +1049,10 @@ mod tests {
10491049
"C=UK, O=My Organization, OU=My Unit, CN=My Name"
10501050
);
10511051
assert_eq!(alt_names[4], GeneralName::DNSName("localhost"));
1052-
assert_eq!(alt_names[5], GeneralName::RegisteredID(oid!(1.2.90.0)));
1052+
assert_eq!(alt_names[5], GeneralName::RegisteredID(oid!(1.2.90 .0)));
10531053
assert_eq!(
10541054
alt_names[6],
1055-
GeneralName::OtherName(oid!(1.2.3.4), b"\xA0\x17\x0C\x15some other identifier")
1055+
GeneralName::OtherName(oid!(1.2.3 .4), b"\xA0\x17\x0C\x15some other identifier")
10561056
);
10571057
}
10581058

src/lib.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! Parsing a certificate in DER format:
3939
//!
4040
//! ```rust
41-
//! use x509_parser::{parse_x509_certificate, X509Version};
41+
//! use x509_parser::prelude::*;
4242
//!
4343
//! static IGCA_DER: &[u8] = include_bytes!("../assets/IGC_A.der");
4444
//!
@@ -87,7 +87,7 @@
8787
//!
8888
//! ```rust
8989
//! # #[cfg(feature = "verify")]
90-
//! # use x509_parser::X509Certificate;
90+
//! # use x509_parser::certificate::X509Certificate;
9191
//! /// Cryptographic signature verification: returns true if certificate was signed by issuer
9292
//! #[cfg(feature = "verify")]
9393
//! pub fn check_signature(cert: &X509Certificate<'_>, issuer: &X509Certificate<'_>) -> bool {
@@ -122,29 +122,26 @@
122122
))]
123123
#![cfg_attr(docsrs, feature(doc_cfg))]
124124

125-
pub use x509::*;
126-
pub mod x509;
127-
128125
pub mod certificate;
129-
pub use certificate::*;
130126
pub mod certification_request;
131-
pub use certification_request::*;
132127
pub mod cri_attributes;
133128
pub mod error;
134129
pub mod extensions;
135-
pub use extensions::X509Extension;
136130
pub mod objects;
137131
pub mod pem;
132+
pub mod prelude;
138133
pub mod revocation_list;
139-
pub use revocation_list::*;
140-
mod time;
141-
pub use time::*;
134+
pub mod time;
135+
pub mod x509;
142136

143137
// reexports
144138
pub use der_parser;
145139
pub use nom;
146140
pub use num_bigint;
147141

142+
use certificate::X509Certificate;
143+
use revocation_list::CertificateRevocationList;
144+
148145
/// Parse a **DER-encoded** X.509 Certificate, and return the remaining of the input and the built
149146
/// object.
150147
///

src/pem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! ```rust,no_run
1515
//! use std::io::Cursor;
1616
//! use x509_parser::pem::Pem;
17-
//! use x509_parser::X509Version;
17+
//! use x509_parser::x509::X509Version;
1818
//!
1919
//! static IGCA_PEM: &[u8] = include_bytes!("../assets/IGC_A.pem");
2020
//!

src/x509.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<'a> X509Name<'a> {
283283
/// A common operation is to extract the `CommonName` as a string.
284284
///
285285
/// ```
286-
/// use x509_parser::X509Name;
286+
/// use x509_parser::x509::X509Name;
287287
///
288288
/// fn get_first_cn_as_str<'a>(name: &'a X509Name<'_>) -> Option<&'a str> {
289289
/// name.iter_common_name()

tests/pem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io::Cursor;
22
use x509_parser::pem::{parse_x509_pem, Pem};
3-
use x509_parser::{parse_x509_certificate, X509Version};
3+
use x509_parser::{parse_x509_certificate, x509::X509Version};
44

55
static IGCA_PEM: &[u8] = include_bytes!("../assets/IGC_A.pem");
66

tests/readcert.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ use chrono::Datelike;
33
use der_parser::{oid, oid::Oid};
44
use oid_registry::*;
55
use std::collections::HashMap;
6-
use x509_parser::error::*;
7-
use x509_parser::extensions::*;
8-
use x509_parser::{
9-
parse_x509_crl, parse_x509_certificate, ASN1Time, ReasonCode, SubjectPublicKeyInfo,
10-
X509Extension, X509Version,
11-
};
6+
use x509_parser::prelude::*;
127

138
static IGCA_DER: &[u8] = include_bytes!("../assets/IGC_A.der");
149
static NO_EXTENSIONS_DER: &[u8] = include_bytes!("../assets/no_extensions.der");
@@ -46,7 +41,7 @@ fn test_x509_parser() {
4641
assert_eq!(cn_list, Ok(vec!["IGC/A"]));
4742
//
4843
let sig = &tbs_cert.signature;
49-
assert_eq!(sig.algorithm, oid!(1.2.840.113549.1.1.5));
44+
assert_eq!(sig.algorithm, oid!(1.2.840 .113549 .1 .1 .5));
5045
//
5146
let expected_issuer = "C=FR, ST=France, L=Paris, O=PM/SGDN, OU=DCSSI, CN=IGC/A, [email protected]";
5247
assert_eq!(format!("{}", tbs_cert.issuer), expected_issuer);
@@ -66,12 +61,12 @@ fn test_x509_parser() {
6661
assert_eq!(na.year(), 2020);
6762
assert_eq!(na.month(), 10);
6863
assert_eq!(na.day(), 17);
69-
let policies = vec![(oid!(1.2.250.1.121.1.1.1), [].as_ref())]
64+
let policies = vec![(oid!(1.2.250 .1 .121 .1 .1 .1), [].as_ref())]
7065
.into_iter()
7166
.collect();
7267
let expected_extensions_list = vec![
7368
X509Extension::new(
74-
oid!(2.5.29.19),
69+
oid!(2.5.29 .19),
7570
true,
7671
&[48, 3, 1, 1, 255],
7772
ParsedExtension::BasicConstraints(BasicConstraints {
@@ -80,19 +75,19 @@ fn test_x509_parser() {
8075
}),
8176
),
8277
X509Extension::new(
83-
oid!(2.5.29.15),
78+
oid!(2.5.29 .15),
8479
false,
8580
&[3, 2, 1, 70],
8681
ParsedExtension::KeyUsage(KeyUsage { flags: 98 }),
8782
),
8883
X509Extension::new(
89-
oid!(2.5.29.32),
84+
oid!(2.5.29 .32),
9085
false,
9186
&[48, 12, 48, 10, 6, 8, 42, 129, 122, 1, 121, 1, 1, 1],
9287
ParsedExtension::CertificatePolicies(CertificatePolicies { policies }),
9388
),
9489
X509Extension::new(
95-
oid!(2.5.29.14),
90+
oid!(2.5.29 .14),
9691
false,
9792
&[
9893
4, 20, 163, 5, 47, 24, 96, 80, 194, 137, 10, 221, 43, 33, 79, 255, 142, 78,
@@ -104,7 +99,7 @@ fn test_x509_parser() {
10499
])),
105100
),
106101
X509Extension::new(
107-
oid!(2.5.29.35),
102+
oid!(2.5.29 .35),
108103
false,
109104
&[
110105
48, 22, 128, 20, 163, 5, 47, 24, 96, 80, 194, 137, 10, 221, 43, 33, 79,
@@ -214,18 +209,18 @@ fn test_crl_parse() {
214209
assert_eq!(revoked_cert_0.revocation_date, revocation_date);
215210
let mut extensions_map = HashMap::new();
216211
extensions_map.insert(
217-
oid!(2.5.29.21),
212+
oid!(2.5.29 .21),
218213
X509Extension::new(
219-
oid!(2.5.29.21),
214+
oid!(2.5.29 .21),
220215
false,
221216
&[10, 1, 3],
222217
ParsedExtension::ReasonCode(ReasonCode::AffiliationChanged),
223218
),
224219
);
225220
extensions_map.insert(
226-
oid!(2.5.29.24),
221+
oid!(2.5.29 .24),
227222
X509Extension::new(
228-
oid!(2.5.29.24),
223+
oid!(2.5.29 .24),
229224
false,
230225
&[
231226
24, 15, 50, 48, 49, 51, 48, 50, 49, 56, 49, 48, 50, 50, 48, 48, 90,
@@ -240,7 +235,7 @@ fn test_crl_parse() {
240235

241236
let expected_extensions = vec![
242237
X509Extension::new(
243-
oid!(2.5.29.35),
238+
oid!(2.5.29 .35),
244239
false,
245240
&[
246241
48, 22, 128, 20, 190, 18, 1, 204, 170, 234, 17, 128, 218, 46, 173, 178,
@@ -256,7 +251,7 @@ fn test_crl_parse() {
256251
}),
257252
),
258253
X509Extension::new(
259-
oid!(2.5.29.20),
254+
oid!(2.5.29 .20),
260255
false,
261256
&[2, 1, 3],
262257
ParsedExtension::CRLNumber(3u32.into()),
@@ -284,7 +279,7 @@ fn test_crl_parse_empty() {
284279

285280
let expected_extensions = vec![
286281
X509Extension::new(
287-
oid!(2.5.29.20),
282+
oid!(2.5.29 .20),
288283
false,
289284
&[2, 1, 2],
290285
ParsedExtension::CRLNumber(2u32.into()),

tests/readcsr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use oid_registry::{OID_PKCS1_SHA256WITHRSA, OID_SIG_ECDSA_WITH_SHA256, OID_X509_COMMON_NAME};
2-
use x509_parser::extensions::{GeneralName, ParsedExtension};
3-
use x509_parser::{pem, X509CertificationRequest, X509Version};
2+
use x509_parser::prelude::*;
43

54
const CSR_DATA_EMPTY_ATTRIB: &[u8] = include_bytes!("../assets/csr-empty-attributes.csr");
65
const CSR_DATA: &[u8] = include_bytes!("../assets/test.csr");

0 commit comments

Comments
 (0)