From e695e8171a57ffd82c09f9719a99eb10463eb8f7 Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Tue, 16 Nov 2021 19:18:34 +0100 Subject: [PATCH] Implement 'Display' for PublicKeyMaterial --- openpgp-card/Cargo.toml | 1 + openpgp-card/src/crypto_data.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/openpgp-card/Cargo.toml b/openpgp-card/Cargo.toml index ce0cf9e..9dd5929 100644 --- a/openpgp-card/Cargo.toml +++ b/openpgp-card/Cargo.toml @@ -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" diff --git a/openpgp-card/src/crypto_data.rs b/openpgp-card/src/crypto_data.rs index 98ac9bd..15be615 100644 --- a/openpgp-card/src/crypto_data.rs +++ b/openpgp-card/src/crypto_data.rs @@ -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]