1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Bindings to Yubico libfido2
//!
//! This crate provides a safe interface to the Yubico libfido2 library.
//!
//! # Building
//!
//! There are multiple options available to locate libfido2.
//!
//! ## Pre-build MSVC binary.
//!
//! If the rust toolchain is msvc, the `libfido2-sys` crate will download a pre-build binary dll from
//! Yubico release.
//!
//! ## Build from source.
//!
//! If the target is not msvc(mingw on windows or linux), this crate will build a static library from source.
//!
//! The build process requires a C compiler, cmake, libcbor, zlib, libcrypto.
//!
//! ## Automatic
//!
//! The `libfido2-sys` crate can automatically detect libfido2 installations via vcpkg on Windows and `pkg-config` on Linux.
//!
//! This method can be enabled by set environment variable `FIDO2_USE_PKG_CONFIG` to any non empty value.
//!
//! ## Manual
//!
//! A `FIDO2_LIB_DIR` environment variable can be used to help `libfido2-sys` to find a libfido2 installation.
//!
//! The directory should contains the libfido2 libraries.
//!
//! The other dependency like libcbor, libcrypto, zlib will use system version. Currently there is no way to
//! set these library directory, but you can put them together in `FIDO2_LIB_DIR`.
//!
//! # Example
//!
//! ## Enumerate fido devices on system
//! ```rust,no_run
//! use fido2_rs::device::DeviceList;
//!
//! let list = DeviceList::list_devices(4);
//! for dev in list {
//! println!("{:?}", dev.path);
//! }
//!
//! ```
//!
//! ## Make a credential
//! ```rust,no_run
//! use fido2_rs::device::Device;
//! use fido2_rs::credentials::Credential;
//! use fido2_rs::credentials::CoseType;
//! use anyhow::Result;
//! fn main() -> Result<()> {
//! let dev = Device::open("windows://hello").expect("unable open windows hello");
//!
//! let mut cred = Credential::new();
//! cred.set_client_data(&[1, 2, 3, 4, 5, 6])?;
//! cred.set_rp("fido_rs", "fido example")?;
//! cred.set_user(&[1, 2, 3, 4, 5, 6], "alice", Some("alice"), None)?;
//! cred.set_cose_type(CoseType::RS256)?;
//!
//! let _ = dev.make_credential(&mut cred, None)?;
//! dbg!(cred.id());
//!
//! Ok(())
//! }
//! ```
extern crate libfido2_sys as ffi;