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