Crate openssh_keys[][src]

A pure-Rust library to handle OpenSSH public keys.

This crate supports parsing, manipulation, and some basic validation of SSH keys. It provides a struct for encapsulation of SSH keys in projects.

openssh-keys does not have the ability to generate SSH keys. However, it does allow to construct RSA and DSA keys from their components, so if you generate the keys with another library (say, rust-openssl), then you can output the SSH public keys with this library.


use std::{env, fs, io, path};
use std::io::BufRead;

fn inspect_rsa() {
    let home = env::home_dir().unwrap_or(path::PathBuf::from("/home/core/"));
    let pub_path = home.join(".ssh").join("");
    println!("Inspecting '{}':", pub_path.to_string_lossy());
    let file = fs::File::open(&pub_path).expect("unable to open RSA pubkey");
    let reader = io::BufReader::new(file);

    for (i, line) in reader.lines().enumerate() {
        let line = line.expect(&format!("unable to read key at line {}", i + 1));
        let pubkey = openssh_keys::PublicKey::parse(&line).expect("unable to parse RSA pubkey");
        println!(" * Pubkey #{} -> {}", i + 1, pubkey.to_fingerprint_string());





PublicKey is the struct representation of an ssh public key.



Curves for ECDSA


Data is the representation of the data section of an ssh public key. it is an enum with all the different supported key algorithms.