Skip to content

Commit ee2a279

Browse files
authored
elliptic-curve: add From<SecretKey<C>> for PublicKey<C> impls (#2247)
Surprised these didn't exist already
1 parent 176efb8 commit ee2a279

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

elliptic-curve/src/public_key.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
AffinePoint, CurveArithmetic, CurveGroup, Error, NonZeroScalar, ProjectivePoint, Result,
5-
point::NonIdentity,
5+
SecretKey, point::NonIdentity,
66
};
77
use core::fmt::Debug;
88
use group::Group;
@@ -293,6 +293,24 @@ where
293293
}
294294
}
295295

296+
impl<C> From<SecretKey<C>> for PublicKey<C>
297+
where
298+
C: CurveArithmetic,
299+
{
300+
fn from(secret_key: SecretKey<C>) -> Self {
301+
secret_key.public_key()
302+
}
303+
}
304+
305+
impl<C> From<&SecretKey<C>> for PublicKey<C>
306+
where
307+
C: CurveArithmetic,
308+
{
309+
fn from(secret_key: &SecretKey<C>) -> PublicKey<C> {
310+
secret_key.public_key()
311+
}
312+
}
313+
296314
#[cfg(feature = "sec1")]
297315
impl<C> PartialOrd for PublicKey<C>
298316
where

0 commit comments

Comments
 (0)