Class GetDataResponse
The response to the get data command, containing the information requested.
public sealed class GetDataResponse : PivResponse, IYubiKeyResponseWithData<ReadOnlyMemory<byte>>, IYubiKeyResponse
- Inheritance
-
objectGetDataResponse
- Implements
- Inherited Members
Remarks
This is the partner Response class to GetDataCommand.
The data returned is a byte array presented as a ReadOnlyMemory
.
It is the raw data returned by the YubiKey.
It is possible that the data requested is not on the YubiKey. For
example, suppose you request the certificate in slot 9A, but there is no
certificate in that slot yet. The YubiKey will return the Status Word
6A82
(SWConstants.FileOrApplicationNotFound
) and no data. In
that case, Status
will be NoData
and the GetData
method will throw an exception (there is no data).
It is possible the YubiKey could not return the requested data
because authentication was required (PIN or management key). If so, it
will return the Status Word 6982
(SWConstants.SecurityStatusNotSatisfied
) and no data. In that
case, Status
will be AuthenticationRequired
and the
GetData
method will throw an exception.
Your code can get the response object and check Status
and, if
Success
, call GetData
. If the Status
is anything
else, don't call GetData
.
Example:
IYubiKeyConnection connection = key.Connect(YubiKeyApplication.Piv);
GetDataCommand getDataCommand = new GetDataCommand(PivDataTag.Chuid);
GetDataResponse getDataResponse = connection.SendCommand(getDataCommand);
if (getDataResponse.Status != ResponseStatus.Success)
{
// Handle error
}
byte[] getChuid = getDataResponse.GetData();
Constructors
GetDataResponse(ResponseApdu)
Constructs a GetDataResponse based on a ResponseApdu received from the YubiKey.
public GetDataResponse(ResponseApdu responseApdu)
Parameters
responseApdu
ResponseApduThe object containing the response APDU
returned by the YubiKey.
Properties
StatusCodeMap
Retrieves the details describing the processing state.
protected override YubiKeyResponse.ResponseStatusPair StatusCodeMap { get; }
Property Value
- YubiKeyResponse.ResponseStatusPair
The ResponseStatus and a descriptive message, as a YubiKeyResponse.ResponseStatusPair.
Remarks
Implementers of subtypes can override this member to change or add mappings.
Methods
GetData()
Gets the data requested from the YubiKey response.
public ReadOnlyMemory<byte> GetData()
Returns
- ReadOnlyMemory<byte>
The data in the response APDU, presented as a byte array.
Remarks
The return is a byte array, the raw data returned by the YubiKey. It
is the caller's responsibility to parse that data. For example, if
the data returned is a certificate, the caller will likely want to
build an X509Certificate
object from the data.
It is a good idea to call this method, only if the Status
is
Success
. If it is not Success
, an exception will be
thrown.
If the Status property is ResponseStatus.NoData
,
then that particular element is not available. For example, if you
request the cert in slot 9A, but there is no cert in slot 9A, then
this will be the response. In this case, this method will throw an
exception.
If the Status is ResponseStatus.AuthenticationRequired
, then
the data is not available unless the PIN or
management key is entered. In this case, this method will throw an
exception.