|
| 1 | +//! Types for serializing across D-Bus instances |
| 2 | +
|
1 | 3 | use std::collections::HashMap; |
2 | 4 |
|
3 | 5 | use serde::{Deserialize, Serialize}; |
4 | | -use zbus::zvariant::{self, DeserializeDict, LE, Optional, OwnedValue, SerializeDict, Type, Value}; |
| 6 | +use zvariant::{self, DeserializeDict, LE, Optional, OwnedValue, SerializeDict, Type, Value}; |
5 | 7 |
|
6 | | -use crate::model::{Operation, ViewUpdate}; |
| 8 | +use crate::model::Operation; |
7 | 9 |
|
8 | 10 | #[derive(Clone, Debug, Serialize, Deserialize, Type)] |
9 | 11 | pub enum BackgroundEvent { |
@@ -96,89 +98,6 @@ impl From<CreatePublicKeyCredentialResponse> for CreateCredentialResponse { |
96 | 98 | } |
97 | 99 | } |
98 | 100 |
|
99 | | -/// Updates to send to the client |
100 | | -#[derive(Serialize, Deserialize, Type)] |
101 | | -pub enum ClientUpdate { |
102 | | - SetTitle(OwnedValue), |
103 | | - SetDevices(OwnedValue), |
104 | | - SetCredentials(OwnedValue), |
105 | | - |
106 | | - WaitingForDevice(OwnedValue), |
107 | | - SelectingDevice(OwnedValue), |
108 | | - |
109 | | - UsbNeedsPin(OwnedValue), |
110 | | - UsbNeedsUserVerification(OwnedValue), |
111 | | - UsbNeedsUserPresence(OwnedValue), |
112 | | - |
113 | | - HybridNeedsQrCode(OwnedValue), |
114 | | - HybridConnecting(OwnedValue), |
115 | | - HybridConnected(OwnedValue), |
116 | | - |
117 | | - Completed(OwnedValue), |
118 | | - Failed(OwnedValue), |
119 | | -} |
120 | | - |
121 | | -impl TryFrom<ClientUpdate> for ViewUpdate { |
122 | | - type Error = zvariant::Error; |
123 | | - fn try_from(value: ClientUpdate) -> std::result::Result<ViewUpdate, Self::Error> { |
124 | | - match value { |
125 | | - ClientUpdate::SetTitle(v) => v.try_into().map(Self::SetTitle), |
126 | | - ClientUpdate::SetDevices(v) => { |
127 | | - let dbus_devices: Vec<Device> = Value::<'_>::from(v).try_into()?; |
128 | | - let devices: std::result::Result<Vec<crate::model::Device>, zvariant::Error> = |
129 | | - dbus_devices |
130 | | - .into_iter() |
131 | | - .map(|d| { |
132 | | - d.try_into().map_err(|_| { |
133 | | - zvariant::Error::Message( |
134 | | - "Could not deserialize devices".to_string(), |
135 | | - ) |
136 | | - }) |
137 | | - }) |
138 | | - .collect(); |
139 | | - Ok(Self::SetDevices(devices?)) |
140 | | - } |
141 | | - ClientUpdate::SetCredentials(v) => { |
142 | | - let dbus_credentials: Vec<Credential> = Value::<'_>::from(v).try_into()?; |
143 | | - let credentials: std::result::Result< |
144 | | - Vec<crate::model::Credential>, |
145 | | - zvariant::Error, |
146 | | - > = dbus_credentials |
147 | | - .into_iter() |
148 | | - .map(|creds| Ok(creds.into())) |
149 | | - .collect(); |
150 | | - Ok(Self::SetCredentials(credentials?)) |
151 | | - } |
152 | | - |
153 | | - ClientUpdate::WaitingForDevice(v) => { |
154 | | - let dbus_device: Device = Value::<'_>::from(v).try_into()?; |
155 | | - let device: crate::model::Device = dbus_device.try_into().map_err(|_| { |
156 | | - zvariant::Error::Message("Could not deserialize device".to_string()) |
157 | | - })?; |
158 | | - Ok(Self::WaitingForDevice(device)) |
159 | | - } |
160 | | - ClientUpdate::SelectingDevice(_) => Ok(Self::SelectingDevice), |
161 | | - |
162 | | - ClientUpdate::UsbNeedsPin(v) => v.try_into().map(|x: i32| { |
163 | | - let attempts_left = if x == -1 { None } else { Some(x as u32) }; |
164 | | - Self::UsbNeedsPin { attempts_left } |
165 | | - }), |
166 | | - ClientUpdate::UsbNeedsUserVerification(v) => v.try_into().map(|x: i32| { |
167 | | - let attempts_left = if x == -1 { None } else { Some(x as u32) }; |
168 | | - Self::UsbNeedsUserVerification { attempts_left } |
169 | | - }), |
170 | | - ClientUpdate::UsbNeedsUserPresence(_) => Ok(Self::UsbNeedsUserPresence), |
171 | | - |
172 | | - ClientUpdate::HybridNeedsQrCode(v) => v.try_into().map(Self::HybridNeedsQrCode), |
173 | | - ClientUpdate::HybridConnecting(_) => Ok(Self::HybridConnecting), |
174 | | - ClientUpdate::HybridConnected(_) => Ok(Self::HybridConnected), |
175 | | - |
176 | | - ClientUpdate::Completed(_) => Ok(Self::Completed), |
177 | | - ClientUpdate::Failed(v) => v.try_into().map(Self::Failed), |
178 | | - } |
179 | | - } |
180 | | -} |
181 | | - |
182 | 101 | #[derive(SerializeDict, DeserializeDict, Type, Value)] |
183 | 102 | #[zvariant(signature = "dict")] |
184 | 103 | pub struct Credential { |
@@ -207,18 +126,6 @@ impl From<crate::model::Credential> for Credential { |
207 | 126 | } |
208 | 127 | } |
209 | 128 |
|
210 | | -/* |
211 | | -impl TryFrom<Value<'_>> for Credential { |
212 | | - type Error = zvariant::Error; |
213 | | - fn try_from(value: Value<'_>) -> std::result::Result<Self, Self::Error> { |
214 | | - let ctx = zvariant::serialized::Context::new_dbus(LE, 0); |
215 | | - let encoded = zvariant::to_bytes(ctx, &value)?; |
216 | | - let credential: Credential = encoded.deserialize()?.0; |
217 | | - Ok(credential) |
218 | | - } |
219 | | -} |
220 | | - */ |
221 | | - |
222 | 129 | #[derive(SerializeDict, DeserializeDict, Type)] |
223 | 130 | #[zvariant(signature = "a{sv}")] |
224 | 131 | pub struct Device { |
|
0 commit comments