From 2c00e57bc66734fd0bc2bef22ca2bb589783629f Mon Sep 17 00:00:00 2001 From: Luca Fulchir Date: Wed, 8 Feb 2023 23:41:03 +0100 Subject: [PATCH] Public Key try_from_str Signed-off-by: Luca Fulchir --- src/dnssec/record.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/dnssec/record.rs b/src/dnssec/record.rs index c06e411..5492621 100644 --- a/src/dnssec/record.rs +++ b/src/dnssec/record.rs @@ -68,15 +68,30 @@ impl PublicKeyType { } } +impl TryFrom<&str> for PublicKeyType { + type Error = ::std::io::Error; + fn try_from(raw: &str) -> Result { + if let Ok(type_u8) = raw.parse::() { + if let Some(kind) = PublicKeyType::from_u8(type_u8) { + return Ok(kind); + } + } + return Err(::std::io::Error::new( + ::std::io::ErrorKind::InvalidData, + "Public Key Type 0 is the only one supported", + )); + } +} + /// Public Key, with its type and id #[derive(Debug, Clone)] pub struct PublicKey { /// public key raw data - raw: Vec, + pub raw: Vec, /// type of public key - kind: PublicKeyType, + pub kind: PublicKeyType, /// id of public key - id: PublicKeyId, + pub id: PublicKeyId, } impl PublicKey { @@ -334,10 +349,10 @@ impl Address { #[derive(Debug, Clone)] pub struct Record { /// Public keys used by any authentication server - public_keys: Vec, + pub public_keys: Vec, /// List of all authentication servers' addresses. /// Multiple ones can point to the same authentication server - addresses: Vec
, + pub addresses: Vec
, } impl Record {