Skip to main content

Context

Struct Context 

Source
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: DefaultCredentials

Which 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

Source

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.

Source

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).

Source

pub fn require_pin(&self) -> Result<Option<String>>

Return the PIN, invoking pin_fn on first call if not yet resolved.

Resolution order:

  1. Already-cached PIN (from a non-interactive source or a prior call).
  2. pin_fn() — supplied by the caller of Context::new; typically a TTY prompt closure in the application layer. The result is cached so subsequent calls never invoke pin_fn again.
  3. None — the caller must decide whether to error.
Source

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).

Source

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.

Source

pub fn get_public_key(&self, slot: u8) -> Result<PublicKey>

Retrieve the YubiKey’s public key from the given PIV slot.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V