Show / Hide Table of Contents

ReadObject Method

ReadObject<T>()

Read the data at the storage location specified by the defined data tag for the PivDataObject T, storing and returning this data in a new object of type T.

C#
public T ReadObject<T>() where T : PivDataObject, new()

Returns

T

A new object of the type T. It contains the data stored on the YubiKey under the object's defined data tag. If there is no data stored, the returned object's IsEmpty property will be true.

Type Parameters

Name Description
T

The type of PivDataObject to create, set, and return.

Exceptions

Type Condition
ArgumentException

The data is not properly encoded for the data object.

Remarks

For example,

using CardholderUniqueId chuid = pivSession.ReadObject<CardholderUniqueId>();

See also the user's manual entry on PIV data objects.

It is possible that there is no data on the YubiKey in the specified storage location. If so, this method will return a new object with the IsEmpty property set to true.

If there is data stored under the specified data tag, this method will expect it to be formatted as defined by the class T. If it is not formatted as expected, this method will throw an exception.

Note that there is a method that can read using an alternate tag. This method will use the defined tag for the given class.

ReadObject<T>(int)

Read the data at the storage location specified by the given dataTag, storing and returning this data in a new object of type T.

C#
public T ReadObject<T>(int dataTag) where T : PivDataObject, new()

Parameters

Type Name Description
int dataTag

The alternate data tag, the tag of the storage location to look.

Returns

T

A new object of the type T. It contains the data stored on the YubiKey under the object's defined data tag. If there is no data stored, the returned object's IsEmpty property will be true.

Type Parameters

Name Description
T

The type of PivDataObject to create, set, and return.

Exceptions

Type Condition
ArgumentException

The dataTag in not allowed to be an alternate tag, or the data from the YubiKey is not properly encoded for the data object.

Remarks

For example,

using CardholderUniqueId chuid = pivSession.ReadObject<CardholderUniqueId>(0x005FFF55);

See also the user's manual entry on PIV data objects.

This is the same as the ReadObject<T>() method that takes no arguments, except this one will get the data in the storage location specified by dataTag, as opposed to the defined data tag for the class T. This method will still expect the data to be formatted as defined in the class T, it's just that the data is stored under a different tag.

This method is used when you have stored data under an alternate tag. It is likely you will never need this feature, and it is dangerous, because if done incorrectly, sensitive data that should require PIN verification to access will be available without a PIN). But there are rare cases when this feature is useful.

In this article
Back to top Generated by DocFX