Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions ssh-key/tests/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ fn round_trip_non_utf8_comment_openssh() {
#[cfg(feature = "alloc")]
#[test]
fn encode_dsa_openssh() {
encoding_test(OPENSSH_DSA_EXAMPLE)
round_trip_test(OPENSSH_DSA_EXAMPLE);
}

#[cfg(all(feature = "alloc", feature = "p256"))]
Expand Down Expand Up @@ -663,17 +663,25 @@ fn encode_custom_algorithm_openssh() {
/// Common behavior of all encoding tests
#[cfg(feature = "alloc")]
fn encoding_test(private_key: &str) {
#[cfg_attr(not(feature = "std"), allow(unused_variables))]
let key = round_trip_test(private_key);

#[cfg(feature = "std")]
if !matches!(key.algorithm(), Algorithm::Other(_)) {
encoding_integration_test(key)
}
}

#[cfg(feature = "alloc")]
fn round_trip_test(private_key: &str) -> PrivateKey {
let key = PrivateKey::from_openssh(private_key).unwrap();

// Ensure key round-trips
let pem = key.to_openssh(LineEnding::LF).unwrap();
let key2 = PrivateKey::from_openssh(&*pem).unwrap();
assert_eq!(key, key2);

#[cfg(feature = "std")]
if !matches!(key.algorithm(), Algorithm::Other(_)) {
encoding_integration_test(key)
}
key
}

/// Parse PEM encoded using `PrivateKey::to_openssh` using the `ssh-keygen` utility.
Expand Down