feat: fixed incorrect issuer for certificates & added x509 prints (#437)
This commit is contained in:
committed by
GitHub
parent
d8653bc6f0
commit
0071566097
+22
-1
@@ -47,6 +47,7 @@ use p256::NistP256;
|
||||
use p384::NistP384;
|
||||
use rsa::{PublicKeyParts, RsaPublicKey};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::fmt::Display;
|
||||
use std::{fmt, ops::DerefMut};
|
||||
use x509::{der::Oid, RelativeDistinguishedName};
|
||||
use x509_parser::{parse_x509_certificate, x509::SubjectPublicKeyInfo};
|
||||
@@ -94,6 +95,26 @@ impl Serial {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
self.0.to_bytes_be()
|
||||
}
|
||||
/// Returns itself formatted as x509 compatible hex string
|
||||
pub fn as_x509_hex(&self) -> String {
|
||||
let data = self.to_bytes();
|
||||
let raw_hex_string = format!("{:02X?}", data);
|
||||
raw_hex_string
|
||||
.replace(", ", ":")
|
||||
.replace([']', '['], "")
|
||||
.to_lowercase()
|
||||
}
|
||||
/// Returns itself formatted as x509 compatible int string
|
||||
pub fn as_x509_int(&self) -> String {
|
||||
let Serial(buint) = self;
|
||||
format!("{}", buint)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Serial {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(&self.as_x509_hex())
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about how a [`Certificate`] is stored within a YubiKey.
|
||||
@@ -512,7 +533,7 @@ impl Certificate {
|
||||
|
||||
/// Returns the Issuer field of the certificate.
|
||||
pub fn issuer(&self) -> &str {
|
||||
&self.subject
|
||||
&self.issuer
|
||||
}
|
||||
|
||||
/// Returns the SubjectName field of the certificate.
|
||||
|
||||
Reference in New Issue
Block a user