Skip to content

Commit 22afd2d

Browse files
committed
Add libnfc backend to nfc transport
1 parent e1b5849 commit 22afd2d

File tree

5 files changed

+446
-0
lines changed

5 files changed

+446
-0
lines changed

Cargo.lock

Lines changed: 188 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libwebauthn/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ hid-device-tests = ["virtual-hid-device"]
1818
virtual-hid-device = ["solo"]
1919
nfc = ["apdu-core", "apdu", "thiserror"]
2020
pcsc = [ "nfc", "dep:pcsc" ]
21+
libnfc = [
22+
"nfc",
23+
"nfc1-sys",
24+
"nfc1",
25+
]
2126

2227
[dependencies]
2328
base64-url = "2.0.0"
@@ -71,6 +76,8 @@ apdu-core = { version = "0.4.0", optional = true }
7176
apdu = { version = "0.4.0", optional = true }
7277
thiserror = { version = "2.0.12", optional = true }
7378
pcsc = { version = "2.9.0", optional = true }
79+
nfc1 = { version = "0.6.0", optional = true, default-features = false }
80+
nfc1-sys = { version = "0.3.9", optional = true, default-features = false }
7481

7582

7683
[dev-dependencies]

libwebauthn/src/transport/nfc/device.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ use crate::transport::device::Device;
99
use crate::transport::error::Error;
1010

1111
use super::channel::NfcChannel;
12+
#[cfg(feature = "libnfc")]
13+
use super::libnfc;
1214
#[cfg(feature = "pcsc")]
1315
use super::pcsc;
1416
use super::{Context, Nfc};
1517

1618
#[derive(Debug)]
1719
enum DeviceInfo {
20+
#[cfg(feature = "libnfc")]
21+
LibNfc(libnfc::Info),
1822
#[cfg(feature = "pcsc")]
1923
Pcsc(pcsc::Info),
2024
}
@@ -27,6 +31,8 @@ pub struct NfcDevice {
2731
impl fmt::Display for DeviceInfo {
2832
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2933
match &self {
34+
#[cfg(feature = "libnfc")]
35+
DeviceInfo::LibNfc(info) => write!(f, "{}", info),
3036
#[cfg(feature = "pcsc")]
3137
DeviceInfo::Pcsc(info) => write!(f, "{}", info),
3238
}
@@ -40,6 +46,13 @@ impl fmt::Display for NfcDevice {
4046
}
4147

4248
impl NfcDevice {
49+
#[cfg(feature = "libnfc")]
50+
pub fn new_libnfc(info: libnfc::Info) -> Self {
51+
NfcDevice {
52+
info: DeviceInfo::LibNfc(info),
53+
}
54+
}
55+
4356
#[cfg(feature = "pcsc")]
4457
pub fn new_pcsc(info: pcsc::Info) -> Self {
4558
NfcDevice {
@@ -53,6 +66,8 @@ impl NfcDevice {
5366
trace!("nfc channel {:?}", self);
5467
let (mut channel, recv): (NfcChannel<Context>, mpsc::Receiver<UxUpdate>) = match &self.info
5568
{
69+
#[cfg(feature = "libnfc")]
70+
DeviceInfo::LibNfc(info) => info.channel(),
5671
#[cfg(feature = "pcsc")]
5772
DeviceInfo::Pcsc(info) => info.channel(),
5873
}?;
@@ -92,6 +107,8 @@ where
92107
pub async fn list_devices() -> Result<Vec<NfcDevice>, Error> {
93108
let mut all_devices = Vec::new();
94109
let list_devices_fns = [
110+
#[cfg(feature = "libnfc")]
111+
libnfc::list_devices,
95112
#[cfg(feature = "pcsc")]
96113
pcsc::list_devices,
97114
];

0 commit comments

Comments
 (0)