soft_fido2/
lib.rs

1#![warn(unused_extern_crates)]
2#![cfg_attr(not(feature = "std"), no_std)]
3
4//! # soft-fido2
5//!
6//! A pure Rust FIDO2/WebAuthn CTAP2 implementation providing virtual authenticator
7//! capabilities for testing and development.
8//!
9//! ## no_std Support
10//!
11//! This crate supports `no_std` environments. To use without the standard library:
12//!
13//! ```toml
14//! [dependencies]
15//! soft-fido2 = { version = "0.4", default-features = false }
16//! ```
17//!
18//! **Note**: Transport layers (USB HID, UHID) require `std` and are not available in `no_std`.
19//! The core CTAP protocol and authenticator logic work in `no_std` with `alloc`.
20//!
21//! ## Architecture
22//!
23//! - **Authenticator**: Virtual FIDO2 authenticator with callback-based user interaction
24//! - **Client**: High-level API for communicating with authenticators (requires `std`)
25//! - **Transport**: USB HID and Linux UHID transport layers (requires `std`)
26//! - **PIN Protocol**: CTAP2 PIN/UV authentication
27//!
28//! ## Example (with std)
29//!
30//! ```no_run
31//! # #[cfg(feature = "std")]
32//! # fn main() -> Result<(), soft_fido2::Error> {
33//! use soft_fido2::{TransportList, Client};
34//!
35//! let mut list = TransportList::enumerate()?;
36//! let mut transport = list.get(0).unwrap();
37//! transport.open()?;
38//!
39//! let info = Client::authenticator_get_info(&mut transport)?;
40//! # Ok(())
41//! # }
42//! # #[cfg(not(feature = "std"))]
43//! # fn main() {}
44//! ```
45
46extern crate alloc;
47
48// Core modules (no_std compatible)
49pub mod authenticator;
50pub mod ctap;
51pub mod error;
52pub mod options;
53pub mod request;
54pub mod response;
55pub mod types;
56
57// Modules that require std
58#[cfg(feature = "std")]
59pub mod client;
60#[cfg(feature = "std")]
61pub mod pin;
62#[cfg(feature = "std")]
63pub mod transport;
64
65#[cfg(all(target_os = "linux", feature = "std"))]
66pub mod uhid;
67
68// Re-export main types at root level for convenience
69pub use authenticator::{
70    Authenticator, AuthenticatorCallbacks, AuthenticatorConfig, AuthenticatorConfigBuilder,
71    UpResult, UvResult,
72};
73pub use ctap::CtapCommand;
74pub use error::{Error, Result};
75pub use options::AuthenticatorOptions;
76pub use request::{
77    ClientDataHash, CredentialDescriptor, CredentialManagementRequest, CredentialType,
78    DeleteCredentialRequest, EnumerateCredentialsRequest, GetAssertionRequest,
79    MakeCredentialRequest, PinUvAuth, PinUvAuthProtocol, UpdateUserRequest,
80};
81pub use soft_fido2_ctap::StatusCode;
82
83// Re-export PIN storage types for persistent PIN state support
84pub use soft_fido2_ctap::callbacks::PinStorageCallbacks;
85pub use soft_fido2_ctap::types::PinState;
86
87pub use types::{Credential, CredentialRef, Extensions, RelyingParty, User};
88
89// Re-export response types
90pub use response::{
91    CredentialEnumerationBeginResponse, CredentialEnumerationNextResponse, CredentialInfo,
92    CredentialsMetadata, RpEnumerationBeginResponse, RpEnumerationNextResponse, RpInfo,
93};
94
95// std-only re-exports
96#[cfg(feature = "std")]
97pub use client::{Client, compute_rp_id_hash};
98#[cfg(feature = "std")]
99pub use pin::{PinProtocol, PinUvAuthEncapsulation};
100#[cfg(feature = "std")]
101pub use transport::{Transport, TransportList};
102
103#[cfg(all(target_os = "linux", feature = "std"))]
104pub use uhid::Uhid;