Skip to content

Commit c2c6d17

Browse files
authored
ecdsa: have SigningKey::verifying_key return a reference (#567)
The `SigningKey` is internally a keypair, so callers can borrow the `VerifyingKey`, rather than making a copy.
1 parent 31263d2 commit c2c6d17

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ecdsa/src/sign.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ where
9292
&self.secret_scalar
9393
}
9494

95-
/// Get the [`VerifyingKey`] which corresponds to this [`SigningKey`]
96-
// TODO(tarcieri): make this return `&VerifyingKey<C>` in the next breaking release
95+
/// Get the [`VerifyingKey`] which corresponds to this [`SigningKey`].
9796
#[cfg(feature = "verify")]
9897
#[cfg_attr(docsrs, doc(cfg(feature = "verify")))]
99-
pub fn verifying_key(&self) -> VerifyingKey<C> {
100-
self.verifying_key
98+
pub fn verifying_key(&self) -> &VerifyingKey<C> {
99+
&self.verifying_key
101100
}
102101
}
103102

@@ -350,6 +349,18 @@ where
350349
}
351350
}
352351

352+
#[cfg(feature = "verify")]
353+
impl<C> From<SigningKey<C>> for VerifyingKey<C>
354+
where
355+
C: PrimeCurve + ProjectiveArithmetic,
356+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
357+
SignatureSize<C>: ArrayLength<u8>,
358+
{
359+
fn from(signing_key: SigningKey<C>) -> VerifyingKey<C> {
360+
signing_key.verifying_key
361+
}
362+
}
363+
353364
#[cfg(feature = "verify")]
354365
impl<C> From<&SigningKey<C>> for VerifyingKey<C>
355366
where
@@ -358,7 +369,7 @@ where
358369
SignatureSize<C>: ArrayLength<u8>,
359370
{
360371
fn from(signing_key: &SigningKey<C>) -> VerifyingKey<C> {
361-
signing_key.verifying_key()
372+
signing_key.verifying_key
362373
}
363374
}
364375

0 commit comments

Comments
 (0)