diff --git a/Cargo.toml b/Cargo.toml index e48f5a5..205f074 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ members = [ "openpgp-card", "openpgp-card-sequoia", "scdc", + "card-functionality", ] diff --git a/card-functionality/Cargo.toml b/card-functionality/Cargo.toml new file mode 100644 index 0000000..2430f20 --- /dev/null +++ b/card-functionality/Cargo.toml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Heiko Schaefer +# SPDX-License-Identifier: MIT OR Apache-2.0 + +[package] +name = "card-functionality" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +openpgp-card = { path = "../openpgp-card" } +anyhow = "1" \ No newline at end of file diff --git a/card-functionality/src/main.rs b/card-functionality/src/main.rs new file mode 100644 index 0000000..e059f3c --- /dev/null +++ b/card-functionality/src/main.rs @@ -0,0 +1,67 @@ +// SPDX-FileCopyrightText: 2021 Heiko Schaefer +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use anyhow::Result; +use std::env; + +use openpgp_card::apdu::PcscClient; +use openpgp_card::card_app::CardApp; +use openpgp_card::CardClientBox; + +fn test(mut ca: CardApp) -> Result<()> { + let res = ca.verify_pw3("12345678"); + println!("res verify pw3 {:x?}", res); + + let check = ca.check_pw3(); + println!("has pw3 been verified yet? {:x?}", check); + + let res = ca.set_name("Admin< Result<()> { + let cards = PcscClient::list_cards()?; + + // Ident of the OpenPGP Card that will be used for tests. + let test_card_ident = + env::var("TEST_CARD_IDENT").expect("TEST_CARD_IDENT is not set"); + + for card in cards { + let card_client = Box::new(card) as CardClientBox; + + let mut ca = CardApp::new(card_client); + + let res = ca.select()?; + res.check_ok()?; + + let ard = ca.get_app_data()?; + let app_id = CardApp::get_aid(&ard)?; + + println!("Opened Card: ident {}", app_id.ident()); + if app_id.ident() == test_card_ident { + println!("Running Test on {}", app_id.ident()); + + test(ca)?; + } + } + + Ok(()) +}