Skip to content

Commit 9789d88

Browse files
committed
feat: Implement reading of VersionQualifier into YubikeyDeviceInfo
1 parent 50e1ee4 commit 9789d88

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

Yubico.YubiKey/src/Yubico/YubiKey/VersionQualifier.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,10 @@ internal class VersionQualifier
6262
/// <exception cref="ArgumentNullException"></exception>
6363
public VersionQualifier(FirmwareVersion firmwareVersion, VersionQualifierType type, long iteration)
6464
{
65-
if (iteration < 0)
65+
if (iteration < 0 || iteration > uint.MaxValue)
6666
{
67-
throw new ArgumentOutOfRangeException(nameof(iteration), "Iteration must be a non-negative value.");
68-
}
69-
70-
if (iteration > uint.MaxValue)
71-
{
72-
throw new ArgumentOutOfRangeException(nameof(iteration), "Iteration must be less than or equal to int.MaxValue.");
67+
throw new ArgumentOutOfRangeException(nameof(iteration),
68+
$"Iteration must be between 0 and {uint.MaxValue}.");
7369
}
7470

7571
FirmwareVersion = firmwareVersion ?? throw new ArgumentNullException(nameof(firmwareVersion));

Yubico.YubiKey/tests/unit/Yubico/YubiKey/YubikeyDeviceInfoTests.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ private static YubiKeyDeviceInfo DeviceInfoFor(int tag, byte[] deviceInfoData, F
280280
SetVersionTag(tag, version, tlvs);
281281
}
282282

283-
SetVersionQualifierTag(versionQualifier, tlvs);
284283

285284
return YubiKeyDeviceInfo.CreateFromResponseData(tlvs); //We're testing this method
286285
}
@@ -298,25 +297,6 @@ private static void SetVersionTag(int tag, FirmwareVersion? version, Dictionary<
298297
}
299298
}
300299

301-
private static void SetVersionQualifierTag(VersionQualifier? versionQualifier, Dictionary<int, ReadOnlyMemory<byte>> tlvs)
302-
{
303-
if (versionQualifier is null)
304-
{
305-
return;
306-
}
307-
308-
var tlvVq = TlvObjects.EncodeMany(
309-
new TlvObject(0x01, VersionToBytes(versionQualifier.FirmwareVersion)),
310-
new TlvObject(0x02, [(byte)versionQualifier.Type]),
311-
new TlvObject(0x03, [0, 0, 0, (byte)versionQualifier.Iteration]));
312-
313-
var tlvVqLength = tlvVq.Length;
314-
Debug.WriteLine($"VersionQualifier TLV length: {tlvVqLength}");
315-
316-
const byte versionQualifierTag = 0x019;
317-
tlvs.Add(versionQualifierTag, tlvVq);
318-
}
319-
320300
private static byte[] VersionToBytes(FirmwareVersion version) => [version.Major, version.Minor, version.Patch];
321301

322302
private static byte[] FromHex(string? hex) => hex != null ? Base16.DecodeText(hex) : Array.Empty<byte>();

0 commit comments

Comments
 (0)