Class GetMetadataCommand
Get information about the key in a specified slot.
public sealed class GetMetadataCommand : IYubiKeyCommand<GetMetadataResponse>
- Inheritance
-
objectGetMetadataCommand
- Implements
Remarks
The Get Metadata command is available on YubiKey version 5.3 and later.
The partner Response class is GetMetadataResponse.
See the User's Manual entry on getting metadata for specific information about what information is returned. Different slots return different sets of data.
Example:
IYubiKeyConnection connection = key.Connect(YubiKeyApplication.Piv);
GetMetadataCommand metadataCommand = new GetMetadataCommand(0x9A);
GetMetadataResponse metadataResponse = connection.SendCommand(metadataCommand);
if (metadataResponse.Status == ResponseStatus.Success)
{
PivMetadata keyData = metadataResponse.GetData();
}
Constructors
GetMetadataCommand()
Initializes a new instance of the GetMetadataCommand class.
public GetMetadataCommand()
Remarks
This constructor is provided for those developers who want to use the object initializer pattern. For example:
var getMetadataCommand = new GetMetadataCommand()
{
SlotNumber = PivSlot.Authentication,
};
There is no default slot number, hence, for this command to be valid, the slot number must be specified. So if you create an object using this constructor, you must set the SlotNumber property at some time before using it. Otherwise you will get an exception when you do use it.
The valid slot numbers are described in the User's Manual entry PIV slots. There is also the static class PivSlot providing mappings between slo/t names and numbers.
GetMetadataCommand(byte)
Initializes a new instance of the GetMetadataCommand class. This command takes the slot number as input.
public GetMetadataCommand(byte slotNumber)
Parameters
slotNumber
byteThe slot for which the metadata is requested.
Remarks
The valid slot numbers are described in the User's Manual entry PIV slots. There is also the static class PivSlot providing mappings between slot names and numbers.
For example, the following two are equivalent.
var getMetadata = new GetMetadataCommand(0x9C);
var getMetadata = new GetMetadataCommand(PivSlot.Signing);
Properties
Application
Gets the YubiKeyApplication to which this command belongs. For this command it's PIV.
public YubiKeyApplication Application { get; }
Property Value
- YubiKeyApplication
YubiKeyApplication.Piv
SlotNumber
The slot for which the metadate is requested.
public byte SlotNumber { get; set; }
Property Value
- byte
The slot number, see PivSlot
Exceptions
- ArgumentException
The slot specified is not valid for getting metadata.
Methods
CreateCommandApdu()
Creates a well-formed CommandApdu to send to the YubiKey.
public CommandApdu CreateCommandApdu()
Returns
- CommandApdu
A valid CommandApdu that is ready to be sent to the YubiKey, or passed along to additional encoders for further processing.
Remarks
This method will first perform validation on all of the parameters and data provided to it. The CommandAPDU it creates should contain all of the data payload for the command, even if it exceeds 65,535 bytes as specified by the ISO 7816-4 specification. The APDU will be properly chained by the device connection prior to being sent to the YubiKey, and the responses will collapsed into a single result.
CreateResponseForApdu(ResponseApdu)
Creates the corresponding IYubiKeyResponse implementation for the current command.
public GetMetadataResponse CreateResponseForApdu(ResponseApdu responseApdu)
Parameters
responseApdu
ResponseApduThe ResponseApdu returned by the YubiKey.
Returns
- GetMetadataResponse
The implementation of IYubiKeyResponse that parses and presents ths response APDU.