bitwarden_vault/cipher/blob/conversions/
ssh_key.rs1use super::{SshKeyDataV1, SshKeyView};
2
3impl_bidirectional_from!(
4 SshKeyView,
5 SshKeyDataV1,
6 [private_key, public_key, fingerprint,]
7);
8
9#[cfg(test)]
10mod tests {
11 use super::super::{CipherBlobV1, test_support::*};
12 use crate::cipher::{cipher::CipherType, ssh_key::SshKeyView};
13
14 #[test]
15 fn test_ssh_key_cipher_round_trip() {
16 let original = crate::CipherView {
17 name: "My SSH Key".to_string(),
18 notes: None,
19 r#type: CipherType::SshKey,
20 ssh_key: Some(SshKeyView {
21 private_key: "-----BEGIN OPENSSH PRIVATE KEY-----".to_string(),
22 public_key: "ssh-ed25519 AAAA".to_string(),
23 fingerprint: "SHA256:abc123".to_string(),
24 }),
25 ..create_shell_cipher_view(CipherType::SshKey)
26 };
27
28 let blob = CipherBlobV1::from_cipher_view(&original).unwrap();
29 let mut restored = create_shell_cipher_view(CipherType::SshKey);
30 blob.apply_to_cipher_view(&mut restored).unwrap();
31
32 assert_eq!(restored.name, "My SSH Key");
33 assert_eq!(restored.r#type, CipherType::SshKey);
34 let ssh_key = restored.ssh_key.unwrap();
35 assert_eq!(ssh_key.private_key, "-----BEGIN OPENSSH PRIVATE KEY-----");
36 assert_eq!(ssh_key.public_key, "ssh-ed25519 AAAA");
37 assert!(restored.login.is_none());
38 }
39}