HasFeature Method
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
Type | Name | Description |
---|---|---|
IYubiKeyDevice | yubiKeyDevice | The YubiKey device to query. |
YubiKeyFeature | feature | The name of the feature that you wish to query. |
Returns
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;
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The YubiKey device was null. |
System.ArgumentException | An unknown feature was queried. |
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.