1
1
use bitwarden_vault:: { Totp , TotpAlgorithm } ;
2
2
use credential_exchange_types:: format:: {
3
- Account as CxfAccount , Credential , Item , ItemType , NoteCredential , OTPHashAlgorithm ,
4
- TotpCredential ,
3
+ Account as CxfAccount , Credential , Item , NoteCredential , OTPHashAlgorithm , TotpCredential ,
5
4
} ;
6
5
use uuid:: Uuid ;
7
6
@@ -27,10 +26,9 @@ pub(crate) fn build_cxf(account: Account, ciphers: Vec<Cipher>) -> Result<String
27
26
28
27
let account = CxfAccount {
29
28
id : account. id . as_bytes ( ) . as_slice ( ) . into ( ) ,
30
- user_name : "" . to_owned ( ) ,
29
+ username : "" . to_owned ( ) ,
31
30
email : account. email ,
32
31
full_name : account. name ,
33
- icon : None ,
34
32
collections : vec ! [ ] , // TODO: Add support for folders
35
33
items,
36
34
extensions : None ,
@@ -46,41 +44,29 @@ impl TryFrom<Cipher> for Item {
46
44
let mut credentials: Vec < Credential > = value. r#type . clone ( ) . into ( ) ;
47
45
48
46
if let Some ( note) = value. notes {
49
- credentials. push ( Credential :: Note ( Box :: new ( NoteCredential { content : note } ) ) ) ;
47
+ credentials. push ( Credential :: Note ( Box :: new ( NoteCredential {
48
+ content : note. into ( ) ,
49
+ } ) ) ) ;
50
50
}
51
51
52
52
Ok ( Self {
53
53
id : value. id . as_bytes ( ) . as_slice ( ) . into ( ) ,
54
54
creation_at : Some ( value. creation_date . timestamp ( ) as u64 ) ,
55
55
modified_at : Some ( value. revision_date . timestamp ( ) as u64 ) ,
56
- ty : value. r#type . try_into ( ) ?,
57
56
title : value. name ,
58
57
subtitle : None ,
59
58
favorite : Some ( value. favorite ) ,
60
59
credentials,
61
60
tags : None ,
62
61
extensions : None ,
62
+ scope : match value. r#type {
63
+ CipherType :: Login ( login) => Some ( ( * login) . into ( ) ) ,
64
+ _ => None ,
65
+ } ,
63
66
} )
64
67
}
65
68
}
66
69
67
- impl TryFrom < CipherType > for ItemType {
68
- type Error = CxfError ;
69
-
70
- fn try_from ( value : CipherType ) -> Result < Self , Self :: Error > {
71
- match value {
72
- CipherType :: Login ( _) => Ok ( ItemType :: Login ) ,
73
- CipherType :: Card ( _) => Ok ( ItemType :: Identity ) ,
74
- CipherType :: Identity ( _) => Ok ( ItemType :: Identity ) ,
75
- CipherType :: SecureNote ( _) => Ok ( ItemType :: Document ) ,
76
- CipherType :: SshKey ( _) => {
77
- // TODO(PM-15448): Add support for SSH Keys
78
- Err ( CxfError :: Internal ( "Unsupported CipherType: SshKey" . into ( ) ) )
79
- }
80
- }
81
- }
82
- }
83
-
84
70
impl From < CipherType > for Vec < Credential > {
85
71
fn from ( value : CipherType ) -> Self {
86
72
match value {
@@ -131,7 +117,7 @@ fn convert_totp(totp: Totp) -> TotpCredential {
131
117
secret : totp. secret . into ( ) ,
132
118
period : totp. period as u8 ,
133
119
digits : totp. digits as u8 ,
134
- username : totp. account . unwrap_or ( "" . to_string ( ) ) ,
120
+ username : totp. account ,
135
121
algorithm : match totp. algorithm {
136
122
TotpAlgorithm :: Sha1 => OTPHashAlgorithm :: Sha1 ,
137
123
TotpAlgorithm :: Sha256 => OTPHashAlgorithm :: Sha256 ,
@@ -144,7 +130,6 @@ fn convert_totp(totp: Totp) -> TotpCredential {
144
130
145
131
#[ cfg( test) ]
146
132
mod tests {
147
- use credential_exchange_types:: format:: FieldType ;
148
133
149
134
use super :: * ;
150
135
use crate :: { Fido2Credential , Field , LoginUri } ;
@@ -164,7 +149,7 @@ mod tests {
164
149
assert_eq ! ( String :: from( credential. secret) , "ONSWG4TFOQ" ) ;
165
150
assert_eq ! ( credential. period, 60 ) ;
166
151
assert_eq ! ( credential. digits, 4 ) ;
167
- assert_eq ! ( credential
. username
, "[email protected] " ) ;
152
+ assert_eq ! ( credential
. username
. unwrap ( ) , "[email protected] " ) ;
168
153
assert_eq ! ( credential. algorithm, OTPHashAlgorithm :: Sha1 ) ;
169
154
assert_eq ! ( credential. issuer, Some ( "test-issuer" . to_string( ) ) ) ;
170
155
}
@@ -249,10 +234,13 @@ mod tests {
249
234
assert_eq ! ( item. id. to_string( ) , "JcjEFLRGSOmhvbEHALvXQA" ) ;
250
235
assert_eq ! ( item. creation_at, Some ( 1706613834 ) ) ;
251
236
assert_eq ! ( item. modified_at, Some ( 1706623773 ) ) ;
252
- assert_eq ! ( item. ty, ItemType :: Login ) ;
253
237
assert_eq ! ( item. title, "Bitwarden" ) ;
254
238
assert_eq ! ( item. subtitle, None ) ;
255
239
assert_eq ! ( item. tags, None ) ;
240
+ assert_eq ! (
241
+ item. scope. unwrap( ) . urls,
242
+ vec![ "https://vault.bitwarden.com" . to_string( ) ]
243
+ ) ;
256
244
assert ! ( item. extensions. is_none( ) ) ;
257
245
258
246
assert_eq ! ( item. credentials. len( ) , 4 ) ;
@@ -262,19 +250,12 @@ mod tests {
262
250
match credential {
263
251
Credential :: BasicAuth ( basic_auth) => {
264
252
let username = basic_auth. username . as_ref ( ) . unwrap ( ) ;
265
- assert_eq ! ( username. field_type, FieldType :: String ) ;
266
- assert_eq ! ( username
. value
, "[email protected] " ) ;
253
+ assert_eq ! ( username
. value
. 0 , "[email protected] " ) ;
267
254
assert ! ( username. label. is_none( ) ) ;
268
255
269
256
let password = basic_auth. password . as_ref ( ) . unwrap ( ) ;
270
- assert_eq ! ( password. field_type, FieldType :: ConcealedString ) ;
271
- assert_eq ! ( password. value, "asdfasdfasdf" ) ;
257
+ assert_eq ! ( password. value. 0 , "asdfasdfasdf" ) ;
272
258
assert ! ( password. label. is_none( ) ) ;
273
-
274
- assert_eq ! (
275
- basic_auth. urls,
276
- vec![ "https://vault.bitwarden.com" . to_string( ) ]
277
- ) ;
278
259
}
279
260
_ => panic ! ( "Expected Credential::BasicAuth" ) ,
280
261
}
@@ -286,7 +267,7 @@ mod tests {
286
267
assert_eq ! ( String :: from( totp. secret. clone( ) ) , "JBSWY3DPEHPK3PXP" ) ;
287
268
assert_eq ! ( totp. period, 30 ) ;
288
269
assert_eq ! ( totp. digits, 6 ) ;
289
- assert_eq ! ( totp. username, "" ) ;
270
+ assert_eq ! ( totp. username, None ) ;
290
271
assert_eq ! ( totp. algorithm, OTPHashAlgorithm :: Sha1 ) ;
291
272
assert ! ( totp. issuer. is_none( ) ) ;
292
273
}
@@ -299,7 +280,7 @@ mod tests {
299
280
Credential :: Passkey ( passkey) => {
300
281
assert_eq ! ( passkey. credential_id. to_string( ) , "6NiHiekW4ZY8vYHa-ucbvA" ) ;
301
282
assert_eq ! ( passkey. rp_id, "123" ) ;
302
- assert_eq ! ( passkey. user_name , "" ) ;
283
+ assert_eq ! ( passkey. username , "" ) ;
303
284
assert_eq ! ( passkey. user_display_name, "" ) ;
304
285
assert_eq ! ( String :: from( passkey. user_handle. clone( ) ) , "AAECAwQFBg" ) ;
305
286
assert_eq ! ( String :: from( passkey. key. clone( ) ) , "AAECAwQFBg" ) ;
@@ -312,7 +293,7 @@ mod tests {
312
293
313
294
match credential {
314
295
Credential :: Note ( n) => {
315
- assert_eq ! ( n. content, "My note" ) ;
296
+ assert_eq ! ( n. content. value . 0 , "My note" ) ;
316
297
}
317
298
_ => panic ! ( "Expected Credential::Passkey" ) ,
318
299
}
0 commit comments