From 36f28054714f58a3c70b39869b0b55e6ece4a0bb Mon Sep 17 00:00:00 2001 From: DoumanAsh Date: Mon, 11 May 2026 13:08:51 +0900 Subject: [PATCH] Implement SigningKey::from_pem --- ecdsa/src/signing.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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,