From 73593e66e738cfb6dbf620ce73642add38697aed Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Fri, 8 Oct 2021 00:51:01 +0200 Subject: [PATCH] Add "list-cards" tool. --- card-functionality/Cargo.toml | 4 ++++ card-functionality/src/list-cards.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 card-functionality/src/list-cards.rs diff --git a/card-functionality/Cargo.toml b/card-functionality/Cargo.toml index a0530ae..2c7f016 100644 --- a/card-functionality/Cargo.toml +++ b/card-functionality/Cargo.toml @@ -23,6 +23,10 @@ path = "src/keygen.rs" name = "other" path = "src/other.rs" +[[bin]] +name = "list-cards" +path = "src/list-cards.rs" + [dependencies] openpgp-card = { path = "../openpgp-card" } openpgp-card-sequoia = { path = "../openpgp-card-sequoia" } diff --git a/card-functionality/src/list-cards.rs b/card-functionality/src/list-cards.rs new file mode 100644 index 0000000..3767b9e --- /dev/null +++ b/card-functionality/src/list-cards.rs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2021 Heiko Schaefer +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use anyhow::Result; + +use openpgp_card_pcsc::PcscClient; +use openpgp_card_sequoia::card::Open; + +fn main() -> Result<()> { + println!("The following OpenPGP cards are connected to your system:"); + + for card in PcscClient::cards()? { + let open = Open::open_card(card)?; + println!(" {}", open.application_identifier()?.ident()); + } + + Ok(()) +}