Skip to content

Commit

Permalink
Move Algorithm::from_str()'s logic from -proto to -server.
Browse files Browse the repository at this point in the history
`Algorithm::from_str()` isn't uesd by -resolver so it shouldn't be in
-proto.
  • Loading branch information
briansmith authored and bluejekyll committed Oct 25, 2017
1 parent dcb4971 commit 6bf9ec2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
20 changes: 0 additions & 20 deletions proto/src/rr/dnssec/algorithm.rs
Expand Up @@ -15,7 +15,6 @@
*/
use std::fmt;
use std::fmt::{Display, Formatter};
use std::str::FromStr;

use serialize::binary::*;
use error::*;
Expand Down Expand Up @@ -173,25 +172,6 @@ impl BinSerializable<Algorithm> for Algorithm {
}
}

impl FromStr for Algorithm {
type Err = ProtoError;

fn from_str(s: &str) -> ProtoResult<Algorithm> {
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<Algorithm> for &'static str {
fn from(a: Algorithm) -> &'static str {
a.to_str()
Expand Down
11 changes: 10 additions & 1 deletion server/src/config.rs
Expand Up @@ -296,7 +296,16 @@ impl KeyConfig {

/// algorithm for for the key, see `Algorithm` for supported algorithms.
pub fn algorithm(&self) -> ParseResult<Algorithm> {
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.
Expand Down

0 comments on commit 6bf9ec2

Please sign in to comment.