@@ -139,8 +139,8 @@ impl From<&Ctap1Transport> for Ctap2Transport {
139139
140140#[ derive( Debug , Clone , Serialize , Deserialize ) ]
141141pub struct Ctap2PublicKeyCredentialDescriptor {
142- pub r#type : Ctap2PublicKeyCredentialType ,
143142 pub id : ByteBuf ,
143+ pub r#type : Ctap2PublicKeyCredentialType ,
144144
145145 #[ serde( skip_serializing_if = "Option::is_none" ) ]
146146 pub transports : Option < Vec < Ctap2Transport > > ,
@@ -156,11 +156,11 @@ pub enum Ctap2COSEAlgorithmIdentifier {
156156
157157#[ derive( Debug , Clone , Copy , Serialize , Deserialize ) ]
158158pub struct Ctap2CredentialType {
159- #[ serde( rename = "type" ) ]
160- pub public_key_type : Ctap2PublicKeyCredentialType ,
161-
162159 #[ serde( rename = "alg" ) ]
163160 pub algorithm : Ctap2COSEAlgorithmIdentifier ,
161+
162+ #[ serde( rename = "type" ) ]
163+ pub public_key_type : Ctap2PublicKeyCredentialType ,
164164}
165165
166166impl Default for Ctap2CredentialType {
@@ -205,3 +205,40 @@ pub enum Ctap2UserVerificationOperation {
205205 GetPinToken ,
206206 None ,
207207}
208+
209+ #[ cfg( test) ]
210+ mod tests {
211+ use crate :: proto:: ctap2:: Ctap2PublicKeyCredentialDescriptor ;
212+
213+ use super :: { Ctap2CredentialType , Ctap2COSEAlgorithmIdentifier , Ctap2PublicKeyCredentialType } ;
214+ use serde_bytes:: ByteBuf ;
215+ use serde_cbor;
216+ use hex;
217+
218+ #[ test]
219+ /// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
220+ pub fn credential_type_field_serialization ( ) {
221+ let credential_type = Ctap2CredentialType {
222+ algorithm : Ctap2COSEAlgorithmIdentifier :: ES256 ,
223+ public_key_type : Ctap2PublicKeyCredentialType :: PublicKey ,
224+ } ;
225+ let serialized = serde_cbor:: to_vec ( & credential_type) . unwrap ( ) ;
226+ // Known good, verified by hand with cbor.me playground
227+ let expected = hex:: decode ( "a263616c672664747970656a7075626c69632d6b6579" ) . unwrap ( ) ;
228+ assert_eq ! ( serialized, expected) ;
229+ }
230+
231+ #[ test]
232+ /// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
233+ pub fn credential_descriptor_serialization ( ) {
234+ let credential_descriptor = Ctap2PublicKeyCredentialDescriptor {
235+ id : ByteBuf :: from ( vec ! [ 0x42 ] ) ,
236+ r#type : Ctap2PublicKeyCredentialType :: PublicKey ,
237+ transports : None ,
238+ } ;
239+ let serialized = serde_cbor:: to_vec ( & credential_descriptor) . unwrap ( ) ;
240+ // Known good, verified by hand with cbor.me playground
241+ let expected = hex:: decode ( "a2626964414264747970656a7075626c69632d6b6579" ) . unwrap ( ) ;
242+ assert_eq ! ( serialized, expected) ;
243+ }
244+ }
0 commit comments