Skip to content

Commit

Permalink
addressed PR feedback: tests and reliability of ECParameters
Browse files Browse the repository at this point in the history
will not default to empty Array on null (ECParameterExtensions)
added tests for ECParametersExtensions
added tests for ECPrivateKeyParameters
added tests for ECPublicKeyParameters
  • Loading branch information
DennisDyallo committed Dec 12, 2024
1 parent d36823e commit cd72d24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions Yubico.YubiKey/src/Yubico/YubiKey/Scp/Scp03State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ private void PerformExternalAuthenticate(IApduTransform pipeline)

return (macedApdu.Data, newMacChainingValue);
}


/// <inheritdoc cref="ScpState.Dispose()"/>
protected override void Dispose(bool disposing)
{
if (disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ public void Constructor_WithNullECDsaObject_ThrowsArgumentNullException()
}

[Theory]
[InlineData("nistP256")]
[InlineData("nistP384")]
[InlineData("nistP521")]
public void Constructor_WithDifferentCurves_CreatesValidInstance(string curveName)
[InlineData("1.2.840.10045.3.1.7")] // NIST P-256
[InlineData("1.3.132.0.34")] // NIST P-384
[InlineData("1.3.132.0.35")] // NIST P-512
public void Constructor_WithDifferentCurves_CreatesValidInstance(string oid)
{
// Arrange
using var ecdsa = ECDsa.Create(ECCurve.CreateFromFriendlyName(curveName));

using var ecdsa = ECDsa.Create(ECCurve.CreateFromOid(Oid.FromOidValue(oid, OidGroup.PublicKeyAlgorithm)));
// Act
var privateKeyParams = new ECPrivateKeyParameters(ecdsa);

// Assert
Assert.Equal(curveName, privateKeyParams.Parameters.Curve.Oid.FriendlyName);
Assert.Equal(oid, privateKeyParams.Parameters.Curve.Oid.Value);
Assert.NotNull(privateKeyParams.Parameters.D);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,22 @@ public void GetBytes_ReturnsCorrectFormat()
}

[Theory]
[InlineData("nistP256")]
[InlineData("nistP384")]
[InlineData("nistP521")]
public void Constructor_WithDifferentCurves_CreatesValidInstance(string curveName)
[InlineData("1.2.840.10045.3.1.7")] // NIST P-256
[InlineData("1.3.132.0.34")] // NIST P-384
[InlineData("1.3.132.0.35")] // NIST P-512
public void Constructor_WithDifferentCurves_CreatesValidInstance(string oid)
{
// Arrange
using var ecdsa = ECDsa.Create(ECCurve.CreateFromFriendlyName(curveName));

using var ecdsa = ECDsa.Create(ECCurve.CreateFromOid(Oid.FromOidValue(oid, OidGroup.PublicKeyAlgorithm)));
// Act
var publicKeyParams = new ECPublicKeyParameters(ecdsa);

// Assert
Assert.Equal(curveName, publicKeyParams.Parameters.Curve.Oid.FriendlyName);
Assert.Equal(oid, publicKeyParams.Parameters.Curve.Oid.Value);
Assert.NotNull(publicKeyParams.Parameters.Q.X);
Assert.NotNull(publicKeyParams.Parameters.Q.Y);

}

[Fact]
Expand Down

0 comments on commit cd72d24

Please sign in to comment.