1
+ use std:: collections:: HashMap ;
1
2
use serde_derive:: * ;
2
- use serde_json:: Value ;
3
3
4
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
4
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
5
5
#[ serde( rename = "publicKey" , rename_all = "camelCase" ) ]
6
6
pub struct PublicKeyCredentialCreationOptions {
7
7
pub rp : PublicKeyCredentialRpEntity ,
@@ -16,8 +16,8 @@ pub struct PublicKeyCredentialCreationOptions {
16
16
pub authenticator_selection : Option < AuthenticatorSelectionCriteria > ,
17
17
#[ serde( skip_serializing_if = "Option::is_none" ) ]
18
18
pub attestation : Option < AttestationConveyancePreference > ,
19
- #[ serde( skip_serializing_if = "Option::is_none " ) ]
20
- pub extensions : Option < Value > ,
19
+ #[ serde( default , skip_serializing_if = "Extensions::is_empty " ) ]
20
+ pub extensions : Extensions ,
21
21
}
22
22
23
23
#[ derive( Serialize , Deserialize , Clone , Debug ) ]
@@ -32,11 +32,11 @@ pub struct PublicKeyCredentialRequestOptions {
32
32
pub allow_credentials : Vec < PublicKeyCredentialDescriptor > ,
33
33
#[ serde( skip_serializing_if = "Option::is_none" ) ]
34
34
pub user_verification : Option < UserVerificationRequirement > ,
35
- #[ serde( skip_serializing_if = "Option::is_none " ) ]
36
- pub extensions : Option < Value > ,
35
+ #[ serde( default , skip_serializing_if = "Extensions::is_empty " ) ]
36
+ pub extensions : Extensions ,
37
37
}
38
38
39
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
39
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
40
40
pub struct PublicKeyCredentialRpEntity {
41
41
#[ serde( skip_serializing_if = "Option::is_none" ) ]
42
42
pub id : Option < String > ,
@@ -45,7 +45,7 @@ pub struct PublicKeyCredentialRpEntity {
45
45
pub icon : Option < String > ,
46
46
}
47
47
48
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
48
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
49
49
#[ serde( rename_all = "camelCase" ) ]
50
50
pub struct PublicKeyCredentialUserEntity {
51
51
pub id : String ,
@@ -55,14 +55,14 @@ pub struct PublicKeyCredentialUserEntity {
55
55
pub icon : Option < String > ,
56
56
}
57
57
58
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
58
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
59
59
pub struct PublicKeyCredentialParameters {
60
60
#[ serde( rename = "type" ) ]
61
61
pub auth_type : PublicKeyCredentialType ,
62
62
pub alg : i64 ,
63
63
}
64
64
65
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
65
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq ) ]
66
66
pub struct PublicKeyCredentialDescriptor {
67
67
#[ serde( rename = "type" ) ]
68
68
pub cred_type : PublicKeyCredentialType ,
@@ -77,13 +77,13 @@ impl PartialEq for PublicKeyCredentialDescriptor {
77
77
}
78
78
}
79
79
80
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
80
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
81
81
pub enum PublicKeyCredentialType {
82
82
#[ serde( rename = "public-key" ) ]
83
83
PublicKey ,
84
84
}
85
85
86
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
86
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
87
87
pub enum AuthenticatorTransport {
88
88
#[ serde( rename = "usb" ) ]
89
89
Usb ,
@@ -95,7 +95,7 @@ pub enum AuthenticatorTransport {
95
95
Internal ,
96
96
}
97
97
98
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
98
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
99
99
#[ serde( rename_all = "camelCase" ) ]
100
100
pub struct AuthenticatorSelectionCriteria {
101
101
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -106,7 +106,7 @@ pub struct AuthenticatorSelectionCriteria {
106
106
pub user_verification : Option < UserVerificationRequirement > ,
107
107
}
108
108
109
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
109
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
110
110
#[ serde( rename_all = "camelCase" ) ]
111
111
pub enum AuthenticatorAttachment {
112
112
Platform ,
@@ -122,7 +122,7 @@ pub enum UserVerificationRequirement {
122
122
Discouraged ,
123
123
}
124
124
125
- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
125
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
126
126
#[ serde( rename_all = "camelCase" ) ]
127
127
pub enum AttestationConveyancePreference {
128
128
None ,
@@ -178,3 +178,37 @@ pub enum TokenBindingStatus {
178
178
Present ,
179
179
Supported ,
180
180
}
181
+
182
+ #[ derive( Serialize , Deserialize , Clone , Debug , Default , Eq , PartialEq ) ]
183
+ #[ serde( rename_all = "camelCase" ) ]
184
+ pub struct Extensions {
185
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
186
+ pub prf : Option < PrfExtension > ,
187
+ }
188
+
189
+ impl Extensions {
190
+ pub fn is_empty ( & self ) -> bool {
191
+ self . prf . is_none ( )
192
+ }
193
+ }
194
+
195
+ // https://w3c.github.io/webauthn/#dictdef-authenticationextensionsprfinputs
196
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
197
+ #[ serde( rename_all = "camelCase" ) ]
198
+ pub struct PrfExtension {
199
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
200
+ pub eval : Option < AuthenticationExtensionsPRFValues > ,
201
+
202
+ // Only supported in authentication, not creation
203
+ #[ serde( default , skip_serializing_if = "HashMap::is_empty" ) ]
204
+ pub eval_by_credential : HashMap < String , AuthenticationExtensionsPRFValues > ,
205
+ }
206
+
207
+ // https://w3c.github.io/webauthn/#dictdef-authenticationextensionsprfvalues
208
+ #[ derive( Serialize , Deserialize , Clone , Debug , Eq , PartialEq ) ]
209
+ #[ serde( rename_all = "camelCase" ) ]
210
+ pub struct AuthenticationExtensionsPRFValues {
211
+ pub first : Vec < u8 > ,
212
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
213
+ pub second : Option < Vec < u8 > > ,
214
+ }
0 commit comments