Skip to content

Commit

Permalink
elliptic-curve: add back From<PublicKey> for EncodedPoint impl (#773
Browse files Browse the repository at this point in the history
)

This was removed in #771 but can still be supported
  • Loading branch information
tarcieri authored Sep 20, 2021
1 parent 5a80783 commit 8a839b1
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion elliptic-curve/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use {core::str::FromStr, pkcs8::ToPublicKey};
use {
crate::{
sec1::{EncodedPoint, FromEncodedPoint, ModulusSize, ToEncodedPoint},
FieldSize, PrimeCurve,
FieldSize, PointCompression, PrimeCurve,
},
core::cmp::Ordering,
};
Expand Down Expand Up @@ -206,6 +206,32 @@ where
}
}

#[cfg(feature = "sec1")]
#[cfg_attr(docsrs, doc(cfg(feature = "sec1")))]
impl<C> From<PublicKey<C>> for EncodedPoint<C>
where
C: PrimeCurve + ProjectiveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
{
fn from(public_key: PublicKey<C>) -> EncodedPoint<C> {
EncodedPoint::<C>::from(&public_key)
}
}

#[cfg(feature = "sec1")]
#[cfg_attr(docsrs, doc(cfg(feature = "sec1")))]
impl<C> From<&PublicKey<C>> for EncodedPoint<C>
where
C: PrimeCurve + ProjectiveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
{
fn from(public_key: &PublicKey<C>) -> EncodedPoint<C> {
public_key.to_encoded_point(C::COMPRESS_POINTS)
}
}

#[cfg(feature = "sec1")]
#[cfg_attr(docsrs, doc(cfg(feature = "sec1")))]
impl<C> PartialOrd for PublicKey<C>
Expand Down

0 comments on commit 8a839b1

Please sign in to comment.