Skip to content

Commit 4e3aade

Browse files
committed
misc: added logging when generate key
1 parent 3eea339 commit 4e3aade

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.KeyPairs.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.IO.Compression;
1919
using System.Security;
2020
using System.Security.Cryptography.X509Certificates;
21+
using Microsoft.Extensions.Logging;
2122
using Yubico.Core.Tlv;
2223
using Yubico.YubiKey.Cryptography;
2324
using Yubico.YubiKey.Piv.Commands;
@@ -60,7 +61,7 @@ public PivPublicKey GenerateKeyPair(
6061
return response.GetData();
6162
}
6263

63-
/// <summary>
64+
/// <summary>
6465
/// Generate a new key pair in the given slot.
6566
/// </summary>
6667
/// <remarks>
@@ -164,12 +165,19 @@ public IPublicKey GenerateKeyPair(
164165
PivPinPolicy pinPolicy = PivPinPolicy.Default,
165166
PivTouchPolicy touchPolicy = PivTouchPolicy.Default)
166167
{
168+
Logger.LogInformation("Generating key pair.");
169+
167170
YubiKey.ThrowIfUnsupportedAlgorithm(keyType.GetPivAlgorithm());
168171

169172
RefreshManagementKeyAuthentication();
170173

171174
var command = new GenerateKeyPairCommand(slotNumber, keyType, pinPolicy, touchPolicy);
172175
var response = Connection.SendCommand(command);
176+
177+
if (response.Status != ResponseStatus.Success)
178+
{
179+
throw new InvalidOperationException("Error generating key pair: " + response);
180+
}
173181

174182
return PivKeyDecoder.CreatePublicKey(response.Data, keyType);
175183
}

0 commit comments

Comments
 (0)