mirror of
https://github.com/pcvolkmer/cert-tools.git
synced 2025-04-19 09:06:49 +00:00
refactor: move print_cert() into main.rs
This commit is contained in:
parent
9486cb0653
commit
ee8409957c
37
src/lib.rs
37
src/lib.rs
@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use console::style;
|
||||
use openssl::asn1::Asn1Time;
|
||||
use openssl::hash::MessageDigest;
|
||||
use openssl::nid::Nid;
|
||||
@ -29,42 +28,6 @@ use std::hash::{Hash, Hasher};
|
||||
use std::path::Path;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub fn print_cert(cert: &Certificate) {
|
||||
println!(
|
||||
"{}
|
||||
Issuer: {}
|
||||
Gültigkeit: Gültig von: {} bis: {}
|
||||
SHA-1-Fingerprint: {}
|
||||
SHA-256-Fingerprint: {}
|
||||
Subject-Key-Id: {}
|
||||
Authority-Key-Id: {}",
|
||||
style(format!("Name: {}", cert.name()))
|
||||
.bold()
|
||||
.underlined(),
|
||||
cert.issuer(),
|
||||
if cert.is_valid_not_before(&SystemTime::now()) {
|
||||
style(cert.not_before().to_string())
|
||||
} else {
|
||||
style(cert.not_before().to_string()).red()
|
||||
},
|
||||
if cert.is_valid_not_after(&SystemTime::now()) {
|
||||
style(cert.not_after().to_string())
|
||||
} else {
|
||||
style(cert.not_after().to_string()).red()
|
||||
},
|
||||
cert.fingerprint().sha1,
|
||||
cert.fingerprint().sha256,
|
||||
cert.subject_key_id(),
|
||||
cert.authority_key_id(),
|
||||
);
|
||||
if !cert.dns_names().is_empty() {
|
||||
println!(
|
||||
"DNS Names: {}",
|
||||
style(cert.dns_names().join(", "))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hex_encode<T: AsRef<[u8]>>(s: T) -> String {
|
||||
s.as_ref()
|
||||
.iter()
|
||||
|
39
src/main.rs
39
src/main.rs
@ -20,12 +20,13 @@
|
||||
mod cli;
|
||||
|
||||
use crate::cli::{Cli, SubCommand};
|
||||
use cert_tools::{Certificate, Chain, PrivateKey};
|
||||
use clap::Parser;
|
||||
use console::style;
|
||||
use itertools::Itertools;
|
||||
use std::cmp::Ordering;
|
||||
use std::path::Path;
|
||||
use cert_tools::{print_cert, Chain, PrivateKey};
|
||||
use std::time::SystemTime;
|
||||
|
||||
fn main() -> Result<(), ()> {
|
||||
let cli = Cli::parse();
|
||||
@ -150,3 +151,39 @@ fn main() -> Result<(), ()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_cert(cert: &Certificate) {
|
||||
println!(
|
||||
"{}
|
||||
Issuer: {}
|
||||
Gültigkeit: Gültig von: {} bis: {}
|
||||
SHA-1-Fingerprint: {}
|
||||
SHA-256-Fingerprint: {}
|
||||
Subject-Key-Id: {}
|
||||
Authority-Key-Id: {}",
|
||||
style(format!("Name: {}", cert.name()))
|
||||
.bold()
|
||||
.underlined(),
|
||||
cert.issuer(),
|
||||
if cert.is_valid_not_before(&SystemTime::now()) {
|
||||
style(cert.not_before().to_string())
|
||||
} else {
|
||||
style(cert.not_before().to_string()).red()
|
||||
},
|
||||
if cert.is_valid_not_after(&SystemTime::now()) {
|
||||
style(cert.not_after().to_string())
|
||||
} else {
|
||||
style(cert.not_after().to_string()).red()
|
||||
},
|
||||
cert.fingerprint().sha1,
|
||||
cert.fingerprint().sha256,
|
||||
cert.subject_key_id(),
|
||||
cert.authority_key_id(),
|
||||
);
|
||||
if !cert.dns_names().is_empty() {
|
||||
println!(
|
||||
"DNS Names: {}",
|
||||
style(cert.dns_names().join(", "))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user