@@ -12,14 +12,7 @@ use zvariant::{
1212 Signature , Structure , StructureBuilder , Type , Value , signature:: Fields ,
1313} ;
1414
15- use crate :: model:: Operation ;
16-
17- #[ derive( Clone , Debug ) ]
18-
19- pub enum BackgroundEvent {
20- UsbStateChanged ( crate :: model:: UsbState ) ,
21- HybridStateChanged ( crate :: model:: HybridState ) ,
22- }
15+ use crate :: model:: { BackgroundEvent , Operation } ;
2316
2417const TAG_VALUE_SIGNATURE : & ' static Signature = & Signature :: Structure ( Fields :: Static {
2518 fields : & [ & Signature :: U8 , & Signature :: Variant ] ,
@@ -42,7 +35,7 @@ impl Serialize for BackgroundEvent {
4235 let structure: Structure < ' _ > = state. into ( ) ;
4336 tuple. serialize_element ( & Value :: Structure ( structure) ) ?;
4437 }
45- Self :: HybridStateChanged ( state) => {
38+ Self :: HybridQrStateChanged ( state) => {
4639 tuple. serialize_element ( & 0x02_u8 ) ?;
4740 let structure: Structure < ' _ > = state. try_into ( ) . map_err ( |err| {
4841 S :: Error :: custom ( format ! (
@@ -95,7 +88,7 @@ impl<'de> Deserialize<'de> for BackgroundEvent {
9588 "could not deserialize HybridState from structure: {err}"
9689 ) )
9790 } ) ?;
98- Ok ( BackgroundEvent :: HybridStateChanged ( state) )
91+ Ok ( BackgroundEvent :: HybridQrStateChanged ( state) )
9992 }
10093 _ => Err ( D :: Error :: custom ( format ! (
10194 "Unknown BackgroundEvent tag : {tag}"
@@ -104,40 +97,6 @@ impl<'de> Deserialize<'de> for BackgroundEvent {
10497 }
10598}
10699
107- impl TryFrom < BackgroundEvent > for crate :: model:: BackgroundEvent {
108- type Error = zvariant:: Error ;
109-
110- fn try_from ( value : BackgroundEvent ) -> Result < Self , Self :: Error > {
111- match value {
112- BackgroundEvent :: HybridStateChanged ( hybrid_state_val) => Ok (
113- crate :: model:: BackgroundEvent :: HybridQrStateChanged ( hybrid_state_val) ,
114- ) ,
115- BackgroundEvent :: UsbStateChanged ( usb_state) => {
116- Ok ( crate :: model:: BackgroundEvent :: UsbStateChanged ( usb_state) )
117- }
118- }
119- }
120- }
121-
122- impl From < crate :: model:: BackgroundEvent > for BackgroundEvent {
123- fn from ( value : crate :: model:: BackgroundEvent ) -> Self {
124- match value {
125- crate :: model:: BackgroundEvent :: HybridQrStateChanged ( state) => {
126- BackgroundEvent :: HybridStateChanged ( state. into ( ) )
127- }
128- crate :: model:: BackgroundEvent :: UsbStateChanged ( state) => {
129- BackgroundEvent :: UsbStateChanged ( state. into ( ) )
130- /*
131- let state: UsbState = state.into();
132- let value = Value::new(state)
133- .try_to_owned()
134- .expect("non-file descriptor value to succeed");
135- */
136- }
137- }
138- }
139- }
140-
141100#[ derive( Clone , Debug , DeserializeDict , Type ) ]
142101#[ zvariant( signature = "dict" ) ]
143102pub struct CreateCredentialRequest {
@@ -1016,7 +975,7 @@ mod test {
1016975 #[ test]
1017976 fn test_serialize_background_hybrid_event ( ) {
1018977 let state = crate :: model:: HybridState :: Started ( "FIDO:/1234" . to_string ( ) ) ;
1019- let event = BackgroundEvent :: HybridStateChanged ( state) ;
978+ let event = BackgroundEvent :: HybridQrStateChanged ( state) ;
1020979 let ctx = zvariant:: serialized:: Context :: new_dbus ( zvariant:: BE , 0 ) ;
1021980 assert_eq ! ( "(yv)" , BackgroundEvent :: SIGNATURE . to_string( ) ) ;
1022981 let data = zvariant:: to_bytes ( ctx, & event) . unwrap ( ) ;
@@ -1033,13 +992,13 @@ mod test {
1033992 let event: BackgroundEvent = data. deserialize ( ) . unwrap ( ) . 0 ;
1034993 assert ! ( matches!(
1035994 event,
1036- BackgroundEvent :: HybridStateChanged ( crate :: model:: HybridState :: Completed )
995+ BackgroundEvent :: HybridQrStateChanged ( crate :: model:: HybridState :: Completed )
1037996 ) ) ;
1038997 }
1039998
1040999 #[ test]
10411000 fn test_round_trip_background_hybrid_event ( ) {
1042- let event = BackgroundEvent :: HybridStateChanged ( crate :: model:: HybridState :: Started (
1001+ let event = BackgroundEvent :: HybridQrStateChanged ( crate :: model:: HybridState :: Started (
10431002 String :: from ( "FIDO:/1234" ) ,
10441003 ) ) ;
10451004 let ctx = zvariant:: serialized:: Context :: new_dbus ( zvariant:: BE , 0 ) ;
@@ -1049,7 +1008,7 @@ mod test {
10491008 let event_2: BackgroundEvent = data2. deserialize ( ) . unwrap ( ) . 0 ;
10501009 assert ! ( matches!(
10511010 event_2,
1052- BackgroundEvent :: HybridStateChanged ( crate :: model:: HybridState :: Started ( ref f) ) if f == "FIDO:/1234"
1011+ BackgroundEvent :: HybridQrStateChanged ( crate :: model:: HybridState :: Started ( ref f) ) if f == "FIDO:/1234"
10531012 ) ) ;
10541013 }
10551014
0 commit comments