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 error::SshKeyExportError;
13use pkcs8::LineEnding;
14use ssh_key::{HashAlg, PrivateKey};
15
16#[cfg(feature = "uniffi")]
17uniffi::setup_scaffolding!();
18
19#[derive(Debug)]
21pub struct SshKeyData {
22 pub private_key: String,
24 pub public_key: String,
26 pub fingerprint: String,
28}
29
30fn ssh_private_key_to_data(value: PrivateKey) -> Result<SshKeyData, SshKeyExportError> {
31 let private_key_openssh = value
32 .to_openssh(LineEnding::LF)
33 .map_err(|_| SshKeyExportError::KeyConversion)?;
34
35 Ok(SshKeyData {
36 private_key: private_key_openssh.to_string(),
37 public_key: value.public_key().to_string(),
38 fingerprint: value.fingerprint(HashAlg::Sha256).to_string(),
39 })
40}