1
0
mirror of https://github.com/pcvolkmer/cert-tools.git synced 2025-04-19 17:06:49 +00:00

refactor: move print_cert() into main.rs

This commit is contained in:
Paul-Christian Volkmer 2025-01-04 18:45:47 +01:00
parent 9486cb0653
commit ee8409957c
2 changed files with 38 additions and 38 deletions

View File

@ -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()

View File

@ -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(", "))
);
}
}