diff --git a/ecdsa/src/sign.rs b/ecdsa/src/sign.rs index 3dacc160..979fcbd9 100644 --- a/ecdsa/src/sign.rs +++ b/ecdsa/src/sign.rs @@ -74,6 +74,22 @@ where Ok(Self { inner }) } + /// Serialize this [`SigningKey`] as bytes + pub fn to_bytes(&self) -> FieldBytes { + self.inner.to_repr() + } + + /// Borrow the secret [`NonZeroScalar`] value for this key. + /// + /// # ⚠️ Warning + /// + /// This value is key material. + /// + /// Please treat it with the care it deserves! + pub fn as_nonzero_scalar(&self) -> &NonZeroScalar { + &self.inner + } + /// Get the [`VerifyingKey`] which corresponds to this [`SigningKey`] #[cfg(feature = "verify")] #[cfg_attr(docsrs, doc(cfg(feature = "verify")))] @@ -82,11 +98,6 @@ where inner: PublicKey::from_secret_scalar(&self.inner), } } - - /// Serialize this [`SigningKey`] as bytes - pub fn to_bytes(&self) -> FieldBytes { - self.inner.to_repr() - } } impl ConstantTimeEq for SigningKey diff --git a/ecdsa/src/verify.rs b/ecdsa/src/verify.rs index db167947..7c7bf637 100644 --- a/ecdsa/src/verify.rs +++ b/ecdsa/src/verify.rs @@ -84,6 +84,22 @@ where pub fn to_encoded_point(&self, compress: bool) -> EncodedPoint { self.inner.to_encoded_point(compress) } + + /// Borrow the inner [`AffinePoint`] for this public key. + pub fn as_affine(&self) -> &AffinePoint { + self.inner.as_affine() + } +} + +impl AsRef> for VerifyingKey +where + C: PrimeCurve + ProjectiveArithmetic, + AffinePoint: FromEncodedPoint + ToEncodedPoint, + FieldSize: sec1::ModulusSize, +{ + fn as_ref(&self) -> &AffinePoint { + self.as_affine() + } } impl Copy for VerifyingKey where C: PrimeCurve + ProjectiveArithmetic {}