Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,23 @@ pub mod sign;
pub mod verify;

// Re-export the `elliptic-curve` crate (and select types)
pub use elliptic_curve::{self, generic_array, sec1::EncodedPoint, weierstrass::Curve, SecretKey};
pub use elliptic_curve::{self, generic_array, sec1::EncodedPoint, weierstrass::Curve};

// Re-export the `signature` crate (and select types)
pub use signature::{self, Error};

#[cfg(feature = "sign")]
#[cfg_attr(docsrs, doc(cfg(feature = "sign")))]
pub use sign::SigningKey;

#[cfg(feature = "verify")]
#[cfg_attr(docsrs, doc(cfg(feature = "verify")))]
pub use verify::VerifyKey;

#[cfg(feature = "zeroize")]
#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))]
pub use elliptic_curve::SecretKey;

use core::{
convert::{TryFrom, TryInto},
fmt::{self, Debug},
Expand Down
19 changes: 13 additions & 6 deletions ecdsa/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ where
.ok_or_else(Error::new)
}

/// Create a new signing key from a [`SecretKey`].
// TODO(tarcieri): infallible `From` conversion from a secret key
pub fn from_secret_key(secret_key: &SecretKey<C>) -> Result<Self, Error> {
Self::new(secret_key.as_bytes())
}

/// Get the [`VerifyKey`] which corresponds to this [`SigningKey`]
#[cfg(feature = "verify")]
#[cfg_attr(docsrs, doc(cfg(feature = "verify")))]
Expand All @@ -78,6 +72,19 @@ where
}
}

impl<C> From<&SecretKey<C>> for SigningKey<C>
where
C: Curve + Arithmetic,
C::Scalar: FromDigest<C> + Invert<Output = C::Scalar> + SignPrimitive<C> + Zeroize,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(secret_key: &SecretKey<C>) -> Self {
Self {
secret_scalar: *secret_key.secret_scalar(),
}
}
}

impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>
where
C: Curve + Arithmetic,
Expand Down