Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Algorithm::from_str()'s logic from -proto to -server. #259

Merged
merged 3 commits into from Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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