From 279cf02b3609281484022b6bfcb93c4851155540 Mon Sep 17 00:00:00 2001 From: Oscar Virot Date: Tue, 22 Jul 2025 11:38:28 +0200 Subject: [PATCH] Change Find-YubiKey to return YubikeyInformation type Change Get-YubiKey to simpler ways, Yubico SDK caches the issue that I wanted to work around, no need for complex code then Update YubikeyInformation to allow for transformed to YubiKeyDevice by casting. --- Module/Cmdlets/Yubikey/FindYubikey.cs | 3 ++- Module/Cmdlets/Yubikey/GetYubikey.cs | 2 +- Module/types/YubiKeyInformation.cs | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Module/Cmdlets/Yubikey/FindYubikey.cs b/Module/Cmdlets/Yubikey/FindYubikey.cs index bba1563..1fc9330 100644 --- a/Module/Cmdlets/Yubikey/FindYubikey.cs +++ b/Module/Cmdlets/Yubikey/FindYubikey.cs @@ -16,6 +16,7 @@ /// // Imports +using powershellYK.YubiKey; using System.Management.Automation; // Windows PowerShell namespace. using Yubico.YubiKey; @@ -57,7 +58,7 @@ protected override void BeginProcessing() // Return found YubiKeys foreach (var yubiKey in yubiKeys) { - WriteObject((YubiKeyDevice)yubiKey); + WriteObject(new YubikeyInformation(yubiKey: (YubiKeyDevice)yubiKey)); } // Handle case when no YubiKeys are found diff --git a/Module/Cmdlets/Yubikey/GetYubikey.cs b/Module/Cmdlets/Yubikey/GetYubikey.cs index c57b6af..09392b8 100644 --- a/Module/Cmdlets/Yubikey/GetYubikey.cs +++ b/Module/Cmdlets/Yubikey/GetYubikey.cs @@ -55,7 +55,7 @@ protected override void ProcessRecord() try { // Get and return YubiKey information - WriteObject(new YubikeyInformation(yubiKey: (YubiKeyDevice)YubiKeyDevice.FindAll().Where(yk => yk.SerialNumber == YubiKeyModule._yubikey!.SerialNumber).First())); + WriteObject(new YubikeyInformation(yubiKey: YubiKeyModule._yubikey)); } catch (System.InvalidOperationException e) { diff --git a/Module/types/YubiKeyInformation.cs b/Module/types/YubiKeyInformation.cs index 98904cf..b4cf6b0 100644 --- a/Module/types/YubiKeyInformation.cs +++ b/Module/types/YubiKeyInformation.cs @@ -25,6 +25,7 @@ using Yubico.YubiKey.Fido2.Cose; using powershellYK.support; using Yubico.YubiKey; +using powershellYK.PIV; namespace powershellYK.YubiKey { @@ -110,5 +111,14 @@ public YubikeyInformation(YubiKeyDevice yubiKey) this.YubiKeyDevice = yubiKey; this.PrettyName = PowershellYKText.FriendlyName(yubiKey); } + + #region Operators + + public static implicit operator YubiKeyDevice(YubikeyInformation info) + { + return info.YubiKeyDevice; + } + + #endregion } }