diff options
-rw-r--r-- | openpgp/src/crypto/keygrip.rs | 8 | ||||
-rw-r--r-- | openpgp/src/fingerprint.rs | 8 | ||||
-rw-r--r-- | openpgp/src/keyid.rs | 8 | ||||
-rw-r--r-- | openpgp/src/message/mod.rs | 8 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 8 | ||||
-rw-r--r-- | openpgp/src/tpk/mod.rs | 8 | ||||
-rw-r--r-- | store/src/lib.rs | 12 |
7 files changed, 54 insertions, 6 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> { diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs index 9c4a57cf..a12ec118 100644 --- a/openpgp/src/fingerprint.rs +++ b/openpgp/src/fingerprint.rs @@ -18,6 +18,14 @@ impl fmt::Debug for Fingerprint { } } +impl std::str::FromStr for Fingerprint { + type Err = failure::Error; + + fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { + Self::from_hex(s) + } +} + impl Fingerprint { /// Reads a binary fingerprint. pub fn from_bytes(raw: &[u8]) -> Fingerprint { diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index 799bf4fd..2e77c962 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -20,6 +20,14 @@ impl fmt::Debug for KeyID { } } +impl std::str::FromStr for KeyID { + type Err = failure::Error; + + fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { + Self::from_hex(s) + } +} + impl From<KeyID> for Vec<u8> { fn from(id: KeyID) -> Self { let mut r = Vec::with_capacity(8); diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index d36ddb3c..30f8268d 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -338,6 +338,14 @@ impl<'a> Parse<'a, Message> for Message { } } +impl std::str::FromStr for Message { + type Err = failure::Error; + + fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { + Self::from_bytes(s.as_bytes()) + } +} + impl Message { /// Converts the `PacketPile` to a `Message`. /// diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index e14a541d..275c0dba 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -64,6 +64,14 @@ impl<'a> Parse<'a, PacketPile> for PacketPile { } } +impl std::str::FromStr for PacketPile { + type Err = failure::Error; + + fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { + Self::from_bytes(s.as_bytes()) + } +} + impl From<Vec<Packet>> for PacketPile { fn from(p: Vec<Packet>) -> Self { PacketPile { top_level: Container { packets: p } } diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs index fb1ae43e..29f59da2 100644 --- a/openpgp/src/tpk/mod.rs +++ b/openpgp/src/tpk/mod.rs @@ -368,6 +368,14 @@ impl<'a> Parse<'a, TPKParser<'a, vec::IntoIter<Packet>>> } } +impl std::str::FromStr for TPK { + type Err = failure::Error; + + fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { + Self::from_bytes(s.as_bytes()) + } +} + impl<'a, I: Iterator<Item=Packet>> TPKParser<'a, I> { /// Initializes a TPKParser from an iterator over Packets. pub fn from_iter(iter: I) -> Self { diff --git a/store/src/lib.rs b/store/src/lib.rs index 2dd00361..54fc8661 100644 --- a/store/src/lib.rs +++ b/store/src/lib.rs @@ -251,19 +251,19 @@ impl Pool { /// Pool::import(&ctx, &tpk)?; /// /// // Lookup by the primary key's KeyID. - /// let key = Pool::lookup_by_subkeyid(&ctx, &KeyID::from_hex("AACB3243630052D9")?)?; + /// let key = Pool::lookup_by_subkeyid(&ctx, &"AACB3243630052D9".parse()?)?; /// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint()); /// /// // Lookup by the signing subkey's KeyID. - /// let key = Pool::lookup_by_subkeyid(&ctx, &KeyID::from_hex("7223B56678E02528")?)?; + /// let key = Pool::lookup_by_subkeyid(&ctx, &"7223B56678E02528".parse()?)?; /// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint()); /// /// // Lookup by the encryption subkey's KeyID. - /// let key = Pool::lookup_by_subkeyid(&ctx, &KeyID::from_hex("C2B819056C652598")?)?; + /// let key = Pool::lookup_by_subkeyid(&ctx, &"C2B819056C652598".parse()?)?; /// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint()); /// /// // Lookup by the authentication subkey's KeyID. - /// let key = Pool::lookup_by_subkeyid(&ctx, &KeyID::from_hex("A3506AFB820ABD08")?)?; + /// let key = Pool::lookup_by_subkeyid(&ctx, &"A3506AFB820ABD08".parse()?)?; /// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint()); /// # Ok(()) /// # } @@ -490,12 +490,12 @@ impl Store { /// store.import("Emmelie", &tpk)?; /// /// // Lookup by the primary key's KeyID. - /// let tpk_ = store.lookup_by_subkeyid(&KeyID::from_hex("069C0C348DD82C19")?)? + /// let tpk_ = store.lookup_by_subkeyid(&"069C0C348DD82C19".parse()?)? /// .tpk()?; /// assert_eq!(tpk, tpk_); /// /// // Lookup by the subkey's KeyID. - /// let tpk_ = store.lookup_by_subkeyid(&KeyID::from_hex("22E3FAFE96B56C32")?)? + /// let tpk_ = store.lookup_by_subkeyid(&"22E3FAFE96B56C32".parse()?)? /// .tpk()?; /// assert_eq!(tpk, tpk_); /// # Ok(()) |