Skip to content

Commit b380788

Browse files
committed
Implement SigningKey::from_pem
1 parent f467f70 commit b380788

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecdsa/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ edition = "2024"
1717
rust-version = "1.85"
1818

1919
[dependencies]
20-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["sec1"] }
20+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["sec1"] }
2121
signature = { version = "3.0.0-rc.10", default-features = false, features = ["rand_core"] }
2222
zeroize = { version = "1.5", default-features = false }
2323

@@ -30,7 +30,7 @@ sha2 = { version = "0.11", optional = true, default-features = false, features =
3030
spki = { version = "0.8", optional = true, default-features = false }
3131

3232
[dev-dependencies]
33-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["dev"] }
33+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["dev"] }
3434
hex-literal = "1"
3535
sha2 = { version = "0.11", default-features = false }
3636

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+
impl<C> SigningKey<C>
128+
where
129+
C: EcdsaCurve + AssociatedOid + CurveArithmetic,
130+
AffinePoint<C>: FromSec1Point<C> + ToSec1Point<C>,
131+
FieldBytesSize<C>: sec1::ModulusSize,
132+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
133+
SignatureSize<C>: ArraySize,
134+
{
135+
#[inline]
136+
#[cfg(feature = "pem")]
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)