Skip to content

Commit 2f0fdf2

Browse files
authored
Merge pull request #144 from linux-credentials/push-stsupkxpwqou
Clean up a few things
2 parents b54bfbc + 9dcfe53 commit 2f0fdf2

7 files changed

Lines changed: 16 additions & 52 deletions

File tree

credentialsd-common/src/model.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,29 @@ pub enum CredentialType {
3030
// Password,
3131
}
3232

33-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
33+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)]
3434
pub struct Device {
3535
pub id: String,
3636
pub transport: Transport,
3737
}
3838

39-
#[derive(Debug, Serialize, Deserialize, Type)]
39+
#[derive(Clone, Debug, Serialize, Deserialize, Type)]
4040
pub enum Operation {
4141
Create,
4242
Get,
4343
}
4444

45-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
45+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)]
46+
#[zvariant(signature = "s")]
4647
pub enum Transport {
48+
#[serde(rename = "BLE")]
4749
Ble,
4850
HybridLinked,
4951
HybridQr,
5052
Internal,
53+
#[serde(rename = "NFC")]
5154
Nfc,
55+
#[serde(rename = "USB")]
5256
Usb,
5357
}
5458

credentialsd-common/src/server.rs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use serde::{
77
de::{DeserializeSeed, Error, Visitor},
88
};
99
use zvariant::{
10-
self, Array, DeserializeDict, DynamicDeserialize, LE, NoneValue, Optional, OwnedValue,
10+
self, Array, DeserializeDict, DynamicDeserialize, NoneValue, Optional, OwnedValue,
1111
SerializeDict, Signature, Structure, StructureBuilder, Type, Value, signature::Fields,
1212
};
1313

14-
use crate::model::{BackgroundEvent, Operation, RequestingApplication};
14+
use crate::model::{BackgroundEvent, Device, Operation, RequestingApplication};
1515

1616
const TAG_VALUE_SIGNATURE: &Signature = &Signature::Structure(Fields::Static {
1717
fields: &[&Signature::U8, &Signature::Variant],
@@ -175,43 +175,6 @@ impl From<crate::model::Credential> for Credential {
175175
}
176176
}
177177

178-
#[derive(SerializeDict, DeserializeDict, Type)]
179-
#[zvariant(signature = "a{sv}")]
180-
pub struct Device {
181-
pub id: String,
182-
pub transport: String,
183-
}
184-
185-
impl TryFrom<Value<'_>> for Device {
186-
type Error = zvariant::Error;
187-
fn try_from(value: Value<'_>) -> std::result::Result<Self, Self::Error> {
188-
let ctx = zvariant::serialized::Context::new_dbus(LE, 0);
189-
let encoded = zvariant::to_bytes(ctx, &value)?;
190-
let device: Device = encoded.deserialize()?.0;
191-
Ok(device)
192-
}
193-
}
194-
195-
impl From<crate::model::Device> for Device {
196-
fn from(value: crate::model::Device) -> Self {
197-
Device {
198-
id: value.id,
199-
transport: value.transport.as_str().to_owned(),
200-
}
201-
}
202-
}
203-
204-
impl TryFrom<Device> for crate::model::Device {
205-
type Error = ();
206-
fn try_from(value: Device) -> std::result::Result<Self, Self::Error> {
207-
let transport = value.transport.try_into().map_err(|_| ())?;
208-
Ok(Self {
209-
id: value.id,
210-
transport,
211-
})
212-
}
213-
}
214-
215178
impl TryFrom<&Value<'_>> for crate::model::Error {
216179
type Error = zvariant::Error;
217180

credentialsd-ui/src/client.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ impl FlowController for DbusCredentialClient {
2424
async fn get_available_public_key_devices(
2525
&self,
2626
) -> std::result::Result<Vec<credentialsd_common::model::Device>, ()> {
27-
let dbus_devices = self
28-
.proxy()
27+
self.proxy()
2928
.await?
3029
.get_available_public_key_devices()
3130
.await
3231
.map_err(|err| {
3332
tracing::error!("Failed to retrieve available devices/transports: {err}")
34-
})?;
35-
dbus_devices.into_iter().map(|d| d.try_into()).collect()
33+
})
3634
}
3735

3836
async fn get_hybrid_credential(&mut self) -> std::result::Result<(), ()> {

credentialsd-ui/src/dbus.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use async_std::channel::Sender;
22
use credentialsd_common::{
3-
model::BackgroundEvent,
4-
server::{Device, RequestId, ViewRequest},
3+
model::{BackgroundEvent, Device},
4+
server::{RequestId, ViewRequest},
55
};
66
use zbus::{fdo, interface, proxy};
77

credentialsd/src/credential_service/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ impl<
146146
.map_err(|err| err.to_string());
147147
if let Err(err) = launch_ui_response {
148148
tracing::error!("Failed to launch UI for credentials: {err}. Cancelling request.");
149-
_ = self.ctx.lock().unwrap().take();
150149
let err = Err(CredentialServiceError::Internal(err));
151150
let ctx = self.ctx.lock().unwrap().take().unwrap();
152151
ctx.response_channel

credentialsd/src/dbus/flow_control.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::future::Future;
55
use std::{collections::VecDeque, fmt::Debug, sync::Arc};
66

77
use credentialsd_common::model::{
8-
BackgroundEvent, Error as CredentialServiceError, RequestingApplication, WebAuthnError,
8+
BackgroundEvent, Device, Error as CredentialServiceError, RequestingApplication, WebAuthnError,
99
};
10-
use credentialsd_common::server::{Device, RequestId, WindowHandle};
10+
use credentialsd_common::server::{RequestId, WindowHandle};
1111
use futures_lite::StreamExt;
1212
use tokio::sync::oneshot;
1313
use tokio::{

credentialsd/src/dbus/gateway.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ impl From<WebAuthnError> for Error {
602602
mod test {
603603
use credentialsd_common::model::WebAuthnError;
604604

605-
use crate::webauthn::{AppId, NavigationContext, Origin};
605+
use crate::webauthn::{NavigationContext, Origin};
606606

607607
use super::check_origin_from_privileged_client;
608608
fn check_same_origin(origin: &str) -> Result<NavigationContext, WebAuthnError> {

0 commit comments

Comments
 (0)