Table of Contents

Class ConfigureNdef

Namespace
Yubico.YubiKey.Otp.Operations
Assembly
Yubico.YubiKey.dll

Configures a YubiKey's NDEF slot for text or URI.

public class ConfigureNdef : OperationBase<ConfigureNdef>
Inheritance
object
ConfigureNdef
Inherited Members

Remarks

This class is not to be instantiated by non-SDK code. Instead, you will get a reference to an instance of this class by calling ConfigureNdef(Slot).

Once you have a reference to an instance, the member methods of this class can be used to chain together configurations using a builder pattern.

Methods

AsText(string)

Configures the NDEF slot to use freeform text as the basis for the generated OTP.

public ConfigureNdef AsText(string text)

Parameters

text string

The text to program into the NDEF slot.

Returns

ConfigureNdef

The current ConfigureNdef instance.

Exceptions

InvalidOperationException

This exception is thrown if the configuration build has already been configured to use a URI using the AsUri(Uri?) method.

AsUri(Uri?)

Configures the NDEF slot to use a URI as the basis for the generated OTP.

public ConfigureNdef AsUri(Uri? uri)

Parameters

uri Uri

The URI to program into the NDEF slot.

Returns

ConfigureNdef

The current ConfigureNdef instance.

Exceptions

InvalidOperationException

This exception is thrown if the configuration builder has already been configured to use text using the AsText(string) method.

ExecuteOperation()

Execute the operation here.

protected override void ExecuteOperation()

Remarks

This method is called after pre-launch code has run. Everything that could be validated should have been before this method is called.

The only validation could that should be in this method are things that could not be checked in the PreLaunchOperation() method. For example, if an operation must be completed in multiple steps, and subsequent steps depend on the success of previous steps, then it must be in this method by necessity.

PreLaunchOperation()

Validate all settings and choices here.

protected override void PreLaunchOperation()

Remarks

All possible validation should be done here. The point of this method is to simplify the ExecuteOperation() method that each operation must implement.

Conflicting choices that could not be checked by the OtpSettings<T> methods should be checked here.

Many of the operation classes use nullable fields (bool?) for choices. This allows the PreLaunchOperation() implementation to verify that a choice has been made. In the ExecuteOperation() method, the field has already been validated, and an exception thrown if it was not set, so null-forgiving operators are used when accessing those fields in ExecuteOperation().

UseUtf16Encoding(bool)

Encode the NDEF text using the UTF-16LE instead of UTF-8.

public ConfigureNdef UseUtf16Encoding(bool setOption = true)

Parameters

setOption bool

Returns

ConfigureNdef

The current ConfigureNdef instance.

Remarks

This setting only has an effect when programming the NDEF slot using AsText(string). If this is set and the AsUri(Uri?) method is called, an exception will be thrown when calling Execute().

By default, the text that is configured into the NDEF slot is encoded using UTF-8. This is the standard that is overwhelmingly preferred for modern operating systems. Some platforms, such as Microsoft Windows, use UTF-16 little endian encoding internally. However, when interacting with other systems, they still interpret UTF-8 encoding with no loss of functionality or compatibility. The option to use UTF-16 encoding is provided to you, but you are strongly advised to consider whether this is the correct choice for your scenario. If you aren't certain of the choice, then the default (UTF-8) is the correct choice and you should not call this method.

WithLanguage(string)

Add an ISO/IANA language code to the NDEF text configuration. Defaults to "en-US".

public ConfigureNdef WithLanguage(string languageCode)

Parameters

languageCode string

The Language Code Identifier (LCID) of the text.

Returns

ConfigureNdef

The current ConfigureNdef instance.

Remarks

If you are using this in a builder pattern where you might call this method with a conditional statement, the negative condition should pass either null or an empty string. If you pass null or an empty string, and you called AsText(string), then the default en-US will be applied.