Skip to content

Commit ef7fea0

Browse files
authored
Updates to YubiKeyInformation type (#173)
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.
1 parent 0bccc6c commit ef7fea0

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Module/Cmdlets/Yubikey/FindYubikey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/// </summary>
1717

1818
// Imports
19+
using powershellYK.YubiKey;
1920
using System.Management.Automation; // Windows PowerShell namespace.
2021
using Yubico.YubiKey;
2122

@@ -57,7 +58,7 @@ protected override void BeginProcessing()
5758
// Return found YubiKeys
5859
foreach (var yubiKey in yubiKeys)
5960
{
60-
WriteObject((YubiKeyDevice)yubiKey);
61+
WriteObject(new YubikeyInformation(yubiKey: (YubiKeyDevice)yubiKey));
6162
}
6263

6364
// Handle case when no YubiKeys are found

Module/Cmdlets/Yubikey/GetYubikey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected override void ProcessRecord()
5555
try
5656
{
5757
// Get and return YubiKey information
58-
WriteObject(new YubikeyInformation(yubiKey: (YubiKeyDevice)YubiKeyDevice.FindAll().Where(yk => yk.SerialNumber == YubiKeyModule._yubikey!.SerialNumber).First()));
58+
WriteObject(new YubikeyInformation(yubiKey: YubiKeyModule._yubikey));
5959
}
6060
catch (System.InvalidOperationException e)
6161
{

Module/types/YubiKeyInformation.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Yubico.YubiKey.Fido2.Cose;
2626
using powershellYK.support;
2727
using Yubico.YubiKey;
28+
using powershellYK.PIV;
2829

2930
namespace powershellYK.YubiKey
3031
{
@@ -110,5 +111,14 @@ public YubikeyInformation(YubiKeyDevice yubiKey)
110111
this.YubiKeyDevice = yubiKey;
111112
this.PrettyName = PowershellYKText.FriendlyName(yubiKey);
112113
}
114+
115+
#region Operators
116+
117+
public static implicit operator YubiKeyDevice(YubikeyInformation info)
118+
{
119+
return info.YubiKeyDevice;
120+
}
121+
122+
#endregion
113123
}
114124
}

0 commit comments

Comments
 (0)