keyfork-derive-util: impl FromStr for DerivationAlgorithm

This commit is contained in:
Ryan Heywood 2023-09-11 21:31:00 -05:00
parent f60b77254a
commit 71261e1323
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
2 changed files with 14 additions and 0 deletions

View File

@ -26,6 +26,8 @@ thiserror = "1.0.47"
# Optional, not personally audited # Optional, not personally audited
k256 = { version = "0.13.1", default-features = false, features = ["std", "arithmetic"], optional = true } k256 = { version = "0.13.1", default-features = false, features = ["std", "arithmetic"], optional = true }
ed25519-dalek = { version = "2.0.0", optional = true } ed25519-dalek = { version = "2.0.0", optional = true }
# Workspace
keyfork-mnemonic-util = { version = "0.1.0", path = "../keyfork-mnemonic-util" } keyfork-mnemonic-util = { version = "0.1.0", path = "../keyfork-mnemonic-util" }
[dev-dependencies] [dev-dependencies]

View File

@ -48,6 +48,18 @@ impl DerivationAlgorithm {
} }
} }
impl std::str::FromStr for DerivationAlgorithm {
type Err = DerivationError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(match s {
"ed25519" => Self::Ed25519,
"secp256k1" => Self::Secp256k1,
_ => return Err(DerivationError::Algorithm),
})
}
}
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DerivationRequest { pub struct DerivationRequest {
algorithm: DerivationAlgorithm, algorithm: DerivationAlgorithm,