radicle: Did improvements

Add conversion from Did to PublicKey through a From implementation.

Add FromStr implementation.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2023-02-16 12:37:24 +00:00 committed by Alexis Sellier
parent a1e1e04fd9
commit efe5ff6ddd
No known key found for this signature in database
1 changed files with 14 additions and 0 deletions

View File

@ -46,12 +46,26 @@ impl From<crypto::PublicKey> for Did {
}
}
impl From<Did> for crypto::PublicKey {
fn from(Did(key): Did) -> Self {
key
}
}
impl From<Did> for String {
fn from(other: Did) -> Self {
other.encode()
}
}
impl FromStr for Did {
type Err = DidError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::decode(s)
}
}
impl TryFrom<String> for Did {
type Error = DidError;