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

SSH private key.

Implementations

Available on crate feature alloc only.

Create a new unencrypted private key with the given keypair data and comment.

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

Parse an OpenSSH-formatted PEM private key.

OpenSSH-formatted private keys begin with the following:

-----BEGIN OPENSSH PRIVATE KEY-----

Parse a raw binary SSH private key.

Encode OpenSSH-formatted (PEM) private key.

Available on crate feature alloc only.

Encode an OpenSSH-formatted PEM private key, allocating a self-zeroizing String for the result.

Available on crate feature alloc only.

Serialize SSH private key as raw bytes.

Available on crate feature alloc only.

Sign the given message using this private key, returning an SshSig.

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 private key from an OpenSSH-formatted PEM file.

Available on crate feature std only.

Write private key as an OpenSSH-formatted PEM file.

Available on crate feature encryption only.

Attempt to decrypt an encrypted private key using the provided password to derive an encryption key.

Returns Error::Decrypted if the private key is already decrypted.

Available on crate feature encryption only.

Encrypt an unencrypted private key using the provided password to derive an encryption key.

Uses the following algorithms:

Returns Error::Encrypted if the private key is already encrypted.

Available on crate feature encryption only.

Encrypt an unencrypted private key using the provided cipher and KDF configuration.

Returns Error::Encrypted if the private key is already encrypted.

Get the digital signature Algorithm used by this key.

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

Cipher algorithm (a.k.a. ciphername).

Compute key fingerprint.

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

Is this key encrypted?

Key Derivation Function (KDF) used to encrypt this key.

Returns Kdf::None if this key is not encrypted.

Keypair data.

Get the PublicKey which corresponds to this private key.

Available on crate feature rand_core only.

Generate a random key which uses the given algorithm.

Returns
  • Error::Algorithm if the algorithm is unsupported.
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
Determine if two items are equal. Read more
Formats the value using the given formatter. Read more
Type returned in the event of a decoding error.
Attempt to decode a value of this type using the provided Reader.
Type returned in the event of an encoding error.
Get the length of this type encoded in bytes, prior to Base64 encoding.
Encode this value using the provided Writer.
Return the length of this type after encoding when prepended with a uint32 length prefix. Read more
Encode this value, first prepending a uint32 length prefix set to Encode::encoded_len. 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.
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 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
Expected PEM type label for a given document, e.g. "PRIVATE KEY"
Validate that a given label matches the expected label.
Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
Sign the given message and return a digital signature
The type returned in the event of a conversion error.
Performs the conversion.

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
Decode the provided PEM-encoded string, interpreting the Base64-encoded body of the document using the Decode trait. Read more
Encode this type using the Encode trait, writing the resulting PEM document into the provided out buffer. Read more
Encode this type using the Encode trait, writing the resulting PEM document to a returned String. 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
Attempt to sign the given message, updating the state, and returning a digital signature on success, or an error if something went wrong. Read more
Sign the given message, update the state, and return a digital signature
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.