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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2026 Yubico AB
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Rust SDK for interacting with YubiKey devices.
//!
//! **yubikit** provides a complete API for communicating with YubiKeys over
//! USB (CCID/SmartCard, FIDO HID, OTP HID) and NFC. It covers the full
//! range of YubiKey applications: OATH, PIV, OpenPGP, FIDO2/CTAP2, WebAuthn,
//! YubiOTP, HSM Auth, and device management.
//!
//! # Getting started
//!
//! Most workflows follow the same pattern: discover devices, open a connection
//! over the desired transport, then create a session for the application you
//! want to use.
//!
//! ```no_run
//! use yubikit::platform::device::list_devices;
//! use yubikit::management::UsbInterface;
//! use yubikit::oath::OathSession;
//!
//! // 1. Discover connected YubiKeys
//! let all = UsbInterface::CCID | UsbInterface::OTP | UsbInterface::FIDO;
//! let devices = list_devices(all).expect("enumeration failed");
//! let dev = devices.first().expect("no YubiKey found");
//!
//! // 2. Open a SmartCard (CCID) connection
//! let conn = dev.open_smartcard().expect("connection failed");
//!
//! // 3. Create an OATH session and list accounts
//! let mut session = OathSession::new(conn).expect("OATH init failed");
//! let creds = session.list_credentials().expect("list failed");
//! for cred in &creds {
//! println!("{cred:?}");
//! }
//! ```
//!
//! # Transports and connections
//!
//! YubiKeys expose different USB interfaces, each requiring its own
//! connection type:
//!
//! | Interface | Connection | Used by |
//! |-----------|-----------|---------|
//! | CCID (SmartCard) | [`smartcard::SmartCardConnection`] | OATH, PIV, OpenPGP, Management, FIDO2, HSM Auth, Security Domain |
//! | FIDO HID | [`fido::FidoConnection`] | FIDO2/CTAP2, WebAuthn, Management |
//! | OTP HID | [`otp::OtpConnection`] | YubiOTP, Management |
//!
//! All connection types implement [`core::Connection`]. Session types are
//! generic over their connection type, so the same [`ctap2::Ctap2Session`]
//! works over both SmartCard and FIDO HID.
//!
//! # Module overview
//!
//! ## Device discovery and management
//! - [`device`] — Enumerate connected YubiKeys, open connections
//! - [`management`] — Read/write device configuration, capabilities, and mode
//!
//! ## YubiKey applications
//! - [`oath`] — OATH TOTP/HOTP credential management and code calculation
//! - [`piv`] — PIV (FIPS 201) smart card operations (keys, certificates, PIN)
//! - [`piv_util`] — CHUID generation and pivman management-key metadata helpers
//! - [`openpgp`] — OpenPGP card operations (keys, certificates, PIN)
//! - [`hsmauth`] — YubiHSM Auth credential management
//! - [`yubiotp`] — YubiOTP slot configuration (challenge-response, static passwords, HOTP)
//! - [`securitydomain`] — GlobalPlatform Security Domain (SCP03 key management)
//!
//! ## FIDO2 and WebAuthn
//! - [`ctap`] — Low-level CTAP transport session (CTAP1/CTAP2 dispatch)
//! - [`ctap2`] — CTAP2 commands: credentials, assertions, PIN/UV, bio enrollment, large blobs
//! - [`webauthn`] — High-level WebAuthn client with extension support (PRF, credProtect, largeBlob, etc.)
//!
//! ## Transport and protocol infrastructure
//! - [`platform`] — USB HID (FIDO and OTP) and PC/SC transport implementations (requires `pcsc` or `hid`)
//! - [`smartcard`] — ISO 7816 SmartCard / CCID connection, APDU handling, and SCP03 secure channel
//! - [`otp`] — OTP HID framing protocol
//! - [`core`] — Shared types: [`core::Version`], [`core::Connection`] trait
//! - [`cbor`] — CBOR encoding/decoding helpers for CTAP2
/// CBOR encoding and decoding utilities.
/// Core types shared across all YubiKey applications.
/// CTAP session management and device communication.
/// CTAP2 protocol implementation for FIDO2 authenticator operations.
/// High-level device enumeration and connection management.
/// FIDO connection trait and transport abstraction.
/// YubiHSM Auth application for symmetric key storage and derivation.
/// Cryptographic key types, parsing utilities, and OID encoding.
/// Logging utilities for diagnostic output.
/// Device management — reading info, configuring interfaces, and settings.
/// OATH (TOTP/HOTP) credential management.
/// OpenPGP smart card application.
/// OTP (One-Time Password) frame protocol and modhex codec.
/// PIV (Personal Identity Verification) smart card application.
/// PIV utilities for CHUID generation and pivman management-key metadata.
/// Platform-specific transport implementations (HID, PC/SC).
///
/// This module is available when the `pcsc` and/or `hid` features are enabled.
/// Security Domain operations for managing SCP keys and certificates.
/// Smart card communication primitives — APDUs, status words, ISO 7816-4, and SCP.
/// WebAuthn client — high-level API for credentials and assertions.
/// YubiOTP application — configuring OTP slots and challenge-response.