bitwarden_ssh/
lib.rs

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