-
Notifications
You must be signed in to change notification settings - Fork 55
feat: Implement reading of VersionQualifier into YubikeyDeviceInfo #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Test Results: Windows 2 files 2 suites 9s ⏱️ Results for commit f15f0e4. ♻️ This comment has been updated with latest results. |
Test Results: Ubuntu 2 files 2 suites 16s ⏱️ Results for commit f15f0e4. ♻️ This comment has been updated with latest results. |
Test Results: MacOS 2 files 2 suites 11s ⏱️ Results for commit f15f0e4. ♻️ This comment has been updated with latest results. |
dc9cf7e
to
9789d88
Compare
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for reading and representing firmware version qualifiers in YubiKeyDeviceInfo
, enhances version parsing, and covers these changes with unit tests.
- Introduce
VersionQualifier
class and corresponding TLV tag - Update
YubiKeyDeviceInfo
to parse, store, and override firmware version based on qualifiers - Add
FromBytes
toFirmwareVersion
and comprehensive unit tests
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
tests/unit/Yubico/YubiKey/YubikeyDeviceInfoTests.cs | Refactor test helpers, replace DeviceInfoFor defaults, add qualifier parsing tests |
tests/unit/Yubico/YubiKey/VersionQualifierTests.cs | New unit tests for VersionQualifier behavior |
src/Yubico/YubiKey/YubikeyDeviceManagementTags.cs | Add VersionQualifierTag constant |
src/Yubico/YubiKey/YubiKeyDeviceInfo.cs | Parse and apply version qualifiers; add VersionName property |
src/Yubico/YubiKey/VersionQualifier.cs | Implement VersionQualifier class |
src/Yubico/YubiKey/FirmwareVersion.cs | Add FromBytes factory for 3-byte firmware version parsing |
Comments suppressed due to low confidence (4)
Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceInfo.cs:375
- Using '!=' on a class compares references, not values, so this check will always be true (different instances). As a result, default qualifiers will never defer to
second
. Use!VersionQualifier.Equals(new VersionQualifier())
or compare against a shared default instance instead.
VersionQualifier = VersionQualifier != new VersionQualifier() ? VersionQualifier : second.VersionQualifier,
Yubico.YubiKey/src/Yubico/YubiKey/VersionQualifier.cs:60
- The documentation states an upper bound of int.MaxValue, but the code actually allows up to uint.MaxValue. Update the doc to reflect the correct maximum or adjust the code to match.
/// <param name="iteration">The iteration number of the version qualifier, must be a non-negative value and less than or equal to int.MaxValue.</param>
Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceInfo.cs:321
- [nitpick] Local variable names in C# should be camelCase. Rename
Logger
tologger
to follow naming conventions.
var Logger = Core.Logging.Log.GetLogger<YubiKeyDeviceInfo>();
Yubico.YubiKey/tests/unit/Yubico/YubiKey/YubikeyDeviceInfoTests.cs:263
- DefaultInfo currently passes an empty array to CreateFromResponseData, which expects a Dictionary<int, ReadOnlyMemory>. Change this to pass an empty Dictionary<int, ReadOnlyMemory> (e.g., new Dictionary<int, ReadOnlyMemory>()).
private static YubiKeyDeviceInfo DefaultInfo() => YubiKeyDeviceInfo.CreateFromResponseData([]);
Yubico.YubiKey/tests/unit/Yubico/YubiKey/YubikeyDeviceInfoTests.cs
Outdated
Show resolved
Hide resolved
Yubico.YubiKey/tests/unit/Yubico/YubiKey/YubikeyDeviceInfoTests.cs
Outdated
Show resolved
Hide resolved
Yubico.YubiKey/tests/unit/Yubico/YubiKey/YubikeyDeviceInfoTests.cs
Outdated
Show resolved
Hide resolved
…s.cs Co-authored-by: Copilot <[email protected]>
…s.cs Co-authored-by: Copilot <[email protected]>
…s.cs Co-authored-by: Copilot <[email protected]>
Yubico.YubiKey/tests/unit/Yubico/YubiKey/VersionQualifierTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
This pull request introduces several enhancements and new features to the
Yubico.YubiKey
library, focusing on firmware version handling, version qualifiers, and unit tests. The most important changes include adding aVersionQualifier
class, updatingYubiKeyDeviceInfo
to support version qualifiers, and introducing comprehensive unit tests for these updates.Fixes: YESDK-1451
Type of change
How has this been tested?
I have ran unit tests similar to those in the Java Yubikit SDK. I have yet to run them on actual keys.
Test configuration:
Checklist:
dotnet format
to format my codeFirmware Version Enhancements:
FirmwareVersion.FromBytes
method to create aFirmwareVersion
instance from a byte array containing major, minor, and patch versions. Includes validation for the byte array length. (FirmwareVersion.cs
, Yubico.YubiKey/src/Yubico/YubiKey/FirmwareVersion.csR95-R115)Version Qualifier Feature:
VersionQualifier
class: Added a new class to represent version qualifiers, including the firmware version, type (Alpha, Beta, Final), and iteration number. Includes constructors, validation, and overrides forToString
,Equals
, andGetHashCode
. (VersionQualifier.cs
, Yubico.YubiKey/src/Yubico/YubiKey/VersionQualifier.csR1-R98)VersionQualifierTag
constant: UpdatedYubikeyDeviceManagementTags
to include a new tag for version qualifiers. (YubikeyDeviceManagementTags.cs
, Yubico.YubiKey/src/Yubico/YubiKey/YubikeyDeviceManagementTags.csR45)Integration with
YubiKeyDeviceInfo
:YubiKeyDeviceInfo
: Added aVersionQualifier
property and logic to handle version qualifiers in theCreateFromResponseData
method. The firmware version is overridden by the version qualifier when applicable. (YubiKeyDeviceInfo.cs
, [1] [2]YubiKeyDeviceInfo
constructor: DefaultVersionQualifier
is initialized toFinal
with iteration 0. (YubiKeyDeviceInfo.cs
, Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceInfo.csR121)Unit Tests:
VersionQualifier
: Comprehensive unit tests forVersionQualifier
class, covering initialization, string representation, equality, and hash code functionality. (VersionQualifierTests.cs
, Yubico.YubiKey/tests/unit/Yubico/YubiKey/VersionQualifierTests.csR1-R97)YubiKeyDeviceInfoTests
: Improved test readability by introducing aDefaultInfo
helper method to streamline test setup. (YubikeyDeviceInfoTests.cs
, [1] [2] [3]Footnotes
See Yubikey models (Multi-protocol, Security Key, FIPS, Bio, YubiHSM, YubiHSM FIPS) ↩