16 releases

0.6.4 Jul 12, 2024
0.6.2 Jun 27, 2023
0.6.0 Nov 18, 2022
0.5.0 Mar 16, 2021
0.2.0 Nov 7, 2017

#89 in Cryptography

Download history 3718/week @ 2024-07-25 3562/week @ 2024-08-01 4125/week @ 2024-08-08 3768/week @ 2024-08-15 4314/week @ 2024-08-22 3605/week @ 2024-08-29 3125/week @ 2024-09-05 3271/week @ 2024-09-12 2786/week @ 2024-09-19 3392/week @ 2024-09-26 3043/week @ 2024-10-03 3319/week @ 2024-10-10 3254/week @ 2024-10-17 3716/week @ 2024-10-24 3612/week @ 2024-10-31 2609/week @ 2024-11-07

13,861 downloads per month
Used in 12 crates (7 directly)

MIT/Apache

51KB
980 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.

Release process

Releases can be performed by creating a new release ticket and following the steps in the checklist there.

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.5MB
~33K SLoC