Skip to content
Merged
Changes from 1 commit
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
49 changes: 31 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,45 @@ fn main() -> ! {
let mut u2f: Option<touch::Touch> = None;
debug!("OpenSK initialized");
loop {
match (wink.is_some(), opensk_ctap.should_wink()) {
(true, true) | (false, false) => (),
(false, true) => wink = Some(blink::Blink::new_ms(100)),
(true, false) => wink = None,
}
let mut packet = [0; 64];
let timeout = wink.is_some().then_some(500);
match env::hid_connection::recv(&mut packet, timeout).unwrap() {
RecvStatus::Timeout => continue,
update_state(&mut wink, opensk_ctap.should_wink(), || {
blink::Blink::new_ms(100)
});
let mut packet = Some([0; 64]);
let mut timeout = None;
timeout = timeout.or(wink.is_some().then_some(500));
#[cfg(feature = "ctap1")]
(timeout = timeout.or(u2f.is_some().then_some(1000)));
Comment thread
ia0 marked this conversation as resolved.
Outdated
match env::hid_connection::recv(packet.as_mut().unwrap(), timeout).unwrap() {
RecvStatus::Timeout => packet = None,
RecvStatus::Received(endpoint) => assert_eq!(endpoint, UsbEndpoint::MainHid),
}
#[cfg(feature = "ctap1")]
if u2f.as_ref().is_some_and(|x| x.is_present()) {
u2f = None;
opensk_ctap.u2f_grant_user_presence();
}
for packet in opensk_ctap.process_hid_packet(&packet, Transport::MainHid) {
opensk_ctap
.env()
.hid_connection()
.send(&packet, UsbEndpoint::MainHid)
.unwrap();
if let Some(packet) = packet {
for packet in opensk_ctap.process_hid_packet(&packet, Transport::MainHid) {
Comment thread
ia0 marked this conversation as resolved.
Outdated
opensk_ctap
.env()
.hid_connection()
.send(&packet, UsbEndpoint::MainHid)
.unwrap();
}
}
#[cfg(feature = "ctap1")]
if opensk_ctap.u2f_needs_user_presence() && u2f.is_none() {
u2f = Some(touch::Touch::new());
}
update_state(
&mut u2f,
opensk_ctap.u2f_needs_user_presence(),
touch::Touch::new,
);
}
}

fn update_state<T>(state: &mut Option<T>, target: bool, build: impl FnOnce() -> T) {
*state = match (state.is_some(), target) {
(true, true) | (false, false) => return,
(true, false) => None,
(false, true) => Some(build()),
}
}
Loading