bitwarden_wasm_internal/
ssh.rs

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