Skip to main content

bitwarden_wasm_internal/
ssh.rs

1use bitwarden_vault::SshKeyView;
2
3/// Generate a new SSH key pair
4///
5/// # Arguments
6/// - `key_algorithm` - The algorithm to use for the key pair
7///
8/// # Returns
9/// - `Ok(SshKey)` if the key was successfully generated
10/// - `Err(KeyGenerationError)` if the key could not be generated
11#[bitwarden_ffi::wasm_export]
12pub fn generate_ssh_key(
13    key_algorithm: bitwarden_ssh::generator::KeyAlgorithm,
14) -> Result<SshKeyView, bitwarden_ssh::error::KeyGenerationError> {
15    bitwarden_ssh::generator::generate_sshkey(key_algorithm).map(Into::into)
16}
17
18/// Convert a PCKS8 or OpenSSH encrypted or unencrypted private key
19/// to an OpenSSH private key with public key and fingerprint
20///
21/// # Arguments
22/// - `imported_key` - The private key to convert
23/// - `password` - The password to use for decrypting the key
24///
25/// # Returns
26/// - `Ok(SshKey)` if the key was successfully coneverted
27/// - `Err(PasswordRequired)` if the key is encrypted and no password was provided
28/// - `Err(WrongPassword)` if the password provided is incorrect
29/// - `Err(Parsing)` if the key could not be parsed
30/// - `Err(UnsupportedKeyType)` if the key type is not supported
31#[bitwarden_ffi::wasm_export]
32pub fn import_ssh_key(
33    imported_key: &str,
34    password: Option<String>,
35) -> Result<SshKeyView, bitwarden_ssh::error::SshKeyImportError> {
36    bitwarden_ssh::import::import_key(imported_key.to_string(), password).map(Into::into)
37}