11 releases

0.5.0 Mar 16, 2021
0.4.2 Jun 22, 2020
0.4.1 Nov 1, 2018
0.3.0 Jul 11, 2018
0.2.0 Nov 7, 2017

#67 in Network programming

Download history 112/week @ 2021-04-04 135/week @ 2021-04-11 129/week @ 2021-04-18 72/week @ 2021-04-25 79/week @ 2021-05-02 115/week @ 2021-05-09 101/week @ 2021-05-16 123/week @ 2021-05-23 113/week @ 2021-05-30 79/week @ 2021-06-06 62/week @ 2021-06-13 50/week @ 2021-06-20 53/week @ 2021-06-27 157/week @ 2021-07-04 106/week @ 2021-07-11 83/week @ 2021-07-18

674 downloads per month
Used in 10 crates (5 directly)

MIT/Apache

45KB
848 lines

openssh-keys   Latest Version Docs Badge

A pure-Rust library to handle OpenSSH public keys.

openssh-keys can parse, print, and fingerprint OpenSSH public keys. It supports the following algorithms:

  • RSA
  • DSA
  • ECDSA (nistp256, nistp384, nistp521)
  • ED25519

It can construct RSA and DSA keys from their components using the PublicKey::from_rsa() and PublicKey::from_dsa() functions respectively.

Example

extern crate openssh_keys;

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

fn main() {
    let home = env::home_dir().unwrap_or(path::PathBuf::from("/home/core/"));
    let pub_path = home.join(".ssh").join("id_rsa.pub");
    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());
    }
}

Some more examples are available under examples.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1–1.4MB
~34K SLoC