Table of Contents

Class YubiKeyFeatureExtensions

Namespace
Yubico.YubiKey
Assembly
Yubico.YubiKey.dll

A static class containing the HasFeature(IYubiKeyDevice, YubiKeyFeature) extension method.

public static class YubiKeyFeatureExtensions
Inheritance
object
YubiKeyFeatureExtensions

Methods

HasFeature(IYubiKeyDevice, YubiKeyFeature)

Feature presence detection. Used to query whether or not a particular YubiKey feature is available for this device.

public static bool HasFeature(this IYubiKeyDevice yubiKeyDevice, YubiKeyFeature feature)

Parameters

yubiKeyDevice IYubiKeyDevice

The YubiKey device to query.

feature YubiKeyFeature

The name of the feature that you wish to query.

Returns

bool

true if the feature is present on the YubiKey, false otherwise.

Examples

Get the number of total tries a user has to enter the PIN of the PIV application:

public int GetPinTries(YubiKeyDevice yubiKeyDevice)
{
  if (!yubiKeyDevice.HasFeature(YubiKeyFeature.PivMetadata))
    throw new NotSupportedException("The PIV metadata command is not supported on this YubiKey.");

  using PivSession piv = new PivSession(yubiKeyDevice);
  var metadata = piv.GetMetadata(PivSlot.Pin);
  return metadata.RetryCount;
}

Remarks

Use this API to programmatically detect if a particular feature is present on a YubiKey. If your application needs to deal with a heterogeneous deployment of YubiKeys across major releases, this method allows you to switch on whether a certain feature is present or not. This method is meant to be more accurate than querying firmware versions directly, as it will be kept up to date with all YubiKey releases.

Exceptions

ArgumentNullException

The YubiKey device was null.

ArgumentException

An unknown feature was queried.

ThrowOnMissingFeature(IYubiKeyDevice, YubiKeyFeature)

Throws a System.NotSupportedException if the YubiKey doesn't support the requested feature.

public static void ThrowOnMissingFeature(this IYubiKeyDevice yubiKeyDevice, YubiKeyFeature feature)

Parameters

yubiKeyDevice IYubiKeyDevice
feature YubiKeyFeature

Exceptions

NotSupportedException