Add key generation test

This commit is contained in:
Sosthène Guédon
2022-12-16 11:34:09 +01:00
parent ddb3132f6a
commit a7d9b21ad1
2 changed files with 21 additions and 0 deletions
+6
View File
@@ -6,7 +6,13 @@ use piv_authenticator::{vpicc::VirtualCard, Authenticator};
use std::{sync::mpsc, thread::sleep, time::Duration};
use stoppable_thread::spawn;
use std::sync::Mutex;
static VSC_MUTEX: Mutex<()> = Mutex::new(());
pub fn with_vsc<F: FnOnce() -> R, R>(f: F) -> R {
let _lock = VSC_MUTEX.lock().unwrap();
let mut vpicc = vpicc::connect().expect("failed to connect to vpcd");
let (tx, rx) = mpsc::channel();
+15
View File
@@ -22,3 +22,18 @@ fn list() {
assert_eq!(p.wait().unwrap(), WaitStatus::Exited(p.pid(), 0));
});
}
#[test]
fn generate() {
with_vsc(|| {
let mut p = spawn("pivy-tool -A 3des -K 010203040506070801020304050607080102030405060708 generate 9A -a eccp256 -P 123456").unwrap();
p.check("Touch button confirmation may be required.")
.unwrap();
p.check(Regex(
"^ecdsa-sha2-nistp256 (?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)? PIV_slot_9A@[A-F0-9]{20}$",
))
.unwrap();
p.check(Eof).unwrap();
assert_eq!(p.wait().unwrap(), WaitStatus::Exited(p.pid(), 0));
});
}