Struct openssh_keys::PublicKey [] [src]

pub struct PublicKey { /* fields omitted */ }

PublicKey is the struct representation of an ssh public key.

Methods

impl PublicKey
[src]

[src]

parse takes a string and parses it as a public key from an authorized keys file. the format it expects is described here https://tools.ietf.org/html/rfc4253#section-6.6 and here https://man.openbsd.org/sshd#AUTHORIZED_KEYS_FILE_FORMAT

sshd describes an additional, optional "options" field for public keys in the authorized_keys file. This field allows for passing of options to sshd that only apply to that particular public key. This means that a public key in an authorized keys file is a strict superset of the public key format described in rfc4253. Another superset of a public key is what is present in the known_hosts file. This file has a hostname as the first thing on the line. This parser treats the hostname the same as an option field. When one of these things is found at the beginning of a line, it is treated as a semi-opaque string that is carried with the public key and reproduced when the key is printed. It is not entirely opaque, since the parser needs to be aware of quoting semantics within the option fields, since options surrounded by double quotes can contain spaces, which are otherwise the main delimiter of the parts of a public key.

You can parse and output ssh keys like this

let rsa_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcMCOEryBa8IkxXacjIawaQPp08hR5h7+4vZePZ7DByTG3tqKgZYRJ86BaR+4fmdikFoQjvLJVUmwniq3wixhkP7VLCbqip3YHzxXrzxkbPC3w3O1Bdmifwn9cb8RcZXfXncCsSu+h5XCtQ5BOi41Iit3d13gIe/rfXVDURmRanV6R7Voljxdjmp/zyReuzc2/w5SI6Boi4tmcUlxAI7sFuP1kA3pABDhPtc3TDgAcPUIBoDCoY8q2egI197UuvbgsW2qraUcuQxbMvJOMSFg2FQrE2bpEqC4CtBn7+HiJrkVOHjV7bvSv7jd1SuX5XqkwMCRtdMuRpJr7CyZoFL5n demos@anduin";
let key = openssh_keys::PublicKey::parse(rsa_key).unwrap();
let out = key.to_string();
assert_eq!(rsa_key, out);

parse somewhat attempts to keep track of comments, but it doesn't fully comply with the rfc in that regard.

[src]

read_keys takes a reader and parses it as an authorized_keys file. it returns an error if it can't read or parse any of the public keys in the list.

[src]

get an ssh public key from rsa components

[src]

get an ssh public key from dsa components

[src]

keytype returns the type of key in the format described by rfc4253 The output will be ssh-{type} where type is [rsa,ed25519,ecdsa,dsa]

[src]

data returns the data section of the key in the format described by rfc4253 the contents of the data section depend on the keytype. For RSA keys it contains the keytype, exponent, and modulus in that order. Other types have other data sections. This function doesn't base64 encode the data, that task is left to the consumer of the output.

[src]

[src]

to_key_format returns a string representation of the ssh key. this string output is appropriate to use as a public key file. it adheres to the format described in https://tools.ietf.org/html/rfc4253#section-6.6

an ssh key consists of four pieces:

[options] ssh-keytype data comment

the output of the data section is described in the documentation for the data function. the options section is optional, and is not part of the spec. rather, it is a field present in authorized_keys files or known_hosts files.

[src]

size returns the size of the stored ssh key. for rsa keys this is determined by the number of bits in the modulus. for dsa keys it's the number of bits in the prime p.

see https://github.com/openssh/openssh-portable/blob/master/sshkey.c#L261 for more details

[src]

fingerprint returns a string representing the fingerprint of the ssh key the format of the fingerprint is described tersely in https://tools.ietf.org/html/rfc4716#page-6. This uses the ssh-keygen defaults of a base64 encoded SHA256 hash.

[src]

to_fingerprint_string prints out the fingerprint in the same format used by ssh-keygen -l -f key, specifically the implementation here - https://github.com/openssh/openssh-portable/blob/master/ssh-keygen.c#L842 right now it just sticks with the defaults of a base64 encoded SHA256 hash.

Trait Implementations

impl Clone for PublicKey
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for PublicKey
[src]

[src]

Formats the value using the given formatter.

impl Eq for PublicKey
[src]

impl Display for PublicKey
[src]

[src]

Formats the value using the given formatter. Read more

impl PartialEq for PublicKey
[src]

Two public keys are equivalent if their data sections are equivalent, ignoring their comment section.

[src]

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

1.0.0
[src]

This method tests for !=.

impl FromStr for PublicKey
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more