diff --git a/ssh-key/src/private.rs b/ssh-key/src/private.rs index 23c4d5f7e..922e9f077 100644 --- a/ssh-key/src/private.rs +++ b/ssh-key/src/private.rs @@ -26,6 +26,7 @@ use crate::{ base64::{self, Decode}, public, Algorithm, CipherAlg, Error, KdfAlg, KdfOptions, Result, }; +use core::str::FromStr; #[cfg(feature = "alloc")] use alloc::string::String; @@ -126,6 +127,14 @@ impl PrivateKey { } } +impl FromStr for PrivateKey { + type Err = Error; + + fn from_str(s: &str) -> Result { + Self::from_openssh(s) + } +} + /// Private key data. #[derive(Clone, Debug)] #[non_exhaustive] diff --git a/ssh-key/src/public.rs b/ssh-key/src/public.rs index 224062bde..e6f72654a 100644 --- a/ssh-key/src/public.rs +++ b/ssh-key/src/public.rs @@ -21,6 +21,7 @@ use crate::{ base64::{self, Decode}, Algorithm, Error, Result, }; +use core::str::FromStr; #[cfg(feature = "alloc")] use alloc::{borrow::ToOwned, string::String}; @@ -72,6 +73,14 @@ impl PublicKey { } } +impl FromStr for PublicKey { + type Err = Error; + + fn from_str(s: &str) -> Result { + Self::from_openssh(s) + } +} + /// Public key data. #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] #[non_exhaustive]