Implement 'Display' for PublicKeyMaterial

This commit is contained in:
Heiko Schaefer 2021-11-16 19:18:34 +01:00
parent 874c28b7ff
commit e695e8171a
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D
2 changed files with 21 additions and 0 deletions

View file

@ -14,6 +14,7 @@ documentation = "https://docs.rs/crate/openpgp-card"
[dependencies]
nom = "6"
hex-literal = "0.3"
hex-slice = "0.1"
anyhow = "1"
thiserror = "1"
env_logger = "0.8"

View file

@ -120,6 +120,26 @@ pub enum PublicKeyMaterial {
E(EccPub),
}
impl std::fmt::Display for PublicKeyMaterial {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use hex_slice::AsHex;
match self {
Self::R(rsa) => {
write!(
f,
"RSA, n: {:02X}, e: {:02X}",
rsa.n.plain_hex(false),
rsa.v.plain_hex(false)
)
}
Self::E(ecc) => {
write!(f, "ECC, data: {:02X}", ecc.data.plain_hex(false))
}
}
}
}
/// RSA-specific container for public key material from an OpenPGP card.
#[derive(Debug)]
#[non_exhaustive]