pub struct PublicKey(/* private fields */);Expand description
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn from_bytes(key: &[u8]) -> Result<PublicKey, EllipticCurveError>
pub fn from_bytes(key: &[u8]) -> Result<PublicKey, EllipticCurveError>
Parses a compressed (67-byte) or uncompressed (133-byte) SEC1 encoding.
Returns EllipticCurveError::InvalidKey when the encoding is not a
valid point on the P-521 curve.
Sourcepub fn from_x_y(
x_bytes: &[u8; 66],
y_bytes: &[u8; 66],
) -> Result<PublicKey, EllipticCurveError>
pub fn from_x_y( x_bytes: &[u8; 66], y_bytes: &[u8; 66], ) -> Result<PublicKey, EllipticCurveError>
Builds a public key from raw affine x and y coordinates (both
big-endian, 66 bytes each). Returns InvalidKey if the coordinates
are not a valid point on the P-521 curve.
This is useful when importing keys from formats like JWK where x
and y are available directly.
Sourcepub fn verify(
&self,
message: &[u8],
signature: &[u8; 132],
) -> Result<(), EllipticCurveError>
pub fn verify( &self, message: &[u8], signature: &[u8; 132], ) -> Result<(), EllipticCurveError>
Verifies an ECDSA signature over message using SHA-512.
Both canonical low-s and non-canonical high-s signatures are accepted,
matching typical ECDSA interoperability. Use Self::verify_strict to
additionally reject high-s signatures.
Sourcepub fn verify_strict(
&self,
message: &[u8],
signature: &[u8; 132],
) -> Result<(), EllipticCurveError>
pub fn verify_strict( &self, message: &[u8], signature: &[u8; 132], ) -> Result<(), EllipticCurveError>
Verifies an ECDSA signature over message using SHA-512, additionally
rejecting non-canonical high-s signatures (s > n / 2).
Use this when signature malleability must be excluded (Bitcoin/EIP-2
style). Note that some third-party signers emit high-s signatures, which
this method will reject; Self::verify accepts both forms.
Sourcepub fn to_bytes(&self) -> [u8; 133]
pub fn to_bytes(&self) -> [u8; 133]
Returns the 133-byte uncompressed SEC1 encoding (0x04 || x || y).
Sourcepub fn to_compressed_bytes(&self) -> [u8; 67]
pub fn to_compressed_bytes(&self) -> [u8; 67]
Returns the 67-byte compressed SEC1 encoding (0x02/0x03 || x).