@@ -11,7 +11,7 @@ use zvariant::{
1111 SerializeDict , Signature , Str , Structure , StructureBuilder , Type , Value , signature:: Fields ,
1212} ;
1313
14- use crate :: model:: { BackendRequest , Device , Operation , RequestId , RequestingApplication } ;
14+ use crate :: model:: { Device , Operation , RequestId , RequestingApplication , UserInteractedEvent } ;
1515
1616const TAG_VALUE_SIGNATURE : & Signature = & Signature :: Structure ( Fields :: Static {
1717 fields : & [ & Signature :: U32 , & Signature :: Variant ] ,
@@ -49,12 +49,12 @@ const BACKGROUND_EVENT_ERROR_CREDENTIAL_EXCLUDED: u32 = 0x80000006;
4949const BACKGROUND_EVENT_ERROR_PIN_ATTEMPTS_EXHAUSTED : u32 = 0x80000007 ;
5050const BACKGROUND_EVENT_ERROR_PIN_NOT_SET : u32 = 0x80000008 ;
5151
52- const BACKEND_REQUEST_START_HYBRID_DISCOVERY : u32 = 0x01 ;
53- const BACKEND_REQUEST_START_USB_DISCOVERY : u32 = 0x02 ;
54- const BACKEND_REQUEST_START_NFC_DISCOVERY : u32 = 0x03 ;
55- const BACKEND_REQUEST_ENTER_CLIENT_PIN : u32 = 0x04 ;
56- const BACKEND_REQUEST_SELECT_CREDENTIAL : u32 = 0x05 ;
57- const BACKEND_REQUEST_CANCEL_REQUEST : u32 = 0x06 ;
52+ const USER_INTERACTED_EVENT_HYBRID_DISCOVERY_REQUESTED : u32 = 0x01 ;
53+ const USER_INTERACTED_EVENT_NFC_DISCOVERY_REQUESTED : u32 = 0x02 ;
54+ const USER_INTERACTED_EVENT_USB_DISCOVERY_REQUESTED : u32 = 0x03 ;
55+ const USER_INTERACTED_EVENT_CLIENT_PIN_ENTERED : u32 = 0x04 ;
56+ const USER_INTERACTED_EVENT_CREDENTIAL_SELECTED : u32 = 0x05 ;
57+ const USER_INTERACTED_EVENT_REQUEST_CANCELLED : u32 = 0x06 ;
5858
5959/// Flattened enum BackgroundEvent for sending across D-Bus.
6060#[ derive( Debug , Clone , PartialEq ) ]
@@ -274,94 +274,6 @@ impl<'de> Deserialize<'de> for BackgroundEvent {
274274 }
275275}
276276
277- impl Type for BackendRequest {
278- const SIGNATURE : & ' static Signature = TAG_VALUE_SIGNATURE ;
279- }
280-
281- impl From < & BackendRequest > for Structure < ' _ > {
282- fn from ( value : & BackendRequest ) -> Self {
283- match value {
284- BackendRequest :: StartHybridDiscovery => tag_value_to_struct ( 0x01 , None ) ,
285- BackendRequest :: StartNfcDiscovery => tag_value_to_struct ( 0x02 , None ) ,
286- BackendRequest :: StartUsbDiscovery => tag_value_to_struct ( 0x03 , None ) ,
287- BackendRequest :: EnterClientPin ( pin) => {
288- tag_value_to_struct ( 0x04 , Some ( Value :: Str ( pin. into ( ) ) ) )
289- }
290- BackendRequest :: SelectCredential ( credential_id) => {
291- tag_value_to_struct ( 0x05 , Some ( Value :: Str ( credential_id. into ( ) ) ) )
292- }
293- BackendRequest :: CancelRequest => tag_value_to_struct ( 0x06 , None ) ,
294- }
295- }
296- }
297-
298- impl TryFrom < & Structure < ' _ > > for BackendRequest {
299- type Error = zvariant:: Error ;
300-
301- fn try_from ( value : & Structure < ' _ > ) -> Result < Self , Self :: Error > {
302- let ( tag, value) = parse_tag_value_struct ( value) ?;
303-
304- match tag {
305- 0x01 => Ok ( BackendRequest :: StartHybridDiscovery ) ,
306- 0x02 => Ok ( BackendRequest :: StartNfcDiscovery ) ,
307- 0x03 => Ok ( BackendRequest :: StartUsbDiscovery ) ,
308- 0x04 => {
309- let s: Str = value. downcast_ref ( ) ?;
310- if s. is_empty ( ) {
311- return Err ( zvariant:: Error :: invalid_length (
312- s. len ( ) ,
313- & "a non-empty string" ,
314- ) ) ;
315- }
316- Ok ( BackendRequest :: EnterClientPin ( s. as_str ( ) . to_string ( ) ) )
317- }
318- 0x05 => {
319- let s: Str = value. downcast_ref ( ) ?;
320- if s. is_empty ( ) {
321- return Err ( zvariant:: Error :: invalid_length (
322- s. len ( ) ,
323- & "a non-empty string" ,
324- ) ) ;
325- }
326- Ok ( BackendRequest :: SelectCredential ( s. as_str ( ) . to_string ( ) ) )
327- }
328- 0x06 => Ok ( BackendRequest :: CancelRequest ) ,
329- _ => Err ( zvariant:: Error :: Message ( format ! (
330- "Unknown BackendRequest tag : {tag}"
331- ) ) ) ,
332- }
333- }
334- }
335-
336- impl Serialize for BackendRequest {
337- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
338- where
339- S : serde:: Serializer ,
340- {
341- let structure: Structure = self . into ( ) ;
342- structure. serialize ( serializer)
343- }
344- }
345-
346- impl < ' de > Deserialize < ' de > for BackendRequest {
347- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
348- where
349- D : serde:: Deserializer < ' de > ,
350- {
351- let d = Structure :: deserializer_for_signature ( TAG_VALUE_SIGNATURE ) . map_err ( |err| {
352- D :: Error :: custom ( format ! (
353- "could not create deserializer for tag-value struct: {err}"
354- ) )
355- } ) ?;
356- let structure = d. deserialize ( deserializer) ?;
357- ( & structure) . try_into ( ) . map_err ( |err| {
358- D :: Error :: custom ( format ! (
359- "could not deserialize structure into BackendRequest: {err}"
360- ) )
361- } )
362- }
363- }
364-
365277#[ derive( Clone , Debug , DeserializeDict , Type ) ]
366278#[ zvariant( signature = "dict" ) ]
367279pub struct CreateCredentialRequest {
@@ -507,6 +419,116 @@ impl From<GetPublicKeyCredentialResponse> for GetCredentialResponse {
507419 }
508420}
509421
422+ impl Type for UserInteractedEvent {
423+ const SIGNATURE : & ' static Signature = TAG_VALUE_SIGNATURE ;
424+ }
425+
426+ impl From < & UserInteractedEvent > for Structure < ' _ > {
427+ fn from ( value : & UserInteractedEvent ) -> Self {
428+ match value {
429+ UserInteractedEvent :: HybridDiscoveryRequested => {
430+ tag_value_to_struct ( USER_INTERACTED_EVENT_HYBRID_DISCOVERY_REQUESTED , None )
431+ }
432+ UserInteractedEvent :: NfcDiscoveryRequested => {
433+ tag_value_to_struct ( USER_INTERACTED_EVENT_NFC_DISCOVERY_REQUESTED , None )
434+ }
435+ UserInteractedEvent :: UsbDiscoveryRequested => {
436+ tag_value_to_struct ( USER_INTERACTED_EVENT_USB_DISCOVERY_REQUESTED , None )
437+ }
438+ UserInteractedEvent :: ClientPinEntered ( pin) => tag_value_to_struct (
439+ USER_INTERACTED_EVENT_CLIENT_PIN_ENTERED ,
440+ Some ( Value :: Str ( pin. into ( ) ) ) ,
441+ ) ,
442+ UserInteractedEvent :: CredentialSelected ( credential_id) => tag_value_to_struct (
443+ USER_INTERACTED_EVENT_CREDENTIAL_SELECTED ,
444+ Some ( Value :: Str ( credential_id. into ( ) ) ) ,
445+ ) ,
446+ UserInteractedEvent :: RequestCancelled => {
447+ tag_value_to_struct ( USER_INTERACTED_EVENT_REQUEST_CANCELLED , None )
448+ }
449+ }
450+ }
451+ }
452+
453+ impl TryFrom < & Structure < ' _ > > for UserInteractedEvent {
454+ type Error = zvariant:: Error ;
455+
456+ fn try_from ( value : & Structure < ' _ > ) -> Result < Self , Self :: Error > {
457+ let ( tag, value) = parse_tag_value_struct ( value) ?;
458+
459+ match tag {
460+ USER_INTERACTED_EVENT_HYBRID_DISCOVERY_REQUESTED => {
461+ Ok ( UserInteractedEvent :: HybridDiscoveryRequested )
462+ }
463+ USER_INTERACTED_EVENT_NFC_DISCOVERY_REQUESTED => {
464+ Ok ( UserInteractedEvent :: NfcDiscoveryRequested )
465+ }
466+ USER_INTERACTED_EVENT_USB_DISCOVERY_REQUESTED => {
467+ Ok ( UserInteractedEvent :: UsbDiscoveryRequested )
468+ }
469+ USER_INTERACTED_EVENT_CLIENT_PIN_ENTERED => {
470+ let s: Str = value. downcast_ref ( ) ?;
471+ if s. is_empty ( ) {
472+ return Err ( zvariant:: Error :: invalid_length (
473+ s. len ( ) ,
474+ & "a non-empty string" ,
475+ ) ) ;
476+ }
477+ Ok ( UserInteractedEvent :: ClientPinEntered (
478+ s. as_str ( ) . to_string ( ) ,
479+ ) )
480+ }
481+ USER_INTERACTED_EVENT_CREDENTIAL_SELECTED => {
482+ let s: Str = value. downcast_ref ( ) ?;
483+ if s. is_empty ( ) {
484+ return Err ( zvariant:: Error :: invalid_length (
485+ s. len ( ) ,
486+ & "a non-empty string" ,
487+ ) ) ;
488+ }
489+ Ok ( UserInteractedEvent :: CredentialSelected (
490+ s. as_str ( ) . to_string ( ) ,
491+ ) )
492+ }
493+ USER_INTERACTED_EVENT_REQUEST_CANCELLED => Ok ( UserInteractedEvent :: RequestCancelled ) ,
494+ _ => Err ( zvariant:: Error :: Message ( format ! (
495+ "Unknown {} tag : {tag}" ,
496+ stringify!( UserInteractedEvent )
497+ ) ) ) ,
498+ }
499+ }
500+ }
501+
502+ impl Serialize for UserInteractedEvent {
503+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
504+ where
505+ S : serde:: Serializer ,
506+ {
507+ let structure: Structure = self . into ( ) ;
508+ structure. serialize ( serializer)
509+ }
510+ }
511+
512+ impl < ' de > Deserialize < ' de > for UserInteractedEvent {
513+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
514+ where
515+ D : serde:: Deserializer < ' de > ,
516+ {
517+ let d = Structure :: deserializer_for_signature ( TAG_VALUE_SIGNATURE ) . map_err ( |err| {
518+ D :: Error :: custom ( format ! (
519+ "could not create deserializer for tag-value struct: {err}"
520+ ) )
521+ } ) ?;
522+ let structure = d. deserialize ( deserializer) ?;
523+ ( & structure) . try_into ( ) . map_err ( |err| {
524+ D :: Error :: custom ( format ! (
525+ "could not deserialize structure into {}: {err}" ,
526+ stringify!( UserInteractedEvent )
527+ ) )
528+ } )
529+ }
530+ }
531+
510532#[ derive( Clone , Debug , Serialize , Deserialize , Type ) ]
511533pub struct ViewRequest {
512534 pub operation : Operation ,
0 commit comments