Skip to content

Commit ccdac5d

Browse files
jshadjc
authored andcommitted
Add an example to print trust anchors.
1 parent fc11ca2 commit ccdac5d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ webpki-roots = "0.22"
1919
ring = "0.16.5"
2020
untrusted = "0.7.0"
2121
rustls = "0.20"
22+
x509-parser = "0.9.2"
2223

2324
[target.'cfg(windows)'.dependencies]
2425
schannel = "0.1.15"

examples/print-trust-anchors.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Print the Subject of all extracted trust anchors.
2+
3+
use rustls_native_certs;
4+
use std::error::Error;
5+
use x509_parser::prelude::*;
6+
7+
fn main() -> Result<(), Box<dyn Error>> {
8+
for cert in rustls_native_certs::load_native_certs()? {
9+
match parse_x509_certificate(&cert.0) {
10+
Ok((_, cert)) => println!("{}", cert.tbs_certificate.subject),
11+
Err(e) => eprintln!("error parsing certificate: {}", e),
12+
};
13+
}
14+
Ok(())
15+
}

0 commit comments

Comments
 (0)