pub struct PublicKey {
    pub key_type: KeyType,
    pub kind: PublicKeyKind,
    pub comment: Option<String>,
}
Expand description

A type which represents an OpenSSH public key.

Fields

key_type: KeyType

Key type.

kind: PublicKeyKind

The kind of public key.

comment: Option<String>

Associated comment, if any.

Implementations

Reads an OpenSSH public key from a given path.

Examples
let key = sshkeys::PublicKey::from_path("/path/to/id_ed25519.pub")?;

Reads an OpenSSH public key from a given string.

Examples
let key = sshkeys::PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHkbe7gwx7s0dlApEEzpUyOAPrzPLy4czEZw/sh8m8rd me@home").unwrap();
let fp = key.fingerprint();
assert_eq!(fp.hash, "ciQkdxjFUhk2E2vRkWJD9kB8pi+EneOkaCJJHNWzPC4");

Reads a public key from a given byte sequence.

The byte sequence is expected to be the base64 decoded body of the public key.

Example
let data = vec![0, 0, 0, 11, 115, 115, 104, 45,
                101, 100, 50, 53, 53, 49, 57,
                0, 0, 0, 32, 121, 27, 123, 184,
                48, 199, 187, 52, 118, 80, 41, 16,
                76, 233, 83, 35, 128, 62, 188,
                207, 47, 46, 28, 204, 70, 112,
                254, 200, 124, 155, 202, 221];

let key = sshkeys::PublicKey::from_bytes(&data).unwrap();
let fp = key.fingerprint();
assert_eq!(fp.hash, "ciQkdxjFUhk2E2vRkWJD9kB8pi+EneOkaCJJHNWzPC4");

Returns the number of bits of the public key.

Example
let key = sshkeys::PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHkbe7gwx7s0dlApEEzpUyOAPrzPLy4czEZw/sh8m8rd me@home").unwrap();
assert_eq!(key.bits(), 256);

Encodes the public key in an OpenSSH compatible format.

Example
let key = sshkeys::PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHkbe7gwx7s0dlApEEzpUyOAPrzPLy4czEZw/sh8m8rd me@home").unwrap();
assert_eq!(key.encode(), vec![0, 0, 0, 11, 115, 115, 104, 45, 101, 100, 50, 53, 53, 49, 57, 0, 0, 0, 32, 121, 27, 123, 184, 48, 199, 187, 52, 118, 80, 41, 16, 76, 233, 83, 35, 128, 62, 188, 207, 47, 46, 28, 204, 70, 112, 254, 200, 124, 155, 202, 221]);

Computes the fingerprint of the public key using the default OpenSSH fingerprint representation with SHA256.

Example
let key = sshkeys::PublicKey::from_path("/path/to/id_ed25519.pub")?;
let fp = key.fingerprint();
println!("{}", fp.hash);

Computes the fingerprint of the public key using a given fingerprint representation.

Example
let key = sshkeys::PublicKey::from_path("/path/to/id_ed25519.pub").unwrap();
let sha512fp = key.fingerprint_with(sshkeys::FingerprintKind::Sha512);
println!("{}", sha512fp.hash);

Writes the public key to a given writer.

Example
use std::fs::File;
let key = sshkeys::PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...")?;
let mut file = File::create("/path/to/id_ed25519.pub")?;
key.write(&mut file).unwrap();

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Performs the conversion.

Performs the conversion.

Should always be Self

Converts the given value to a String. 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.