The CccId and CardId types allow you to interact with the Cardholder Capability Container (CCC) on a YubiKey. The CCC contains metadata about the card's capabilities, including a specific CardId.
Key Concepts
CccId: Represents the full 51-byte CCC identifier.CardId: Represents the 14-byte card identifier component extracted from the CCC.
Common Tasks
Retrieve the CCC ID from a YubiKey
Use CccId::get(&mut yubikey) to fetch the current CCC identifier from the device. This requires an active YubiKey instance.
If you have a CccId instance, you can extract the underlying 14-byte CardId using the .card_id() method.
Generate a new random Card ID
You can generate a new, random CardId using CardId::generate() or by providing a specific random number generator via CardId::generate_from_rng(rng).
use crate::yubikey::YubiKey;
use crate::cccid::{CccId, CardId};
// 1. Get the CCC ID from the device
let mut yubikey = YubiKey::open()?;
let ccc_id = CccId::get(&mut yubikey)?;
// 2. Extract the Card ID component
let card_id = ccc_id.card_id()?;
// 3. Generate a new random Card ID for future use
let new_card_id = CardId::generate();