Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
tarcieri committed Aug 4, 2020
commit 15df37bd662c521bd8747678bb03efef8e4b5243
19 changes: 19 additions & 0 deletions elliptic-curve/src/weierstrass/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use generic_array::{
typenum::{Unsigned, U1},
ArrayLength, GenericArray,
};
use subtle::CtOption;

/// Size of an untagged point for given elliptic curve.
pub type UntaggedPointSize<C> = <<C as crate::Curve>::ElementSize as Add>::Output;
Expand Down Expand Up @@ -206,3 +207,21 @@ where
PublicKey::Uncompressed(point)
}
}

/// Trait for deserializing a value from a public key.
///
/// This is intended for use with the `AffinePoint` type for a given elliptic curve.
pub trait FromPublicKey<C: Curve>: Sized
where
C::ElementSize: Add<U1>,
<C::ElementSize as Add>::Output: Add<U1>,
CompressedPointSize<C>: ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
/// Deserialize this value from a [`PublicKey`]
///
/// # Returns
///
/// `None` if the public key is not on the curve.
fn from_public_key(public_key: &PublicKey<C>) -> CtOption<Self>;
}