pub struct Context {
pub reader: String,
pub serial: u32,
pub management_key: Option<String>,
pub defaults: DefaultCredentials,
pub piv: Arc<dyn PivBackend>,
pub debug: bool,
pub quiet: bool,
pub pin_protected: bool,
pub flash_handle: Option<Box<dyn FlashHandle>>,
/* private fields */
}Fields§
§reader: String§serial: u32§management_key: Option<String>§defaults: DefaultCredentialsWhich factory-default credentials were still active at startup.
piv: Arc<dyn PivBackend>§debug: bool§quiet: bool§pin_protected: bool§flash_handle: Option<Box<dyn FlashHandle>>Optional flash handle passed in from the interactive device picker.
Kept alive so the LED continues to flash into the next prompt.
Consumed by Context::take_flash.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(
opts: ContextOptions,
pin_fn: Box<dyn Fn() -> Result<Option<String>>>,
device_picker: DevicePicker,
output: OutputOptions,
) -> Result<Self>
pub fn new( opts: ContextOptions, pin_fn: Box<dyn Fn() -> Result<Option<String>>>, device_picker: DevicePicker, output: OutputOptions, ) -> Result<Self>
Build a Context from global CLI options, selecting the device.
pin is the PIN resolved from non-interactive sources (env var, stdin,
deprecated flag). pin_fn is called by require_pin() the first time
a PIN is needed and pin is still None — typically a TTY prompt
closure supplied by the application layer.
Sourcepub fn with_backend(
backend: Arc<dyn PivBackend>,
pin: Option<String>,
debug: bool,
) -> Result<Self>
pub fn with_backend( backend: Arc<dyn PivBackend>, pin: Option<String>, debug: bool, ) -> Result<Self>
Build a Context from an explicit PIV backend.
Use this when you have a VirtualPiv (for tests) or any other
custom PivBackend implementation. The backend must expose exactly
one device; if it exposes none or more than one, an error is returned.
Default-credential and PIN-derived-key checks are skipped (the caller controls the backend and is assumed to have configured it correctly).
Sourcepub fn require_pin(&self) -> Result<Option<String>>
pub fn require_pin(&self) -> Result<Option<String>>
Return the PIN, invoking pin_fn on first call if not yet resolved.
Resolution order:
- Already-cached PIN (from a non-interactive source or a prior call).
pin_fn()— supplied by the caller ofContext::new; typically a TTY prompt closure in the application layer. The result is cached so subsequent calls never invokepin_fnagain.None— the caller must decide whether to error.
Sourcepub fn management_key_for_write(&self) -> Result<Option<String>>
pub fn management_key_for_write(&self) -> Result<Option<String>>
Return the management key to use for write operations.
Priority: explicit –key > PIN-protected retrieval > None (use default).
Sourcepub fn take_flash(&mut self) -> Option<Box<dyn FlashHandle>>
pub fn take_flash(&mut self) -> Option<Box<dyn FlashHandle>>
Take the flash handle passed in from the interactive device picker.
Returns Some(handle) the first time it is called (if the picker
provided one), and None on all subsequent calls. The LED stops
flashing when the returned handle is dropped.
Sourcepub fn get_public_key(&self, slot: u8) -> Result<PublicKey>
pub fn get_public_key(&self, slot: u8) -> Result<PublicKey>
Retrieve the YubiKey’s public key from the given PIV slot.