Skip to content

Commit 36f2805

Browse files
committed
Implement SigningKey::from_pem
1 parent ad60042 commit 36f2805

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

ecdsa/src/signing.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,33 @@ where
124124
}
125125
}
126126

127+
#[cfg(feature = "pem")]
128+
impl<C> SigningKey<C>
129+
where
130+
C: EcdsaCurve + AssociatedOid + CurveArithmetic,
131+
AffinePoint<C>: FromSec1Point<C> + ToSec1Point<C>,
132+
FieldBytesSize<C>: sec1::ModulusSize,
133+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
134+
SignatureSize<C>: ArraySize,
135+
{
136+
#[inline]
137+
/// Parse [`SigningKey`] from PEM-encoded private key.
138+
///
139+
/// Supported formats:
140+
/// - `SEC1` - requires feature `sec1`
141+
/// - `PKCS#8` - requires feature `pkcs8`
142+
///
143+
/// # Errors
144+
/// - If `pem` is not valid PEM encoded private key
145+
/// - If label within `pem` is not known valid label
146+
/// - If label is valid, but unable to decode DER content of the PEM file
147+
pub fn from_pem(
148+
pem: &str,
149+
) -> ::core::result::Result<Self, impl core::error::Error + Send + Sync + 'static> {
150+
SecretKey::<C>::from_pem(pem).map(Into::into)
151+
}
152+
}
153+
127154
impl<C> Generate for SigningKey<C>
128155
where
129156
C: EcdsaCurve + CurveArithmetic,

0 commit comments

Comments
 (0)