From 1474bc9fe3120b25add966797b6440a974869978 Mon Sep 17 00:00:00 2001 From: TheAwiteb Date: Sun, 7 Jan 2024 22:16:39 +0300 Subject: [PATCH] Support `null` bitwarden `login`, `username` and `password` --- src/password/bitwarden.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/password/bitwarden.rs b/src/password/bitwarden.rs index 7b46ea4..b1ab0a9 100644 --- a/src/password/bitwarden.rs +++ b/src/password/bitwarden.rs @@ -4,8 +4,8 @@ use super::{Password, Passwords}; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BitWardenLoginData { - pub username: String, - pub password: String, + pub username: Option, + pub password: Option, pub uris: Option>, } @@ -27,7 +27,7 @@ pub struct BitWardenPassword { #[serde(rename = "type")] pub ty: i32, pub name: String, - pub login: BitWardenLoginData, + pub login: Option, pub notes: Option, } @@ -43,12 +43,17 @@ impl From for Password { fn from(value: BitWardenPassword) -> Self { Self { name: value.name, - username: value.login.username, - password: value.login.password, + username: value + .login + .as_ref() + .map_or_else(String::new, |l| l.username.to_owned().unwrap_or_default()), + password: value + .login + .as_ref() + .map_or_else(String::new, |l| l.password.to_owned().unwrap_or_default()), service: value .login - .uris - .and_then(|p| p.first().map(|u| u.uri.clone())), + .and_then(|l| l.uris.and_then(|p| p.first().map(|u| u.uri.clone()))), note: value.notes, } } @@ -59,13 +64,13 @@ impl From for BitWardenPassword { Self { ty: 1, name: value.name, - login: BitWardenLoginData { - username: value.username, - password: value.password, + login: Some(BitWardenLoginData { + username: Some(value.username), + password: Some(value.password), uris: value .service .map(|s| vec![BitWardenUri { mt: None, uri: s }]), - }, + }), notes: value.note, } }