Skip to content

Commit

Permalink
fixed #338 - make KeyPair::generate_ed25519 infallible
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Sep 17, 2024
1 parent 73fa3e5 commit cb8d9e9
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions russh-keys/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ impl KeyPair {
}

/// Generate a ED25519 key pair.
pub fn generate_ed25519() -> Option<Self> {
pub fn generate_ed25519() -> Self {
let keypair = ed25519_dalek::SigningKey::generate(&mut OsRng {});
assert_eq!(
keypair.verifying_key().as_bytes(),
ed25519_dalek::VerifyingKey::from(&keypair).as_bytes()
);
Some(KeyPair::Ed25519(keypair))
KeyPair::Ed25519(keypair)
}

/// Generate a RSA key pair.
Expand Down
2 changes: 1 addition & 1 deletion russh/examples/echoserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn main() {
inactivity_timeout: Some(std::time::Duration::from_secs(3600)),
auth_rejection_time: std::time::Duration::from_secs(3),
auth_rejection_time_initial: Some(std::time::Duration::from_secs(0)),
keys: vec![russh_keys::key::KeyPair::generate_ed25519().unwrap()],
keys: vec![russh_keys::key::KeyPair::generate_ed25519()],
..Default::default()
};
let config = Arc::new(config);
Expand Down
2 changes: 1 addition & 1 deletion russh/examples/ratatui_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl AppServer {
inactivity_timeout: Some(std::time::Duration::from_secs(3600)),
auth_rejection_time: std::time::Duration::from_secs(3),
auth_rejection_time_initial: Some(std::time::Duration::from_secs(0)),
keys: vec![russh_keys::key::KeyPair::generate_ed25519().unwrap()],
keys: vec![russh_keys::key::KeyPair::generate_ed25519()],
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion russh/examples/ratatui_shared_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl AppServer {
inactivity_timeout: Some(std::time::Duration::from_secs(3600)),
auth_rejection_time: std::time::Duration::from_secs(3),
auth_rejection_time_initial: Some(std::time::Duration::from_secs(0)),
keys: vec![russh_keys::key::KeyPair::generate_ed25519().unwrap()],
keys: vec![russh_keys::key::KeyPair::generate_ed25519()],
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion russh/examples/sftp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async fn main() {
let config = russh::server::Config {
auth_rejection_time: Duration::from_secs(3),
auth_rejection_time_initial: Some(Duration::from_secs(0)),
keys: vec![KeyPair::generate_ed25519().unwrap()],
keys: vec![KeyPair::generate_ed25519()],
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion russh/examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn main() -> anyhow::Result<()> {
config.auth_rejection_time = std::time::Duration::from_secs(3);
config
.keys
.push(russh_keys::key::KeyPair::generate_ed25519().unwrap());
.push(russh_keys::key::KeyPair::generate_ed25519());
let config = Arc::new(config);
let mut sh = Server {
clients: Arc::new(Mutex::new(HashMap::new())),
Expand Down
11 changes: 4 additions & 7 deletions russh/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ mod compress {
async fn compress_local_test() {
let _ = env_logger::try_init();

let client_key = russh_keys::key::KeyPair::generate_ed25519().unwrap();
let client_key = russh_keys::key::KeyPair::generate_ed25519();
let mut config = server::Config::default();
config.preferred = Preferred::COMPRESSED;
config.inactivity_timeout = None; // Some(std::time::Duration::from_secs(3));
config.auth_rejection_time = std::time::Duration::from_secs(3);
config
.keys
.push(russh_keys::key::KeyPair::generate_ed25519().unwrap());
.push(russh_keys::key::KeyPair::generate_ed25519());
let config = Arc::new(config);
let mut sh = Server {
clients: Arc::new(Mutex::new(HashMap::new())),
Expand Down Expand Up @@ -162,20 +162,17 @@ mod channels {

let _ = env_logger::try_init();

let client_key = russh_keys::key::KeyPair::generate_ed25519().unwrap();
let client_key = russh_keys::key::KeyPair::generate_ed25519();
let mut config = server::Config::default();
config.inactivity_timeout = None;
config.auth_rejection_time = std::time::Duration::from_secs(3);
config
.keys
.push(russh_keys::key::KeyPair::generate_ed25519().unwrap());
.push(russh_keys::key::KeyPair::generate_ed25519());
let config = Arc::new(config);
let socket = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = socket.local_addr().unwrap();

#[derive(Clone)]
struct Server {}

let server_join = tokio::spawn(async move {
let (socket, _) = socket.accept().await.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions russh/tests/test_data_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn test_reader_and_writer() -> Result<(), anyhow::Error> {

async fn stream(addr: SocketAddr, data: &[u8]) -> Result<(), anyhow::Error> {
let config = Arc::new(client::Config::default());
let key = Arc::new(russh_keys::key::KeyPair::generate_ed25519().unwrap());
let key = Arc::new(russh_keys::key::KeyPair::generate_ed25519());

let mut session = russh::client::connect(config, addr, Client).await?;
let mut channel = match session.authenticate_publickey("user", key).await {
Expand Down Expand Up @@ -84,7 +84,7 @@ struct Server;
impl Server {
async fn run(addr: SocketAddr) {
let config = Arc::new(server::Config {
keys: vec![russh_keys::key::KeyPair::generate_ed25519().unwrap()],
keys: vec![russh_keys::key::KeyPair::generate_ed25519()],
window_size: WINDOW_SIZE,
..Default::default()
});
Expand Down

0 comments on commit cb8d9e9

Please sign in to comment.