Skip to content

Commit 4cb9c8e

Browse files
committed
misc: add comments, clarify return type
1 parent 0d71e6c commit 4cb9c8e

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/AsnPrivateKeyDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static IPrivateKey CreatePrivateKey(ReadOnlyMemory<byte> pkcs8EncodedKey)
7070
public static Curve25519PrivateKey CreateCurve25519Key(ReadOnlyMemory<byte> pkcs8EncodedKey) =>
7171
Curve25519PrivateKey.CreateFromPkcs8(pkcs8EncodedKey);
7272

73-
public static (byte[], KeyType) GetCurve25519PrivateKeyData(ReadOnlyMemory<byte> pkcs8EncodedKey)
73+
public static (byte[] privateKey, KeyType keyType) GetCurve25519PrivateKeyData(ReadOnlyMemory<byte> pkcs8EncodedKey)
7474
{
7575
var reader = new AsnReader(pkcs8EncodedKey, AsnEncodingRules.DER);
7676
var seqPrivateKeyInfo = reader.ReadSequence();

Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/AsnUtilities.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public static Span<byte> GetIntegerBytes(Span<byte> value)
8484
/// <exception cref="CryptographicException">If the private key does not meet the bit clamping requirements.</exception>
8585
public static void VerifyX25519PrivateKey(ReadOnlySpan<byte> x25519PrivateKey)
8686
{
87-
if ((x25519PrivateKey[0] & 0b111) != 0 || // Check that the 3 least significant bits are 0
88-
(x25519PrivateKey[31] & 0x80) != 0 || // Check most significant bit is 0
89-
(x25519PrivateKey[31] & 0x40) != 0x40) // Check second-most significant bit is 1
87+
if ((x25519PrivateKey[0] & 0b111) != 0 || // Check that the 3 least significant bits are set
88+
(x25519PrivateKey[31] & 0x80) != 0 || // Check most significant bit is set
89+
(x25519PrivateKey[31] & 0x40) != 0x40) // Check second most significant bit not set
9090
{
9191
throw new CryptographicException("Invalid X25519 private key: improper bit clamping");
9292
}

Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/Curve25519PrivateKey.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public override byte[] ExportPkcs8PrivateKey()
6868
/// </remarks>
6969
public override void Clear() => CryptographicOperations.ZeroMemory(_privateKey.Span);
7070

71-
72-
7371
/// <summary>
7472
/// Creates an instance of <see cref="Curve25519PrivateKey"/> from a PKCS#8
7573
/// DER-encoded private key.

Yubico.YubiKey/tests/unit/Yubico/YubiKey/Cryptography/ZeroingMemoryHandleTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class ZeroingMemoryHandleTests
2323
public void Dispose_ShouldClearArrayContent()
2424
{
2525
byte[] privateKeyData = new byte[] { 10, 20, 30, 40, 50 };
26-
2726
using (var secureData = new ZeroingMemoryHandle(privateKeyData))
2827
{
2928
Assert.Equal(new byte[] { 10, 20, 30, 40, 50 }, secureData.Data);

0 commit comments

Comments
 (0)