#![cfg(feature = "std")]
use ssh_key::DotSsh;
#[cfg(feature = "sha2")]
use {
hex_literal::hex,
ssh_key::{Algorithm, Fingerprint},
};
#[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;
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);
}