```
#[non_exhaustive]
pub enum PublicKey {
RSA {
e: MPI,
n: MPI,
},
DSA {
p: MPI,
q: MPI,
g: MPI,
y: MPI,
},
ElGamal {
p: MPI,
g: MPI,
y: MPI,
},
EdDSA {
curve: Curve,
q: MPI,
},
ECDSA {
curve: Curve,
q: MPI,
},
ECDH {
curve: Curve,
q: MPI,
hash: HashAlgorithm,
sym: SymmetricAlgorithm,
},
Unknown {
mpis: Box<[MPI]>,
rest: Box<[u8]>,
},
}
```

## Expand description

A public key.

Provides a typed and structured way of storing multiple MPIs (and
the occasional elliptic curve) in `Key`

packets.

Note: This enum cannot be exhaustively matched to allow future extensions.

## Variants (Non-exhaustive)

## This enum is marked as non-exhaustive

`RSA`

RSA public key.

`DSA`

#### Fields

`p: MPI`

Prime of the ring Zp.

`q: MPI`

Order of `g`

in Zp.

`g: MPI`

Public generator of Zp.

`y: MPI`

Public key g^x mod p.

NIST DSA public key.

`ElGamal`

ElGamal public key.

`EdDSA`

DJB’s “Twisted” Edwards curve DSA public key.

`ECDSA`

NIST’s Elliptic Curve DSA public key.

`ECDH`

#### Fields

`curve: Curve`

Curve we’re using.

`q: MPI`

Public point.

`hash: HashAlgorithm`

Algorithm used to derive the Key Encapsulation Key.

`sym: SymmetricAlgorithm`

Algorithm used to encapsulate the session key.

Elliptic Curve Diffie-Hellman public key.

`Unknown`

Unknown number of MPIs for an unknown algorithm.

## Implementations

source### impl PublicKey

### impl PublicKey

source#### pub fn bits(&self) -> Option<usize>

#### pub fn bits(&self) -> Option<usize>

Returns the length of the public key in bits.

For finite field crypto this returns the size of the field we
operate in, for ECC it returns `Curve::bits()`

.

Note: This information is useless and should not be used to gauge the security of a particular key. This function exists only because some legacy PGP application like HKP need it.

Returns `None`

for unknown keys and curves.

source#### pub fn algo(&self) -> Option<PublicKeyAlgorithm>

#### pub fn algo(&self) -> Option<PublicKeyAlgorithm>

Returns, if known, the public-key algorithm for this public key.

source### impl PublicKey

### impl PublicKey

source#### pub fn parse<R: Read + Send + Sync>(

algo: PublicKeyAlgorithm,

reader: R

) -> Result<Self>

#### pub fn parse<R: Read + Send + Sync>(

algo: PublicKeyAlgorithm,

reader: R

) -> Result<Self>

Parses a set of OpenPGP MPIs representing a public key.

See Section 3.2 of RFC 4880 for details.

## Trait Implementations

source### impl MarshalInto for PublicKey

### impl MarshalInto for PublicKey

source#### fn serialized_len(&self) -> usize

#### fn serialized_len(&self) -> usize

Computes the maximal length of the serialized representation. Read more

source#### fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>

#### fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>

Serializes into the given buffer. Read more

source### impl Ord for PublicKey

### impl Ord for PublicKey

source### impl PartialOrd<PublicKey> for PublicKey

### impl PartialOrd<PublicKey> for PublicKey

source#### fn partial_cmp(&self, other: &PublicKey) -> Option<Ordering>

#### fn partial_cmp(&self, other: &PublicKey) -> Option<Ordering>

This method returns an ordering between `self`

and `other`

values if one exists. Read more

1.0.0 · source#### fn lt(&self, other: &Rhs) -> bool

#### fn lt(&self, other: &Rhs) -> bool

This method tests less than (for `self`

and `other`

) and is used by the `<`

operator. Read more

1.0.0 · source#### fn le(&self, other: &Rhs) -> bool

#### fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for `self`

and `other`

) and is used by the `<=`

operator. Read more

### impl Eq for PublicKey

### impl StructuralEq for PublicKey

### impl StructuralPartialEq for PublicKey

## Auto Trait Implementations

### impl RefUnwindSafe for PublicKey

### impl Send for PublicKey

### impl Sync for PublicKey

### impl Unpin for PublicKey

### impl UnwindSafe for PublicKey

## Blanket Implementations

source### impl<T> BorrowMut<T> for T where

T: ?Sized,

### impl<T> BorrowMut<T> for T where

T: ?Sized,

const: unstable · source#### pub fn borrow_mut(&mut self) -> &mut T

#### pub fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more

source### impl<T> ToOwned for T where

T: Clone,

### impl<T> ToOwned for T where

T: Clone,

#### type Owned = T

#### type Owned = T

The resulting type after obtaining ownership.

source#### pub fn to_owned(&self) -> T

#### pub fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more

source#### pub fn clone_into(&self, target: &mut T)

#### pub fn clone_into(&self, target: &mut T)

`toowned_clone_into`

)Uses borrowed data to replace owned data, usually by cloning. Read more