run cargo fmt
This commit is contained in:
parent
20fc4719f3
commit
759b9ac93d
2 changed files with 55 additions and 15 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -107,7 +107,11 @@ async fn run_auth(
|
|||
}
|
||||
} else {
|
||||
let Some(ctx) = digid_api::wid_init(&host, &session_id).await else {
|
||||
ctg_pipe.send(pipe::CardToGUI::ProcessingMessage { message: "Failed to initialize DigiD session.".to_owned() }).await;
|
||||
ctg_pipe
|
||||
.send(pipe::CardToGUI::ProcessingMessage {
|
||||
message: "Failed to initialize DigiD session.".to_owned(),
|
||||
})
|
||||
.await;
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
|
|
@ -514,10 +518,25 @@ fn main() {
|
|||
let (gtc_pipe_s, gtc_pipe_r) = async_channel::unbounded();
|
||||
|
||||
let s = args().nth(1).unwrap();
|
||||
let mut parsed_url = url::form_urlencoded::parse(s.split(':').last().unwrap().as_bytes()).into_owned().collect::<HashMap<String, String>>();
|
||||
let mut parsed_url = url::form_urlencoded::parse(s.split(':').last().unwrap().as_bytes())
|
||||
.into_owned()
|
||||
.collect::<HashMap<String, String>>();
|
||||
|
||||
let rt = Runtime::new().unwrap();
|
||||
rt.spawn(async move { run_auth(parsed_url.remove("host").unwrap_or_else(|| String::from("test")), parsed_url.remove("app_session_id").unwrap_or_else(|| String::from("test")), ctg_pipe_s, gtc_pipe_r).await.unwrap() });
|
||||
rt.spawn(async move {
|
||||
run_auth(
|
||||
parsed_url
|
||||
.remove("host")
|
||||
.unwrap_or_else(|| String::from("test")),
|
||||
parsed_url
|
||||
.remove("app_session_id")
|
||||
.unwrap_or_else(|| String::from("test")),
|
||||
ctg_pipe_s,
|
||||
gtc_pipe_r,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
gui::run_gui(ctg_pipe_r, gtc_pipe_s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,9 +109,7 @@ impl PCSCCardFinder {
|
|||
pub fn new() -> Self {
|
||||
Self(Arc::new(Mutex::new(PCSCCardFinderInner {
|
||||
ctx: pcsc::Context::establish(pcsc::Scope::User).unwrap(),
|
||||
reader_states: vec![
|
||||
ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE),
|
||||
],
|
||||
reader_states: vec![ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE)],
|
||||
event_count: HashMap::new(),
|
||||
})))
|
||||
}
|
||||
|
|
@ -122,11 +120,16 @@ impl PCSCCardFinder {
|
|||
loop {
|
||||
{
|
||||
let mut m = self.0.lock().unwrap();
|
||||
m.reader_states.retain(|reader| !reader.event_state().intersects(State::IGNORE | State::UNKNOWN));
|
||||
m.reader_states.retain(|reader| {
|
||||
!reader
|
||||
.event_state()
|
||||
.intersects(State::IGNORE | State::UNKNOWN)
|
||||
});
|
||||
|
||||
for reader in m.ctx.list_readers(&mut readers_buf).unwrap() {
|
||||
if !m.reader_states.iter().any(|f| f.name() == reader) {
|
||||
m.reader_states.push(ReaderState::new(reader, State::UNAWARE));
|
||||
m.reader_states
|
||||
.push(ReaderState::new(reader, State::UNAWARE));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,26 +139,44 @@ impl PCSCCardFinder {
|
|||
}
|
||||
|
||||
let c = self.0.clone();
|
||||
spawn_blocking(move || { let mut c = c.lock().unwrap(); let c = &mut *c; c.ctx.get_status_change(None, &mut c.reader_states) }).await.unwrap().unwrap();
|
||||
spawn_blocking(move || {
|
||||
let mut c = c.lock().unwrap();
|
||||
let c = &mut *c;
|
||||
c.ctx.get_status_change(None, &mut c.reader_states)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
let mut m = self.0.lock().unwrap();
|
||||
let m = &mut *m;
|
||||
|
||||
for reader in &mut m.reader_states {
|
||||
if reader.name() == PNP_NOTIFICATION() {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
|
||||
// Anything with "Yubico" in it will never be valid.
|
||||
if reader.name().to_bytes().starts_with(b"Yubico") {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
|
||||
let last_event_count = m.event_count.insert(reader.name().to_owned(), reader.event_count());
|
||||
if reader.event_state().contains(State::PRESENT) && !reader.event_state().contains(State::INUSE) && Some(reader.event_count()) != last_event_count {
|
||||
let last_event_count = m
|
||||
.event_count
|
||||
.insert(reader.name().to_owned(), reader.event_count());
|
||||
if reader.event_state().contains(State::PRESENT)
|
||||
&& !reader.event_state().contains(State::INUSE)
|
||||
&& Some(reader.event_count()) != last_event_count
|
||||
{
|
||||
// Newly present card, let's give it a try.
|
||||
if let Ok(card) = m.ctx.connect(reader.name(), pcsc::ShareMode::Shared, Protocols::ANY) {
|
||||
return PCSCCard { card, buf: [0; 0x10002] }
|
||||
if let Ok(card) =
|
||||
m.ctx
|
||||
.connect(reader.name(), pcsc::ShareMode::Shared, Protocols::ANY)
|
||||
{
|
||||
return PCSCCard {
|
||||
card,
|
||||
buf: [0; 0x10002],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue