Skip to content

Commit 66f607e

Browse files
Add IoError to TransportError
1 parent 145cbf2 commit 66f607e

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

libwebauthn/src/transport/ble/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use crate::proto::ctap1::apdu::{ApduRequest, ApduResponse};
77
use crate::proto::ctap2::cbor::{CborRequest, CborResponse};
88
use crate::proto::CtapError;
99
use crate::transport::ble::btleplug;
10-
use crate::transport::channel::{
11-
AuthTokenData, Channel, ChannelStatus, Ctap2AuthTokenStore,
12-
};
10+
use crate::transport::channel::{AuthTokenData, Channel, ChannelStatus, Ctap2AuthTokenStore};
1311
use crate::transport::device::SupportedProtocols;
1412
use crate::transport::error::{Error, TransportError};
1513
use crate::UxUpdate;
@@ -129,7 +127,9 @@ impl<'a> Channel for BleChannel<'a> {
129127
debug!("Sending CBOR request");
130128
trace!(?request);
131129

132-
let cbor_request = request.raw_long().or(Err(TransportError::InvalidFraming))?;
130+
let cbor_request = request
131+
.raw_long()
132+
.map_err(|e| TransportError::IoError(e.kind()))?;
133133
let request_frame = BleFrame::new(BleCommand::Msg, &cbor_request);
134134
self.connection
135135
.frame_send(&request_frame)

libwebauthn/src/transport/cable/tunnel.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ async fn connection_send(
453453
debug!("Sending CBOR request");
454454
trace!(?request);
455455

456-
let cbor_request = request.raw_long().or(Err(TransportError::InvalidFraming))?;
456+
let cbor_request = request
457+
.raw_long()
458+
.map_err(|e| TransportError::IoError(e.kind()))?;
457459
if cbor_request.len() > MAX_CBOR_SIZE {
458460
error!(
459461
cbor_request_len = cbor_request.len(),

libwebauthn/src/transport/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pub enum TransportError {
4040
InvalidKey,
4141
#[error("invalid signature")]
4242
InvalidSignature,
43+
#[error("input/output error: {0}")]
44+
IoError(std::io::ErrorKind),
4345
}
4446

4547
#[derive(thiserror::Error, Debug, Copy, Clone, PartialEq)]

libwebauthn/src/transport/hid/channel.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,9 @@ impl Channel for HidChannel<'_> {
448448
let cid = self.init.cid;
449449
debug!({ cid }, "Sending APDU request");
450450
trace!(?request);
451-
let Ok(apdu_raw) = request.raw_long() else {
452-
warn!("Failed to serialize APDU request");
453-
return Err(Error::Transport(TransportError::InvalidFraming));
454-
};
451+
let apdu_raw = request
452+
.raw_long()
453+
.map_err(|e| TransportError::IoError(e.kind()))?;
455454
self.hid_send(&HidMessage::new(cid, HidCommand::Msg, &apdu_raw))
456455
.await?;
457456
Ok(())

0 commit comments

Comments
 (0)