Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion libraries/opensk/src/ctap/hid/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ impl<E: Env> MessageAssembler<E> {

// If the packet is from the timed-out channel, send back a timeout error.
// Otherwise, proceed with processing the packet.
if cid == current_cid {
if cid == current_cid
&& matches!(processed_packet, ProcessedPacket::ContinuationPacket { .. })
Comment thread
pwnall marked this conversation as resolved.
{
return Err((cid, CtapHidError::MsgTimeout));
}
}
Expand Down Expand Up @@ -598,6 +600,41 @@ mod test {
);
}

#[test]
fn test_timed_out_new_init() {
let mut env = TestEnv::default();
let mut assembler = MessageAssembler::default();
assert_eq!(
assembler.parse_packet(
&mut env,
&zero_extend(&[0x12, 0x34, 0x56, 0x78, 0x81, 0x00, 0x40]),
None,
),
Ok(None)
);
env.clock().advance(TIMEOUT_DURATION_MS);
assert_eq!(
assembler.parse_packet(
&mut env,
&zero_extend(&[0x12, 0x34, 0x56, 0x78, 0x81, 0x00, 0x40]),
None
),
Ok(None)
);
assert_eq!(
assembler.parse_packet(
&mut env,
&zero_extend(&[0x12, 0x34, 0x56, 0x78, 0x00]),
None
),
Ok(Some(Message {
cid: [0x12, 0x34, 0x56, 0x78],
cmd: CtapHidCommand::Ping,
payload: vec![0x00; 0x40]
}))
);
}

#[test]
fn test_just_in_time_packets() {
let mut env = TestEnv::default();
Expand Down
9 changes: 9 additions & 0 deletions src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ impl Touch {
}
}

impl Drop for Touch {
fn drop(&mut self) {
if Arc::strong_count(&self.touched) == 2 {
// We're the last object, so we can stop listening.
*STATE.lock() = None;
}
}
}

static STATE: Mutex<Option<State>> = Mutex::new(None);

struct State {
Expand Down
Loading