Skip to content

Commit

Permalink
Simplify errors
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Nov 26, 2024
1 parent ce26892 commit 8d6aa2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/bitwarden-ssh/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use thiserror::Error;
#[derive(Error, Debug)]
pub enum KeyGenerationError {
#[error("Failed to generate key: {0}")]
KeyGenerationError(String),
KeyGenerationError(ssh_key::Error),
#[error("Failed to convert key: {0}")]
KeyConversionError(String),
KeyConversionError(ssh_key::Error),
}
8 changes: 4 additions & 4 deletions crates/bitwarden-ssh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ fn generate_sshkey_internal(
};

let rsa_keypair = ssh_key::private::RsaKeypair::random(&mut rng, bits)
.map_err(|e| KeyGenerationError::KeyGenerationError(e.to_string()))?;
.map_err( KeyGenerationError::KeyGenerationError)?;

let private_key =
ssh_key::PrivateKey::new(ssh_key::private::KeypairData::from(rsa_keypair), "")
.map_err(|e| KeyGenerationError::KeyGenerationError(e.to_string()))?;
.map_err(KeyGenerationError::KeyGenerationError)?;
Ok(private_key)
}
}
.map_err(|e| KeyGenerationError::KeyGenerationError(e.to_string()))?;
.map_err( KeyGenerationError::KeyGenerationError)?;

let private_key_openssh = key
.to_openssh(LineEnding::LF)
.map_err(|e| KeyGenerationError::KeyConversionError(e.to_string()))?;
.map_err(KeyGenerationError::KeyConversionError)?;
Ok(GenerateSshKeyResult {
private_key: private_key_openssh.to_string(),
public_key: key.public_key().to_string(),
Expand Down

0 comments on commit 8d6aa2e

Please sign in to comment.