From 14ff892817feee95345c985ea18dde723395f2e8 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 30 Jan 2026 19:46:37 -0700 Subject: [PATCH] elliptic-curve: add `From for PublicKey` impls Surprised these didn't exist already --- elliptic-curve/src/public_key.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/elliptic-curve/src/public_key.rs b/elliptic-curve/src/public_key.rs index 2e3906a7e..251089eb8 100644 --- a/elliptic-curve/src/public_key.rs +++ b/elliptic-curve/src/public_key.rs @@ -2,7 +2,7 @@ use crate::{ AffinePoint, CurveArithmetic, CurveGroup, Error, NonZeroScalar, ProjectivePoint, Result, - point::NonIdentity, + SecretKey, point::NonIdentity, }; use core::fmt::Debug; use group::Group; @@ -293,6 +293,24 @@ where } } +impl From> for PublicKey +where + C: CurveArithmetic, +{ + fn from(secret_key: SecretKey) -> Self { + secret_key.public_key() + } +} + +impl From<&SecretKey> for PublicKey +where + C: CurveArithmetic, +{ + fn from(secret_key: &SecretKey) -> PublicKey { + secret_key.public_key() + } +} + #[cfg(feature = "sec1")] impl PartialOrd for PublicKey where