bitwarden_ssh/
lib.rs

1#![doc = include_str!("../README.md")]
2
3#[allow(missing_docs)]
4pub mod error;
5#[allow(missing_docs)]
6pub mod generator;
7#[allow(missing_docs)]
8pub mod import;
9
10use bitwarden_vault::SshKeyView;
11use error::SshKeyExportError;
12use pkcs8::LineEnding;
13use ssh_key::{HashAlg, PrivateKey};
14
15#[cfg(feature = "uniffi")]
16uniffi::setup_scaffolding!();
17
18fn ssh_private_key_to_view(value: PrivateKey) -> Result<SshKeyView, SshKeyExportError> {
19    let private_key_openssh = value
20        .to_openssh(LineEnding::LF)
21        .map_err(|_| SshKeyExportError::KeyConversionError)?;
22
23    Ok(SshKeyView {
24        private_key: private_key_openssh.to_string(),
25        public_key: value.public_key().to_string(),
26        fingerprint: value.fingerprint(HashAlg::Sha256).to_string(),
27    })
28}