ssh-key 0.7.0

Pure Rust implementation of SSH key file format decoders/encoders as described in RFC4251/RFC4253 and OpenSSH key formats, as well as "sshsig" signatures and certificates (including certificate validation and certificate authority support), with further support for the `authorized_keys` and `known_hosts` file formats.
Documentation
//! Tests for `~/.ssh` support. Uses the `tests/examples` directory instead.

#![cfg(feature = "std")]

use ssh_key::DotSsh;

#[cfg(feature = "sha2")]
use {
    hex_literal::hex,
    ssh_key::{Algorithm, Fingerprint},
};

/// Number of `mldsa44_ed25519` example keys, which only parse when the
/// algorithm is enabled.
#[cfg(all(feature = "mldsa", feature = "ed25519"))]
const MLDSA_EDDSA_PRIVATE_KEYS: usize = 3;
#[cfg(not(all(feature = "mldsa", feature = "ed25519")))]
const MLDSA_EDDSA_PRIVATE_KEYS: usize = 0;

#[cfg(all(feature = "mldsa", feature = "ed25519"))]
const MLDSA_EDDSA_PUBLIC_KEYS: usize = 1;
#[cfg(not(all(feature = "mldsa", feature = "ed25519")))]
const MLDSA_EDDSA_PUBLIC_KEYS: usize = 0;

/// Open `.ssh` using the `test/examples`.
fn dot_ssh() -> DotSsh {
    DotSsh::open("tests/examples")
}

#[test]
fn path_round_trip() {
    let dot_ssh = dot_ssh();
    dbg!(dot_ssh.path());
    assert!(dot_ssh.path().ends_with("tests/examples"));
}

#[test]
fn private_keys() {
    let dot_ssh = dot_ssh();
    assert_eq!(
        dot_ssh.private_keys().unwrap().count(),
        24 + MLDSA_EDDSA_PRIVATE_KEYS
    );
}

#[cfg(feature = "sha2")]
#[test]
fn private_key_with_fingerprint() {
    let fingerprint = Fingerprint::Sha256(hex!(
        "5025222ebecf8ecf7014524c0c1c8b81cdcdaed754df8e0e814338e7064f7084"
    ));

    let dot_ssh = dot_ssh();
    let key = dot_ssh.private_key_with_fingerprint(fingerprint).unwrap();
    assert_eq!(key.algorithm(), Algorithm::Ed25519);
}

#[test]
fn public_keys() {
    let dot_ssh = dot_ssh();
    assert_eq!(
        dot_ssh.public_keys().unwrap().count(),
        12 + MLDSA_EDDSA_PUBLIC_KEYS
    );
}

#[cfg(feature = "sha2")]
#[test]
fn public_key_with_fingerprint() {
    let fingerprint = Fingerprint::Sha256(hex!(
        "5025222ebecf8ecf7014524c0c1c8b81cdcdaed754df8e0e814338e7064f7084"
    ));

    let dot_ssh = dot_ssh();
    let key = dot_ssh.public_key_with_fingerprint(fingerprint).unwrap();
    assert_eq!(key.algorithm(), Algorithm::Ed25519);
}