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:
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/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use console::style;
|
|
||||||
use openssl::asn1::Asn1Time;
|
use openssl::asn1::Asn1Time;
|
||||||
use openssl::hash::MessageDigest;
|
use openssl::hash::MessageDigest;
|
||||||
use openssl::nid::Nid;
|
use openssl::nid::Nid;
|
||||||
@ -29,42 +28,6 @@ use std::hash::{Hash, Hasher};
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
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 {
|
pub fn hex_encode<T: AsRef<[u8]>>(s: T) -> String {
|
||||||
s.as_ref()
|
s.as_ref()
|
||||||
.iter()
|
.iter()
|
||||||
|
39
src/main.rs
39
src/main.rs
@ -20,12 +20,13 @@
|
|||||||
mod cli;
|
mod cli;
|
||||||
|
|
||||||
use crate::cli::{Cli, SubCommand};
|
use crate::cli::{Cli, SubCommand};
|
||||||
|
use cert_tools::{Certificate, Chain, PrivateKey};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::style;
|
use console::style;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use cert_tools::{print_cert, Chain, PrivateKey};
|
use std::time::SystemTime;
|
||||||
|
|
||||||
fn main() -> Result<(), ()> {
|
fn main() -> Result<(), ()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
@ -150,3 +151,39 @@ fn main() -> Result<(), ()> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
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