bitwarden_auth/login/models/
webauthn_prf_user_decryption_option.rs1use bitwarden_crypto::{EncString, UnsignedSharedKey};
2use serde::{Deserialize, Serialize};
3
4use crate::login::api::response::WebAuthnPrfUserDecryptionOptionApiResponse;
5
6#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
8#[serde(rename_all = "camelCase")]
9#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
10#[cfg_attr(
11 feature = "wasm",
12 derive(tsify::Tsify),
13 tsify(into_wasm_abi, from_wasm_abi)
14)]
15pub struct WebAuthnPrfUserDecryptionOption {
16 pub encrypted_private_key: EncString,
18
19 pub encrypted_user_key: UnsignedSharedKey,
21
22 pub credential_id: Option<String>,
25
26 pub transports: Option<Vec<String>>,
30}
31
32impl From<WebAuthnPrfUserDecryptionOptionApiResponse> for WebAuthnPrfUserDecryptionOption {
33 fn from(api: WebAuthnPrfUserDecryptionOptionApiResponse) -> Self {
34 Self {
35 encrypted_private_key: api.encrypted_private_key,
36 encrypted_user_key: api.encrypted_user_key,
37 credential_id: api.credential_id,
38 transports: api.transports,
39 }
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_webauthn_prf_conversion() {
49 let api = WebAuthnPrfUserDecryptionOptionApiResponse {
50 encrypted_private_key: "2.fkvl0+sL1lwtiOn1eewsvQ==|dT0TynLl8YERZ8x7dxC+DQ==|cWhiRSYHOi/AA2LiV/JBJWbO9C7pbUpOM6TMAcV47hE=".parse().unwrap(),
51 encrypted_user_key: "4.DMD1D5r6BsDDd7C/FE1eZbMCKrmryvAsCKj6+bO54gJNUxisOI7SDcpPLRXf+JdhqY15pT+wimQ5cD9C+6OQ6s71LFQHewXPU29l9Pa1JxGeiKqp37KLYf+1IS6UB2K3ANN35C52ZUHh2TlzIS5RuntxnpCw7APbcfpcnmIdLPJBtuj/xbFd6eBwnI3GSe5qdS6/Ixdd0dgsZcpz3gHJBKmIlSo0YN60SweDq3kTJwox9xSqdCueIDg5U4khc7RhjYx8b33HXaNJj3DwgIH8iLj+lqpDekogr630OhHG3XRpvl4QzYO45bmHb8wAh67Dj70nsZcVg6bAEFHdSFohww==".parse().unwrap(),
52 credential_id: None,
53 transports: None,
54 };
55
56 let domain: WebAuthnPrfUserDecryptionOption = api.clone().into();
57
58 assert_eq!(domain.encrypted_private_key, api.encrypted_private_key);
59 assert_eq!(domain.encrypted_user_key, api.encrypted_user_key);
60 assert_eq!(domain.credential_id, None);
61 assert_eq!(domain.transports, None);
62 }
63
64 #[test]
65 fn test_webauthn_prf_conversion_with_optional_fields() {
66 let api = WebAuthnPrfUserDecryptionOptionApiResponse {
67 encrypted_private_key: "2.fkvl0+sL1lwtiOn1eewsvQ==|dT0TynLl8YERZ8x7dxC+DQ==|cWhiRSYHOi/AA2LiV/JBJWbO9C7pbUpOM6TMAcV47hE=".parse().unwrap(),
68 encrypted_user_key: "4.DMD1D5r6BsDDd7C/FE1eZbMCKrmryvAsCKj6+bO54gJNUxisOI7SDcpPLRXf+JdhqY15pT+wimQ5cD9C+6OQ6s71LFQHewXPU29l9Pa1JxGeiKqp37KLYf+1IS6UB2K3ANN35C52ZUHh2TlzIS5RuntxnpCw7APbcfpcnmIdLPJBtuj/xbFd6eBwnI3GSe5qdS6/Ixdd0dgsZcpz3gHJBKmIlSo0YN60SweDq3kTJwox9xSqdCueIDg5U4khc7RhjYx8b33HXaNJj3DwgIH8iLj+lqpDekogr630OhHG3XRpvl4QzYO45bmHb8wAh67Dj70nsZcVg6bAEFHdSFohww==".parse().unwrap(),
69 credential_id: Some("test-credential-id".to_string()),
70 transports: Some(vec!["usb".to_string(), "nfc".to_string()]),
71 };
72
73 let domain: WebAuthnPrfUserDecryptionOption = api.clone().into();
74
75 assert_eq!(domain.encrypted_private_key, api.encrypted_private_key);
76 assert_eq!(domain.encrypted_user_key, api.encrypted_user_key);
77 assert_eq!(domain.credential_id, Some("test-credential-id".to_string()));
78 assert_eq!(
79 domain.transports,
80 Some(vec!["usb".to_string(), "nfc".to_string()])
81 );
82 }
83}