From 6bf9ec2bf4b29ce819914f3197e4e4634fe96b7e Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Tue, 24 Oct 2017 13:40:11 -0700 Subject: [PATCH] Move `Algorithm::from_str()`'s logic from -proto to -server. `Algorithm::from_str()` isn't uesd by -resolver so it shouldn't be in -proto. --- proto/src/rr/dnssec/algorithm.rs | 20 -------------------- server/src/config.rs | 11 ++++++++++- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/proto/src/rr/dnssec/algorithm.rs b/proto/src/rr/dnssec/algorithm.rs index f48d63e8de..6f861273fe 100644 --- a/proto/src/rr/dnssec/algorithm.rs +++ b/proto/src/rr/dnssec/algorithm.rs @@ -15,7 +15,6 @@ */ use std::fmt; use std::fmt::{Display, Formatter}; -use std::str::FromStr; use serialize::binary::*; use error::*; @@ -173,25 +172,6 @@ impl BinSerializable for Algorithm { } } -impl FromStr for Algorithm { - type Err = ProtoError; - - fn from_str(s: &str) -> ProtoResult { - match s { - "RSASHA1" => Ok(Algorithm::RSASHA1), - "RSASHA256" => Ok(Algorithm::RSASHA256), - "RSASHA1-NSEC3-SHA1" => Ok(Algorithm::RSASHA1NSEC3SHA1), - "RSASHA512" => Ok(Algorithm::RSASHA512), - "ECDSAP256SHA256" => Ok(Algorithm::ECDSAP256SHA256), - "ECDSAP384SHA384" => Ok(Algorithm::ECDSAP384SHA384), - "ED25519" => Ok(Algorithm::ED25519), - _ => Err( - ProtoErrorKind::Msg(format!("unrecognized string {}", s)).into(), - ), - } - } -} - impl From for &'static str { fn from(a: Algorithm) -> &'static str { a.to_str() diff --git a/server/src/config.rs b/server/src/config.rs index b1536f5ac1..548a19a691 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -296,7 +296,16 @@ impl KeyConfig { /// algorithm for for the key, see `Algorithm` for supported algorithms. pub fn algorithm(&self) -> ParseResult { - Algorithm::from_str(&self.algorithm).map_err(|e| e.into()) + match self.algorithm.as_str() { + "RSASHA1" => Ok(Algorithm::RSASHA1), + "RSASHA256" => Ok(Algorithm::RSASHA256), + "RSASHA1-NSEC3-SHA1" => Ok(Algorithm::RSASHA1NSEC3SHA1), + "RSASHA512" => Ok(Algorithm::RSASHA512), + "ECDSAP256SHA256" => Ok(Algorithm::ECDSAP256SHA256), + "ECDSAP384SHA384" => Ok(Algorithm::ECDSAP384SHA384), + "ED25519" => Ok(Algorithm::ED25519), + s => Err(format!("unrecognized string {}", s).into()), + } } /// the signer name for the key, this defaults to the $ORIGIN aka zone name.