openpgp-card-sequoia: adjust example
This commit is contained in:
parent
15646bc50b
commit
7de74d702e
2 changed files with 123 additions and 120 deletions
|
@ -4,7 +4,7 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"openpgp-card",
|
"openpgp-card",
|
||||||
# "openpgp-card-sequoia",
|
"openpgp-card-sequoia",
|
||||||
"card-backend",
|
"card-backend",
|
||||||
"pcsc",
|
"pcsc",
|
||||||
"scdc",
|
"scdc",
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Heiko Schaefer <heiko@schaefer.name>
|
// SPDX-FileCopyrightText: 2021-2023 Heiko Schaefer <heiko@schaefer.name>
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use card_backend_pcsc::PcscBackend;
|
||||||
use openpgp_card::card_do::Sex;
|
use openpgp_card::card_do::Sex;
|
||||||
use openpgp_card::KeyType;
|
use openpgp_card::KeyType;
|
||||||
use openpgp_card_pcsc::PcscBackend;
|
|
||||||
use openpgp_card_sequoia::sq_util;
|
use openpgp_card_sequoia::sq_util;
|
||||||
use openpgp_card_sequoia::{state::Open, Card};
|
use openpgp_card_sequoia::{state::Open, Card};
|
||||||
use sequoia_openpgp::parse::Parse;
|
use sequoia_openpgp::parse::Parse;
|
||||||
|
@ -33,9 +33,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let test_card_ident = env::var("TEST_CARD_IDENT");
|
let test_card_ident = env::var("TEST_CARD_IDENT");
|
||||||
|
|
||||||
if let Ok(test_card_ident) = test_card_ident {
|
if let Ok(test_card_ident) = test_card_ident {
|
||||||
let backend = PcscBackend::open_by_ident(&test_card_ident, None)?;
|
let cards = PcscBackend::card_backends(None)?;
|
||||||
|
let mut card = Card::<Open>::open_by_ident(cards, &test_card_ident)?;
|
||||||
|
|
||||||
let mut card: Card<Open> = backend.into();
|
{
|
||||||
let mut transaction = card.transaction()?;
|
let mut transaction = card.transaction()?;
|
||||||
|
|
||||||
// card metadata
|
// card metadata
|
||||||
|
@ -132,15 +133,16 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
println!("Upload auth key");
|
println!("Upload auth key");
|
||||||
admin.upload_key(vka, KeyType::Authentication, None)?;
|
admin.upload_key(vka, KeyType::Authentication, None)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
println!();
|
println!();
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// Open fresh Card for decrypt
|
// Open fresh Card for decrypt
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
let backend = PcscBackend::open_by_ident(&test_card_ident, None)?;
|
let cards = PcscBackend::card_backends(None)?;
|
||||||
|
let mut card = Card::<Open>::open_by_ident(cards, &test_card_ident)?;
|
||||||
|
|
||||||
let mut card: Card<Open> = backend.into();
|
{
|
||||||
let mut transaction = card.transaction()?;
|
let mut transaction = card.transaction()?;
|
||||||
|
|
||||||
// Check that we're still using the expected card
|
// Check that we're still using the expected card
|
||||||
|
@ -174,13 +176,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
println!("Decrypted plaintext: {plain}");
|
println!("Decrypted plaintext: {plain}");
|
||||||
|
|
||||||
assert_eq!(plain, "Hello world!\n");
|
assert_eq!(plain, "Hello world!\n");
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// Open fresh Card for signing
|
// Open fresh Card for signing
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
let backend = PcscBackend::open_by_ident(&test_card_ident, None)?;
|
let cards = PcscBackend::card_backends(None)?;
|
||||||
|
let mut card = Card::<Open>::open_by_ident(cards, &test_card_ident)?;
|
||||||
|
|
||||||
let mut card: Card<Open> = backend.into();
|
|
||||||
let mut transaction = card.transaction()?;
|
let mut transaction = card.transaction()?;
|
||||||
|
|
||||||
// Sign
|
// Sign
|
||||||
|
@ -211,7 +214,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
println!("The following OpenPGP cards are connected to your system:");
|
println!("The following OpenPGP cards are connected to your system:");
|
||||||
|
|
||||||
for backend in PcscBackend::cards(None)? {
|
for backend in PcscBackend::cards(None)? {
|
||||||
let mut card: Card<Open> = backend.into();
|
let mut card: Card<Open> = Card::<Open>::new(backend?)?;
|
||||||
let open = card.transaction()?;
|
let open = card.transaction()?;
|
||||||
|
|
||||||
println!(" {}", open.application_identifier()?.ident());
|
println!(" {}", open.application_identifier()?.ident());
|
||||||
|
|
Loading…
Reference in a new issue