pub struct PublicKey { /* private fields */ }
Expand description

SSH public key.

OpenSSH encoding

The OpenSSH encoding of an SSH public key looks like following:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILM+rvN+ot98qgEN796jTiQfZfG1KaT0PtFDJ/XFSqti user@example.com

It consists of the following three parts:

  1. Algorithm identifier (in this example ssh-ed25519)
  2. Key data encoded as Base64
  3. Comment (optional): arbitrary label describing a key. Usually an email address

The PublicKey::from_openssh and PublicKey::to_openssh methods can be used to decode/encode public keys, or alternatively, the FromStr and ToString impls.

serde support

When the serde feature of this crate is enabled, this type receives impls of Deserialize and Serialize.

The serialization uses a binary encoding with binary formats like bincode and CBOR, and the OpenSSH string serialization when used with human-readable formats like JSON and TOML.

Implementations

Available on crate feature alloc only.

Create a new public key with the given comment.

On no_std platforms, use PublicKey::from(key_data) instead.

Parse an OpenSSH-formatted public key.

OpenSSH-formatted public keys look like the following:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILM+rvN+ot98qgEN796jTiQfZfG1KaT0PtFDJ/XFSqti foo@bar.com

Parse a raw binary SSH public key.

Encode OpenSSH-formatted public key.

Available on crate feature alloc only.

Encode an OpenSSH-formatted public key, allocating a String for the result.

Available on crate feature alloc only.

Serialize SSH public key as raw bytes.

Available on crate feature alloc only.

Verify the SshSig signature over the given message using this public key.

These signatures can be produced using ssh-keygen -Y sign. They’re encoded as PEM and begin with the following:

-----BEGIN SSH SIGNATURE-----

See PROTOCOL.sshsig for more information.

Available on crate feature std only.

Read public key from an OpenSSH-formatted file.

Available on crate feature std only.

Write public key as an OpenSSH-formatted file.

Get the digital signature Algorithm used by this key.

Comment on the key (e.g. email address).

Private key data.

Compute key fingerprint.

Use Default::default() to use the default hash function (SHA-256).

Available on crate feature alloc only.

Set the comment on the key.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
source

impl From<PublicKey> for Entry

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more
Converts the given value to a String. Read more
Use Self to verify that the provided signature for a given message bytestring is authentic. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.