diff --git a/ecdsa/src/signing.rs b/ecdsa/src/signing.rs index 922b092d..de28edd2 100644 --- a/ecdsa/src/signing.rs +++ b/ecdsa/src/signing.rs @@ -124,6 +124,33 @@ where } } +#[cfg(feature = "pem")] +impl SigningKey +where + C: EcdsaCurve + AssociatedOid + CurveArithmetic, + AffinePoint: FromSec1Point + ToSec1Point, + FieldBytesSize: sec1::ModulusSize, + Scalar: Invert>>, + SignatureSize: ArraySize, +{ + #[inline] + /// Parse [`SigningKey`] from PEM-encoded private key. + /// + /// Supported formats: + /// - `SEC1` - requires feature `sec1` + /// - `PKCS#8` - requires feature `pkcs8` + /// + /// # Errors + /// - If `pem` is not valid PEM encoded private key + /// - If label within `pem` is not known valid label + /// - If label is valid, but unable to decode DER content of the PEM file + pub fn from_pem( + pem: &str, + ) -> ::core::result::Result { + SecretKey::::from_pem(pem).map(Into::into) + } +} + impl Generate for SigningKey where C: EcdsaCurve + CurveArithmetic,