Skip to content

Commit

Permalink
feat(rust): add basic FromStr impl for PublicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed May 11, 2022
1 parent 04daa0d commit a0d9e83
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion sdk/rust/src/key/public_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::hash::{Hash, Hasher};
use std::{
hash::{Hash, Hasher},
str::FromStr,
};

use crate::Error;

Expand Down Expand Up @@ -33,6 +36,17 @@ impl Hash for PublicKey {
}
}

impl FromStr for PublicKey {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// TODO: handle DER-prefixed
// TODO: handle ecdsa

Self::from_bytes_raw_ed25519(&hex::decode(s).map_err(Error::key_parse)?)
}
}

// impl ToProtobuf for PublicKey {
// type Protobuf = services::Key;
//
Expand Down

0 comments on commit a0d9e83

Please sign in to comment.