Skip to content

Commit

Permalink
Rename "virtual" to "vpicc"
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Apr 5, 2023
1 parent 69dc03a commit 7e172d0
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ members = [
]

[[example]]
name = "virtual"
required-features = ["virtual"]
name = "vpicc"
required-features = ["vpicc"]

[dependencies]
heapless = "0.7"
Expand Down Expand Up @@ -56,7 +56,7 @@ hex = { version = "0.4", features = ["serde"] }
[features]
default = []
std = []
virtual = ["std", "vpicc", "virt"]
vpicc = ["std", "dep:vpicc", "virt"]
virt = ["std", "trussed/virt"]

rsa = ["trussed-rsa-alloc"]
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ fix:

.PHONY: test
test:
cargo test --features virtual,rsa2048,rsa4096-gen gpg_crypto,sequoia_gen_key
cargo test --features virtual,rsa2048,rsa4096
cargo test --features vpicc,rsa2048,rsa4096-gen gpg_crypto,sequoia_gen_key
cargo test --features vpicc,rsa2048,rsa4096


.PHONY: test
Expand Down Expand Up @@ -63,7 +63,7 @@ fuzz-cov:

.PHONY: tarpaulin
tarpaulin:
cargo tarpaulin --features virtual,rsa4096-gen -o Html -o Xml
cargo tarpaulin --features vpicc,rsa4096-gen -o Html -o Xml

.PHONY: ci
ci: lint tarpaulin
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Check out the [user guide](USAGE.md) for more information on what can be done.

## Development

Opcard uses [virtualsmartcard](https://frankmorgner.github.io/vsmartcard/) for testing.
`make test` will run `opcard` on the host through virtualsmartcard and test it.
Opcard uses [vpiccsmartcard](https://frankmorgner.github.io/vsmartcard/) for testing.
`make test` will run `opcard` on the host through vpiccsmartcard and test it.

`make dangerous-real-card-test` will instead run the tests against a real card.
The vendor id and serial numbers can be configured with variables:
Expand Down
6 changes: 3 additions & 3 deletions examples/virtual.rs → examples/vpicc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ fn main() {

opcard::virt::with_ram_client("opcard", |client| {
let card = opcard::Card::new(client, opcard::Options::default());
let mut virtual_card = opcard::VirtualCard::new(card);
let mut vpicc_card = opcard::VpiccCard::new(card);
let vpicc = vpicc::connect().expect("failed to connect to vpicc");
vpicc
.run(&mut virtual_card)
.expect("failed to run virtual smartcard");
.run(&mut vpicc_card)
.expect("failed to run vpicc smartcard");
});
}
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//!
//! - If the `apdu-dispatch` feature is enabled, [`Card`] implements the `apdu_dispatch::App`
//! trait and can be used with `apdu_dispatch`.
//! - If the `virtual` feature is enabled, [`VirtualCard`] can be used to emulate a smart card
//! - If the `vpicc` feature is enabled, [`VpiccCard`] can be used to emulate a smart card
//! using [`vsmartcard`](https://frankmorgner.github.io/vsmartcard/) and `vpicc-rs`.

#![cfg_attr(not(any(feature = "std", test)), no_std)]
Expand Down Expand Up @@ -56,13 +56,13 @@ mod state;
mod tlv;
mod types;
mod utils;
#[cfg(feature = "virtual")]
#[cfg(feature = "vpicc")]
mod vpicc;

#[cfg(feature = "virt")]
pub mod virt;

#[cfg(feature = "virtual")]
pub use self::vpicc::VirtualCard;
#[cfg(feature = "vpicc")]
pub use self::vpicc::VpiccCard;
pub use card::{Card, Options};
pub use state::{DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN};
10 changes: 5 additions & 5 deletions src/vpicc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ use crate::card::Card;
const REQUEST_LEN: usize = 7609;
const RESPONSE_LEN: usize = 7609;

/// Virtual OpenPGP smart card implementation.
/// Vpicc OpenPGP smart card implementation.
///
/// This struct provides a virtual OpenPGP smart card implementation that can be used with
/// This struct provides a vpicc OpenPGP smart card implementation that can be used with
/// `vpicc-rs` and [`vsmartcard`](https://frankmorgner.github.io/vsmartcard/) to emulate the card.
#[derive(Clone, Debug)]
pub struct VirtualCard<T: trussed::Client + AuthClient> {
pub struct VpiccCard<T: trussed::Client + AuthClient> {
request_buffer: RequestBuffer<REQUEST_LEN>,
response_buffer: ResponseBuffer<RESPONSE_LEN>,
card: Card<T>,
}

impl<T: trussed::Client + AuthClient> VirtualCard<T> {
impl<T: trussed::Client + AuthClient> VpiccCard<T> {
/// Creates a new virtual smart card from the given card.
pub fn new(card: Card<T>) -> Self {
Self {
Expand All @@ -45,7 +45,7 @@ impl<T: trussed::Client + AuthClient> VirtualCard<T> {
}
}

impl<T: trussed::Client + AuthClient> vpicc::VSmartCard for VirtualCard<T> {
impl<T: trussed::Client + AuthClient> vpicc::VSmartCard for VpiccCard<T> {
fn power_on(&mut self) {}

fn power_off(&mut self) {
Expand Down
6 changes: 3 additions & 3 deletions tests/crypto-gpg-import.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2022 Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
#![cfg(any(feature = "virtual", feature = "dangerous-test-real-card"))]
#![cfg(any(feature = "vpicc", feature = "dangerous-test-real-card"))]

mod virt;

Expand All @@ -10,7 +10,7 @@ use test_log::test;
use virt::gnupg_test;
use virt::GpgCommand::*;

#[cfg(feature = "virtual")]
#[cfg(feature = "vpicc")]
#[allow(unused)]
use virt::with_vsc;

Expand Down Expand Up @@ -1205,7 +1205,7 @@ fn gpg_rsa_4096() {
);
}

#[cfg(all(feature = "virtual", not(feature = "dangerous-test-real-card")))]
#[cfg(all(feature = "vpicc", not(feature = "dangerous-test-real-card")))]
#[test]
fn gpg_crypto() {
#[cfg(feature = "rsa2048")]
Expand Down
6 changes: 3 additions & 3 deletions tests/crypto-gpg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2022 Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
#![cfg(any(feature = "virtual", feature = "dangerous-test-real-card"))]
#![cfg(any(feature = "vpicc", feature = "dangerous-test-real-card"))]

mod virt;

Expand All @@ -12,7 +12,7 @@ use test_log::test;
use virt::gnupg_test;
use virt::GpgCommand::*;

#[cfg(feature = "virtual")]
#[cfg(feature = "vpicc")]
#[allow(unused)]
use virt::with_vsc;

Expand Down Expand Up @@ -1031,7 +1031,7 @@ fn gpg_rsa_4096() {
);
}

#[cfg(all(feature = "virtual", not(feature = "dangerous-test-real-card")))]
#[cfg(all(feature = "vpicc", not(feature = "dangerous-test-real-card")))]
#[test]
fn gpg_crypto() {
with_vsc(gpg_255);
Expand Down
6 changes: 3 additions & 3 deletions tests/crypto-sequoia.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2022 Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
#![cfg(any(feature = "virtual", feature = "dangerous-test-real-card"))]
#![cfg(any(feature = "vpicc", feature = "dangerous-test-real-card"))]

mod card;
mod virt;
Expand All @@ -16,7 +16,7 @@ use sequoia_openpgp::types::HashAlgorithm;

use test_log::test;

#[cfg(all(feature = "virtual", not(feature = "dangerous-test-real-card")))]
#[cfg(all(feature = "vpicc", not(feature = "dangerous-test-real-card")))]
const IDENT: &str = "0000:00000000";
#[cfg(feature = "dangerous-test-real-card")]
const IDENT: &str = concat!(
Expand Down Expand Up @@ -284,7 +284,7 @@ fn curve25519() {
open.factory_reset().unwrap();
}

#[cfg(all(feature = "virtual", not(feature = "dangerous-test-real-card")))]
#[cfg(all(feature = "vpicc", not(feature = "dangerous-test-real-card")))]
#[test]
fn sequoia_gen_key() {
#[cfg(feature = "rsa2048")]
Expand Down
2 changes: 1 addition & 1 deletion tests/gpg-status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2022 Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only

#![cfg(feature = "virtual")]
#![cfg(feature = "vpicc")]

mod virt;

Expand Down
14 changes: 7 additions & 7 deletions tests/virt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2022 Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
#![cfg(any(feature = "virtual", feature = "dangerous-test-real-card"))]
#![cfg(any(feature = "vpicc", feature = "dangerous-test-real-card"))]

use std::{
io::{BufRead, BufReader, Write},
Expand All @@ -9,12 +9,12 @@ use std::{
thread,
};

#[cfg(feature = "virtual")]
#[cfg(feature = "vpicc")]
use std::{sync::mpsc, thread::sleep, time::Duration};

use regex::{Regex, RegexSet};

#[cfg(feature = "virtual")]
#[cfg(feature = "vpicc")]
use stoppable_thread::spawn;

const STDOUT_FILTER: &[&str] = &[
Expand All @@ -36,7 +36,7 @@ const STDERR_FILTER: &[&str] = &[
r"There is NO WARRANTY, to the extent permitted by law.",
];

#[cfg(feature = "virtual")]
#[cfg(feature = "vpicc")]
#[allow(unused)]
pub fn with_vsc<F: FnOnce() -> R, R>(f: F) -> R {
let mut vpicc = vpicc::connect().expect("failed to connect to vpcd");
Expand All @@ -45,10 +45,10 @@ pub fn with_vsc<F: FnOnce() -> R, R>(f: F) -> R {
let handle = spawn(move |stopped| {
opcard::virt::with_ram_client("opcard", |client| {
let card = opcard::Card::new(client, opcard::Options::default());
let mut virtual_card = opcard::VirtualCard::new(card);
let mut vpicc_card = opcard::VpiccCard::new(card);
let mut result = Ok(());
while !stopped.get() && result.is_ok() {
result = vpicc.poll(&mut virtual_card);
result = vpicc.poll(&mut vpicc_card);
if result.is_ok() {
tx.send(()).expect("failed to send message");
}
Expand Down Expand Up @@ -167,7 +167,7 @@ pub fn gpg_status(key: KeyType, sign_count: usize) -> Vec<&'static str> {
};

let fprtimes = r"fprtime:\d*:\d*:\d*:";
#[cfg(feature = "virtual")]
#[cfg(feature = "vpicc")]
let (reader, serial, vendor) = (
r"Reader:Virtual PCD \d\d \d\d:AID:D276000124010304[A-Z0-9]*:openpgp-card",
r"vendor:0000:test card:",
Expand Down

0 comments on commit 7e172d0

Please sign in to comment.