summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/keygrip.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-08-26 14:48:12 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-08-26 16:00:49 +0200
commit86e2cb5263a23fe78a49163f0e798efc349ca89e (patch)
tree070167129b99a3b7f5642ccbe84ee36b7a7d31d2 /openpgp/src/crypto/keygrip.rs
parent86806951896d44a40b30ad4b10d2ea87c6140e45 (diff)
openpgp: Implement FromStr for some types.
- This implements std::str::FromStr for types that have string-representations and are reasonably likely to be encountered by downstream users, e.g. fingerprints or messages. This allows us to do `"xxx".parse()?`. - Fixes #320.
Diffstat (limited to 'openpgp/src/crypto/keygrip.rs')
-rw-r--r--openpgp/src/crypto/keygrip.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/openpgp/src/crypto/keygrip.rs b/openpgp/src/crypto/keygrip.rs
index 9bf4bf5b..66240b92 100644
--- a/openpgp/src/crypto/keygrip.rs
+++ b/openpgp/src/crypto/keygrip.rs
@@ -29,6 +29,14 @@ impl fmt::Display for Keygrip {
}
}
+impl std::str::FromStr for Keygrip {
+ type Err = failure::Error;
+
+ fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
+ Self::from_hex(s)
+ }
+}
+
impl Keygrip {
/// Parses a keygrip.
pub fn from_hex(hex: &str) -> Result<Self> {