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 (key_store, key_id) = create_test_key_store();
17 let mut ctx = key_store.context_mut();
18
19 let original = crate::CipherView {
20 name: "My SSH Key".to_string(),
21 notes: None,
22 r#type: CipherType::SshKey,
23 ssh_key: Some(SshKeyView {
24 private_key: "-----BEGIN OPENSSH PRIVATE KEY-----".to_string(),
25 public_key: "ssh-ed25519 AAAA".to_string(),
26 fingerprint: "SHA256:abc123".to_string(),
27 }),
28 ..create_shell_cipher_view(CipherType::SshKey)
29 };
30
31 let blob = CipherBlobV1::from_cipher_view(&original, &mut ctx, key_id).unwrap();
32 let mut restored = create_shell_cipher_view(CipherType::SshKey);
33 blob.apply_to_cipher_view(&mut restored, &mut ctx, key_id)
34 .unwrap();
35
36 assert_eq!(restored.name, "My SSH Key");
37 assert_eq!(restored.r#type, CipherType::SshKey);
38 let ssh_key = restored.ssh_key.unwrap();
39 assert_eq!(ssh_key.private_key, "-----BEGIN OPENSSH PRIVATE KEY-----");
40 assert_eq!(ssh_key.public_key, "ssh-ed25519 AAAA");
41 assert!(restored.login.is_none());
42 }
43}