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

chore: some code cleanup

This commit is contained in:
Paul-Christian Volkmer 2025-01-06 17:15:19 +01:00
parent f26b486553
commit 8e898cf4bb
2 changed files with 6 additions and 6 deletions

View File

@ -31,7 +31,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
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()
.map(|b| format!("{:02x}", b)) .map(|b| format!("{b:02x}"))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(":") .join(":")
.to_ascii_uppercase() .to_ascii_uppercase()
@ -242,7 +242,7 @@ impl Certificate {
} }
} }
pub fn public_key_matches(&self, private_key: PrivateKey) -> bool { pub fn public_key_matches(&self, private_key: &PrivateKey) -> bool {
if self.key_modulo().to_string() == private_key.modulus.to_string() { if self.key_modulo().to_string() == private_key.modulus.to_string() {
return true; return true;
} }
@ -306,7 +306,7 @@ impl Chain {
} }
x = match cert.public_key() { x = match cert.public_key() {
Ok(public_key) => Some(public_key), Ok(public_key) => Some(public_key),
Err(_) => None, Err(()) => None,
} }
} }
!time_issue && !self.certs.is_empty() !time_issue && !self.certs.is_empty()

View File

@ -415,7 +415,7 @@ impl Ui {
Ok(private_key) => { Ok(private_key) => {
if let Some(chain) = &self.chain { if let Some(chain) = &self.chain {
if let Some(first) = chain.certs().first() { if let Some(first) = chain.certs().first() {
if first.public_key_matches(private_key) { if first.public_key_matches(&private_key) {
column![Container::new(text( column![Container::new(text(
"Private Key matches first Cert Public Key" "Private Key matches first Cert Public Key"
)) ))
@ -558,7 +558,7 @@ Authority-Key-Id: {}
match PrivateKey::read(Path::new(&key)) { match PrivateKey::read(Path::new(&key)) {
Ok(private_key) => { Ok(private_key) => {
if let Some(cert) = chain.certs().first() { if let Some(cert) = chain.certs().first() {
if cert.public_key_matches(private_key) { if cert.public_key_matches(&private_key) {
output.push( output.push(
"✓ Private Key matches first Cert Public Key".to_string(), "✓ Private Key matches first Cert Public Key".to_string(),
); );
@ -679,7 +679,7 @@ Authority-Key-Id: {}
match PrivateKey::read(Path::new(&key)) { match PrivateKey::read(Path::new(&key)) {
Ok(private_key) => { Ok(private_key) => {
if let Some(cert) = chain.certs().first() { if let Some(cert) = chain.certs().first() {
return if cert.public_key_matches(private_key) && chain.is_valid() { return if cert.public_key_matches(&private_key) && chain.is_valid() {
result result
} else { } else {
IndicatorState::Error IndicatorState::Error