bitwarden_uniffi/tool/
ssh.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::sync::Arc;

use crate::{
    error::{BitwardenError, Error},
    Client, Result,
};

#[derive(uniffi::Object)]
pub struct SshClient(pub Arc<Client>);

#[uniffi::export]
impl SshClient {
    pub fn generate_ssh_key(
        &self,
        key_algorithm: bitwarden_ssh::generator::KeyAlgorithm,
    ) -> Result<bitwarden_ssh::SshKey> {
        bitwarden_ssh::generator::generate_sshkey(key_algorithm)
            .map_err(|e| BitwardenError::E(Error::SshGeneration(e)))
    }

    pub fn import_ssh_key(
        &self,
        imported_key: String,
        password: Option<String>,
    ) -> Result<bitwarden_ssh::SshKey> {
        bitwarden_ssh::import::import_key(imported_key, password)
            .map_err(|e| BitwardenError::E(Error::SshImport(e)))
    }
}