Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"unknown algorithm" error #334

Open
Leandros opened this issue Feb 19, 2025 · 2 comments
Open

"unknown algorithm" error #334

Leandros opened this issue Feb 19, 2025 · 2 comments

Comments

@Leandros
Copy link

Using ssh-key to create a new PrivateKey using an algorithm which doesn't have the correct crate feature enabled results in a runtime error (unknown algorithm).

The following code compiles fine but panics with an error at runtime.

# Cargo.toml
[dependencies]
ssh-key = "0.6"
// main.rs
use ssh_key::rand_core::OsRng;
use ssh_key::{Algorithm, PrivateKey};

fn main() {
    let private_key = PrivateKey::random(&mut OsRng, Algorithm::Ed25519).unwrap();
    dbg!(&private_key);
}

This is not very rusty. It would be much less surprising if the enum variant Ed25519 of the Algorithm enum would also be guarded by the feature that enables the algorithm.

@tarcieri
Copy link
Member

There are valid uses of that enum without the associated crate features, such as the ability to simply parse and serialize such keys without the associated cryptographic operations.

I suppose we could have an entirely separate, duplicated enum where each variant is gated on the associated crate features just for the use cases that require cryptographic support. I am not sure the added complexity is worth it, however.

@Leandros
Copy link
Author

I suspected this when filing the issue. I agree that the added code duplication isn't ideal; however, the current situation isn't ideal, either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants