Struct elliptic_curve::PublicKey
source · [−]pub struct PublicKey<C> where
C: Curve + ProjectiveArithmetic, { /* private fields */ }
arithmetic
only.Expand description
Elliptic curve public keys.
This is a wrapper type for AffinePoint
which ensures an inner
non-identity point and provides a common place to handle encoding/decoding.
Parsing “SPKI” Keys
X.509 SubjectPublicKeyInfo
(SPKI) is a commonly used format for encoding
public keys, notably public keys corresponding to PKCS#8 private keys.
(especially ones generated by OpenSSL).
Keys in SPKI format are either binary (ASN.1 BER/DER), or PEM encoded (ASCII) and begin with the following:
-----BEGIN PUBLIC KEY-----
To decode an elliptic curve public key from SPKI, enable the pkcs8
feature of this crate (or the pkcs8
feature of a specific RustCrypto
elliptic curve crate) and use the
elliptic_curve::pkcs8::DecodePublicKey
trait to parse it.
When the pem
feature of this crate (or a specific RustCrypto elliptic
curve crate) is enabled, a FromStr
impl is also available.
serde
support
When the optional serde
feature of this create is enabled, Serialize
and Deserialize
impls are provided for this type.
The serialization is binary-oriented and supports ASN.1 DER Subject Public Key Info (SPKI) as the encoding format.
For a more text-friendly encoding of public keys, use JwkEcKey
instead.
Implementations
Convert an AffinePoint
into a PublicKey
Compute a PublicKey
from a secret NonZeroScalar
value
(i.e. a secret key represented as a raw scalar value)
pub fn from_sec1_bytes(bytes: &[u8]) -> Result<Self> where
C: Curve,
FieldSize<C>: ModulusSize,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
pub fn from_sec1_bytes(bytes: &[u8]) -> Result<Self> where
C: Curve,
FieldSize<C>: ModulusSize,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Decode PublicKey
(compressed or uncompressed) from the
Elliptic-Curve-Point-to-Octet-String
encoding described in
SEC 1: Elliptic Curve Cryptography (Version 2.0) section
2.3.3 (page 10).
Borrow the inner AffinePoint
from this PublicKey
.
In ECC, public keys are elliptic curve points.
Convert this PublicKey
to a ProjectivePoint
for the given curve
pub fn from_jwk(jwk: &JwkEcKey) -> Result<Self> where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
pub fn from_jwk(jwk: &JwkEcKey) -> Result<Self> where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.pub fn from_jwk_str(jwk: &str) -> Result<Self> where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
pub fn from_jwk_str(jwk: &str) -> Result<Self> where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.Parse a string containing a JSON Web Key (JWK) into a PublicKey
.
pub fn to_jwk(&self) -> JwkEcKey where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
pub fn to_jwk(&self) -> JwkEcKey where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.Serialize this public key as JwkEcKey
JSON Web Key (JWK).
pub fn to_jwk_string(&self) -> String where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
pub fn to_jwk_string(&self) -> String where
C: Curve + JwkParameters,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.Serialize this public key as JSON Web Key (JWK) string.
Trait Implementations
impl<C> AsRef<<C as AffineArithmetic>::AffinePoint> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
impl<C> AsRef<<C as AffineArithmetic>::AffinePoint> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
Performs the conversion.
impl<C> DecodePublicKey for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate features pkcs8
and sec1
only.
impl<C> DecodePublicKey for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
pkcs8
and sec1
only.Deserialize object from ASN.1 DER-encoded SubjectPublicKeyInfo
(binary format). Read more
Deserialize SPKI public key from a PublicKeyDocument
.
Deserialize PEM-encoded SubjectPublicKeyInfo
. Read more
impl<'de, C> Deserialize<'de> for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate features pem
and serde
only.
impl<'de, C> Deserialize<'de> for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
pem
and serde
only.Deserialize this value from the given Serde deserializer. Read more
impl<C> EncodePublicKey for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature pem
only.
impl<C> EncodePublicKey for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
pem
only.Serialize a PublicKeyDocument
containing a SPKI-encoded public key.
Serialize this public key as PEM-encoded SPKI with the given LineEnding
.
impl<C> From<&'_ EphemeralSecret<C>> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
This is supported on crate feature ecdh
only.
impl<C> From<&'_ EphemeralSecret<C>> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
ecdh
only.Performs the conversion.
impl<C> From<&'_ PublicKey<C>> for EncodedPoint<C> where
C: Curve + ProjectiveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature sec1
only.
impl<C> From<&'_ PublicKey<C>> for EncodedPoint<C> where
C: Curve + ProjectiveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
sec1
only.Performs the conversion.
impl<C> From<&'_ PublicKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
impl<C> From<&'_ PublicKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.impl<C> From<PublicKey<C>> for EncodedPoint<C> where
C: Curve + ProjectiveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature sec1
only.
impl<C> From<PublicKey<C>> for EncodedPoint<C> where
C: Curve + ProjectiveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
sec1
only.Performs the conversion.
impl<C> From<PublicKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
impl<C> From<PublicKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.impl<C> FromEncodedPoint<C> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature sec1
only.
impl<C> FromEncodedPoint<C> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
sec1
only.Initialize PublicKey
from an EncodedPoint
impl<C> FromStr for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature pem
only.
impl<C> FromStr for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
pem
only.impl<C> Ord for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature sec1
only.
impl<C> Ord for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
sec1
only.impl<C> PartialOrd<PublicKey<C>> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature sec1
only.
impl<C> PartialOrd<PublicKey<C>> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
sec1
only.This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<C> Serialize for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate features pem
and serde
only.
impl<C> Serialize for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
pem
and serde
only.impl<C> ToEncodedPoint<C> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature sec1
only.
impl<C> ToEncodedPoint<C> for PublicKey<C> where
C: Curve + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
sec1
only.Serialize this PublicKey
as a SEC1 EncodedPoint
, optionally applying
point compression
impl<C> ToString for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature pem
only.
impl<C> ToString for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
pem
only.impl<C> TryFrom<&'_ JwkEcKey> for PublicKey<C> where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
impl<C> TryFrom<&'_ JwkEcKey> for PublicKey<C> where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.impl<C> TryFrom<JwkEcKey> for PublicKey<C> where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate feature jwk
only.
impl<C> TryFrom<JwkEcKey> for PublicKey<C> where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
jwk
only.impl<C> TryFrom<SubjectPublicKeyInfo<'_>> for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
This is supported on crate features pkcs8
and sec1
only.
impl<C> TryFrom<SubjectPublicKeyInfo<'_>> for PublicKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: ModulusSize,
pkcs8
and sec1
only.Auto Trait Implementations
impl<C> RefUnwindSafe for PublicKey<C> where
<C as AffineArithmetic>::AffinePoint: RefUnwindSafe,
impl<C> Unpin for PublicKey<C> where
<C as AffineArithmetic>::AffinePoint: Unpin,
impl<C> UnwindSafe for PublicKey<C> where
<C as AffineArithmetic>::AffinePoint: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more