Skip to content

Commit 15df37b

Browse files
committed
elliptic-curve: add back FromPublicKey trait
It seems this was a bit too hastily removed in #247. It's worth keeping around for now as it handles the variable sizes of SEC-1 keys.
1 parent 4554cdc commit 15df37b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

elliptic-curve/src/weierstrass/public_key.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use generic_array::{
1616
typenum::{Unsigned, U1},
1717
ArrayLength, GenericArray,
1818
};
19+
use subtle::CtOption;
1920

2021
/// Size of an untagged point for given elliptic curve.
2122
pub type UntaggedPointSize<C> = <<C as crate::Curve>::ElementSize as Add>::Output;
@@ -206,3 +207,21 @@ where
206207
PublicKey::Uncompressed(point)
207208
}
208209
}
210+
211+
/// Trait for deserializing a value from a public key.
212+
///
213+
/// This is intended for use with the `AffinePoint` type for a given elliptic curve.
214+
pub trait FromPublicKey<C: Curve>: Sized
215+
where
216+
C::ElementSize: Add<U1>,
217+
<C::ElementSize as Add>::Output: Add<U1>,
218+
CompressedPointSize<C>: ArrayLength<u8>,
219+
UncompressedPointSize<C>: ArrayLength<u8>,
220+
{
221+
/// Deserialize this value from a [`PublicKey`]
222+
///
223+
/// # Returns
224+
///
225+
/// `None` if the public key is not on the curve.
226+
fn from_public_key(public_key: &PublicKey<C>) -> CtOption<Self>;
227+
}

0 commit comments

Comments
 (0)