public void Close() { if (yk != IntPtr.Zero) { bool ret = YubiWrapper.yk_close_key(yk) == 1; if (!ret || YubiWrapper.yk_release() != 1) { throw new Exception("Error closing Yubikey"); } } }
private void OnFormLoad(object sender, EventArgs e) { ControlBox = false; progressBar.Maximum = 15; progressBar.Minimum = 0; progressBar.Value = 15; yubi = new YubiWrapper(); try { while (!yubi.Init()) { YubiPrompt prompt = new YubiPrompt(RecoveryButton); DialogResult res = prompt.ShowDialog(); if (res != DialogResult.Retry) { RecoveryMode = prompt.RecoveryMode; DialogResult = DialogResult.Abort; return; } } } catch (PlatformNotSupportedException err) { Debug.Assert(false); MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK); return; } //spawn background countdown timer countdown = new Timer(); countdown.Tick += Countdown; countdown.Interval = 1000; countdown.Enabled = true; keyWorker = new BackgroundWorker(); keyWorker.DoWork += YubiChallengeResponse; keyWorker.RunWorkerCompleted += KeyWorkerDone; keyWorker.RunWorkerAsync(); }