|
|
@ -29,19 +29,19 @@ class CodeDelegationSignatureTest { |
|
|
|
void testValidInputs() { |
|
|
|
void testValidInputs() { |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
long yParity = 1L; |
|
|
|
BigInteger yParity = BigInteger.ONE; |
|
|
|
|
|
|
|
|
|
|
|
CodeDelegationSignature result = CodeDelegationSignature.create(r, s, yParity); |
|
|
|
CodeDelegationSignature result = CodeDelegationSignature.create(r, s, yParity); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(r).isEqualTo(result.getR()); |
|
|
|
assertThat(r).isEqualTo(result.getR()); |
|
|
|
assertThat(s).isEqualTo(result.getS()); |
|
|
|
assertThat(s).isEqualTo(result.getS()); |
|
|
|
assertThat((byte) yParity).isEqualTo(result.getRecId()); |
|
|
|
assertThat(yParity.byteValue()).isEqualTo(result.getRecId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void testNullRValue() { |
|
|
|
void testNullRValue() { |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
long yParity = 0L; |
|
|
|
BigInteger yParity = BigInteger.ZERO; |
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(NullPointerException.class) |
|
|
|
assertThatExceptionOfType(NullPointerException.class) |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(null, s, yParity)); |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(null, s, yParity)); |
|
|
@ -50,7 +50,7 @@ class CodeDelegationSignatureTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void testNullSValue() { |
|
|
|
void testNullSValue() { |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
long yParity = 0L; |
|
|
|
BigInteger yParity = BigInteger.ZERO; |
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(NullPointerException.class) |
|
|
|
assertThatExceptionOfType(NullPointerException.class) |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(r, null, yParity)); |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(r, null, yParity)); |
|
|
@ -60,7 +60,7 @@ class CodeDelegationSignatureTest { |
|
|
|
void testRValueExceedsTwoPow256() { |
|
|
|
void testRValueExceedsTwoPow256() { |
|
|
|
BigInteger r = TWO_POW_256; |
|
|
|
BigInteger r = TWO_POW_256; |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
long yParity = 0L; |
|
|
|
BigInteger yParity = BigInteger.ZERO; |
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(r, s, yParity)) |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(r, s, yParity)) |
|
|
@ -71,23 +71,34 @@ class CodeDelegationSignatureTest { |
|
|
|
void testSValueExceedsTwoPow256() { |
|
|
|
void testSValueExceedsTwoPow256() { |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
BigInteger s = TWO_POW_256; |
|
|
|
BigInteger s = TWO_POW_256; |
|
|
|
long yParity = 0L; |
|
|
|
BigInteger yParity = BigInteger.ZERO; |
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(r, s, yParity)) |
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(r, s, yParity)) |
|
|
|
.withMessageContainingAll("Invalid 's' value, should be < 2^256"); |
|
|
|
.withMessageContainingAll("Invalid 's' value, should be < 2^256"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void testYParityExceedsTwoPow256() { |
|
|
|
|
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
|
|
|
|
BigInteger s = BigInteger.TWO; |
|
|
|
|
|
|
|
BigInteger yParity = TWO_POW_256; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
|
|
|
|
.isThrownBy(() -> CodeDelegationSignature.create(r, s, yParity)) |
|
|
|
|
|
|
|
.withMessageContainingAll("Invalid 'yParity' value, should be < 2^256"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void testValidYParityZero() { |
|
|
|
void testValidYParityZero() { |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
BigInteger r = BigInteger.ONE; |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
BigInteger s = BigInteger.TEN; |
|
|
|
long yParity = 0L; |
|
|
|
BigInteger yParity = BigInteger.ZERO; |
|
|
|
|
|
|
|
|
|
|
|
CodeDelegationSignature result = CodeDelegationSignature.create(r, s, yParity); |
|
|
|
CodeDelegationSignature result = CodeDelegationSignature.create(r, s, yParity); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(r).isEqualTo(result.getR()); |
|
|
|
assertThat(r).isEqualTo(result.getR()); |
|
|
|
assertThat(s).isEqualTo(result.getS()); |
|
|
|
assertThat(s).isEqualTo(result.getS()); |
|
|
|
assertThat((byte) yParity).isEqualTo(result.getRecId()); |
|
|
|
assertThat(yParity.byteValue()).isEqualTo(result.getRecId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|