Skip to content

Commit 7d732d7

Browse files
committed
Rebase on v0.3.0 new errors, etc.
1 parent ec2d1bc commit 7d732d7

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

.clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
type-complexity-threshold = 384
2+
too-many-arguments-threshold = 8

src/virtualdevices/software_u2f.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl SoftwareU2FToken {
2020
_challenge: Vec<u8>,
2121
_application: crate::AppId,
2222
_key_handles: Vec<crate::KeyHandle>,
23-
) -> Result<crate::RegisterResult, crate::Error> {
23+
) -> crate::Result<crate::RegisterResult> {
2424
Ok((vec![0u8; 16], self.dev_info()))
2525
}
2626

@@ -33,7 +33,7 @@ impl SoftwareU2FToken {
3333
_challenge: Vec<u8>,
3434
_app_ids: Vec<crate::AppId>,
3535
_key_handles: Vec<crate::KeyHandle>,
36-
) -> Result<crate::SignResult, crate::Error> {
36+
) -> crate::Result<crate::SignResult> {
3737
Ok((vec![0u8; 0], vec![0u8; 0], vec![0u8; 0], self.dev_info()))
3838
}
3939

src/virtualdevices/webdriver/testtoken.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
use crate::errors;
56
use crate::virtualdevices::software_u2f::SoftwareU2FToken;
6-
use crate::{Error, RegisterFlags, RegisterResult, SignFlags, SignResult};
7+
use crate::{RegisterFlags, RegisterResult, SignFlags, SignResult};
78

89
pub enum TestWireProtocol {
910
CTAP1,
@@ -109,7 +110,7 @@ impl TestToken {
109110
false
110111
}
111112

112-
pub fn register(&self) -> Result<RegisterResult, Error> {
113+
pub fn register(&self) -> crate::Result<RegisterResult> {
113114
if self.u2f_impl.is_some() {
114115
return self.u2f_impl.as_ref().unwrap().register(
115116
RegisterFlags::empty(),
@@ -119,10 +120,12 @@ impl TestToken {
119120
vec![],
120121
);
121122
}
122-
Err(Error::Unknown)
123+
Err(errors::AuthenticatorError::U2FToken(
124+
errors::U2FTokenError::Unknown,
125+
))
123126
}
124127

125-
pub fn sign(&self) -> Result<SignResult, Error> {
128+
pub fn sign(&self) -> crate::Result<SignResult> {
126129
if self.u2f_impl.is_some() {
127130
return self.u2f_impl.as_ref().unwrap().sign(
128131
SignFlags::empty(),
@@ -132,6 +135,8 @@ impl TestToken {
132135
vec![],
133136
);
134137
}
135-
Err(Error::Unknown)
138+
Err(errors::AuthenticatorError::U2FToken(
139+
errors::U2FTokenError::Unknown,
140+
))
136141
}
137142
}

src/virtualdevices/webdriver/virtualmanager.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::vec;
1111
use std::{io, string, thread};
1212

1313
use crate::authenticatorservice::AuthenticatorTransport;
14+
use crate::errors;
1415
use crate::statecallback::StateCallback;
1516
use crate::virtualdevices::webdriver::{testtoken, web_api};
1617

@@ -66,11 +67,13 @@ impl AuthenticatorTransport for VirtualManager {
6667
_application: crate::AppId,
6768
_key_handles: Vec<crate::KeyHandle>,
6869
_status: Sender<crate::StatusUpdate>,
69-
callback: StateCallback<Result<crate::RegisterResult, crate::Error>>,
70-
) -> Result<(), crate::Error> {
70+
callback: StateCallback<crate::Result<crate::RegisterResult>>,
71+
) -> crate::Result<()> {
7172
if self.rloop.is_some() {
7273
error!("WebDriver state error, prior operation never cancelled.");
73-
return Err(crate::Error::Unknown);
74+
return Err(errors::AuthenticatorError::U2FToken(
75+
errors::U2FTokenError::Unknown,
76+
));
7477
}
7578

7679
let state = self.state.clone();
@@ -93,7 +96,7 @@ impl AuthenticatorTransport for VirtualManager {
9396
},
9497
timeout
9598
),
96-
|_| Err(crate::Error::Unknown)
99+
|_| Err(errors::AuthenticatorError::Platform)
97100
);
98101

99102
self.rloop = Some(rloop);
@@ -108,11 +111,13 @@ impl AuthenticatorTransport for VirtualManager {
108111
_app_ids: Vec<crate::AppId>,
109112
_key_handles: Vec<crate::KeyHandle>,
110113
_status: Sender<crate::StatusUpdate>,
111-
callback: StateCallback<Result<crate::SignResult, crate::Error>>,
112-
) -> Result<(), crate::Error> {
114+
callback: StateCallback<crate::Result<crate::SignResult>>,
115+
) -> crate::Result<()> {
113116
if self.rloop.is_some() {
114117
error!("WebDriver state error, prior operation never cancelled.");
115-
return Err(crate::Error::Unknown);
118+
return Err(errors::AuthenticatorError::U2FToken(
119+
errors::U2FTokenError::Unknown,
120+
));
116121
}
117122

118123
let state = self.state.clone();
@@ -135,14 +140,14 @@ impl AuthenticatorTransport for VirtualManager {
135140
},
136141
timeout
137142
),
138-
|_| Err(crate::Error::Unknown)
143+
|_| Err(errors::AuthenticatorError::Platform)
139144
);
140145

141146
self.rloop = Some(rloop);
142147
Ok(())
143148
}
144149

145-
fn cancel(&mut self) -> Result<(), crate::Error> {
150+
fn cancel(&mut self) -> crate::Result<()> {
146151
if let Some(r) = self.rloop.take() {
147152
debug!("WebDriver operation cancelled.");
148153
r.cancel();

src/virtualdevices/webdriver/web_api.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ mod handlers {
240240
};
241241
}
242242

243-
pub fn validate_rp_id(rp_id: &String) -> Result<(), crate::Error> {
244-
if let Ok(uri) = rp_id.parse::<uri::Uri>().map_err(|_| crate::Error::Unknown) {
243+
pub fn validate_rp_id(rp_id: &String) -> crate::Result<()> {
244+
if let Ok(uri) = rp_id.parse::<uri::Uri>().map_err(|_| {
245+
crate::errors::AuthenticatorError::U2FToken(crate::errors::U2FTokenError::Unknown)
246+
}) {
245247
if uri.scheme().is_none()
246248
&& uri.path_and_query().is_none()
247249
&& uri.port().is_none()
@@ -256,7 +258,9 @@ mod handlers {
256258
}
257259
}
258260
}
259-
Err(crate::Error::Unknown)
261+
Err(crate::errors::AuthenticatorError::U2FToken(
262+
crate::errors::U2FTokenError::Unknown,
263+
))
260264
}
261265

262266
pub async fn authenticator_add(

0 commit comments

Comments
 (0)