pub struct PublicKey<C: Curve> { /* private fields */ }Expand description
An ECDSA public key over the given curve.
Implementations§
Source§impl<C: Curve> PublicKey<C>
impl<C: Curve> PublicKey<C>
Sourcepub fn from_x962_uncompressed(x962: &[u8]) -> Option<Self>
pub fn from_x962_uncompressed(x962: &[u8]) -> Option<Self>
Parse a public key in uncompressed X9.62 format. (This is the common format for elliptic curve points beginning with an 0x04 byte.)
Sourcepub fn to_x962_uncompressed(&self) -> Buffer
pub fn to_x962_uncompressed(&self) -> Buffer
Serialize this key as uncompressed X9.62 format.
Sourcepub fn from_x962_compressed(x962: &[u8]) -> Option<Self>
pub fn from_x962_compressed(x962: &[u8]) -> Option<Self>
Parse a public key in compressed X9.62 point format.
Sourcepub fn to_x962_compressed(&self) -> Buffer
pub fn to_x962_compressed(&self) -> Buffer
Serialize this key as compressed X9.62 format.
WARNING: compressed form is rarely used and is not as well supported as the uncompressed form.
Sourcepub fn from_der_subject_public_key_info(spki: &[u8]) -> Option<Self>
pub fn from_der_subject_public_key_info(spki: &[u8]) -> Option<Self>
Parse a public key in SubjectPublicKeyInfo format. (This is found in, e.g., X.509 certificates.)
Sourcepub fn to_der_subject_public_key_info(&self) -> Buffer
pub fn to_der_subject_public_key_info(&self) -> Buffer
Serialize this key in SubjectPublicKeyInfo format.
Sourcepub fn verify(
&self,
signed_msg: &[u8],
signature: &[u8],
) -> Result<(), InvalidSignatureError>
pub fn verify( &self, signed_msg: &[u8], signature: &[u8], ) -> Result<(), InvalidSignatureError>
Verify signature as a valid ASN.1-based signature of a digest of
signed_msg with this public key. SHA-256 will be used to produce the
digest if the curve of this public key is P-256. SHA-384 will be used to
produce the digest if the curve of this public key is P-384.
Sourcepub fn verify_already_hashed(
&self,
hashed_msg: &[u8],
signature: &[u8],
) -> Result<(), InvalidSignatureError>
pub fn verify_already_hashed( &self, hashed_msg: &[u8], signature: &[u8], ) -> Result<(), InvalidSignatureError>
Verify signature as a valid ASN.1-based signature of hashed_msg with
this public key. hashed_msg must already have been hashed with a
secure hash function: passing unhashed data here breaks the security
properties of the signature scheme. If you have unhashed data, use
verify instead.
This function exists because sometimes the “wrong” hash function is used with a key. A key should not be used with different hash functions and there is an obvious correspondence between NIST’s standard elliptic curves and the SHA-2 family of hash functions that implicitly defines the correct hash function to use with a given key. But, if mistakes have been made, this function is here for you.
Sourcepub fn verify_p1363(
&self,
signed_msg: &[u8],
signature: &[u8],
) -> Result<(), InvalidSignatureError>
pub fn verify_p1363( &self, signed_msg: &[u8], signature: &[u8], ) -> Result<(), InvalidSignatureError>
Verify signature as a valid P1363-based signature of a digest of
signed_msg with this public key. SHA-256 will be used to produce the
digest if the curve of this public key is P-256. SHA-384 will be used to
produce the digest if the curve of this public key is P-384.