Class DesktopDeviceSelector

java.lang.Object
com.yubico.yubikit.desktop.DesktopDeviceSelector

public final class DesktopDeviceSelector extends Object
Identifies a specific YubiKey device for selection purposes.

A selector can target a device either by its serial number (preferred when available) or by its fingerprint (a fallback identifier derived from the underlying USB device path or PCSC terminal name). Selectors derived from device records (via YubiKitManager.listDeviceRecords()) may contain both identifiers, allowing lookup by either.

Serial number selection is preferred because serial numbers are stable across unplug/replug cycles and across processes. Use forSerial(int) when the device serial is known.

Fingerprint selection is a fallback for devices that do not expose a serial number (e.g. certain Security Key models). Note that fingerprints are not guaranteed to be stable across unplug/replug cycles or across process restarts — they are derived from OS-assigned device paths. Use forFingerprint(String) when serial is unavailable.

See Also:
  • Method Details

    • forSerial

      public static DesktopDeviceSelector forSerial(int serial)
      Creates a selector that targets a device by its serial number.
      Parameters:
      serial - the device serial number
      Returns:
      a serial-based selector
    • forFingerprint

      public static DesktopDeviceSelector forFingerprint(String fingerprint)
      Creates a selector that targets a device by its fingerprint.

      The fingerprint is typically the HID device path or PCSC terminal name. It is not guaranteed to be stable across unplug/replug cycles or process restarts.

      Parameters:
      fingerprint - the device fingerprint
      Returns:
      a fingerprint-based selector
    • getSerial

      public @Nullable Integer getSerial()
      Returns the serial number used for selection, or null if this selector uses only a fingerprint.
    • getFingerprint

      public @Nullable String getFingerprint()
      Returns the fingerprint used for selection, or null if unavailable.

      When the selector was created via forSerial(int), the fingerprint is null. When derived from a device record, the fingerprint is always populated.

    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object