Skip to content

Commit

Permalink
ecdsa: Implement EncodePrivateKey for SigningKey (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra authored Sep 6, 2022
1 parent 6b86268 commit c696de3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ecdsa/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ use crate::elliptic_curve::{
};

#[cfg(feature = "pem")]
use core::str::FromStr;
use {
crate::elliptic_curve::pkcs8::{EncodePrivateKey, SecretDocument},
core::str::FromStr,
};

/// ECDSA signing key. Generic over elliptic curves.
///
Expand Down Expand Up @@ -290,6 +293,22 @@ where
}
}

#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl<C> EncodePrivateKey for SigningKey<C>
where
C: AssociatedOid + PrimeCurve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn to_pkcs8_der(&self) -> pkcs8::Result<SecretDocument> {
let secret_key = SecretKey::new(self.inner.into());
secret_key.to_pkcs8_der()
}
}

#[cfg(feature = "pkcs8")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
impl<C> DecodePrivateKey for SigningKey<C>
Expand Down

0 comments on commit c696de3

Please sign in to comment.