aboutsummaryrefslogtreecommitdiff
path: root/src/test/model/asn1/IntTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/model/asn1/IntTest.java')
-rw-r--r--src/test/model/asn1/IntTest.java58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/test/model/asn1/IntTest.java b/src/test/model/asn1/IntTest.java
index 23a5e23..d31d132 100644
--- a/src/test/model/asn1/IntTest.java
+++ b/src/test/model/asn1/IntTest.java
@@ -19,81 +19,81 @@ public class IntTest {
@Test
void testEncode() {
// Single-byte
- assertArrayEquals(new Byte[] { 0x0 }, new Int(Int.TAG, null, 0).encodeValueDER());
- assertArrayEquals(new Byte[] { 0x1 }, new Int(Int.TAG, null, 1).encodeValueDER());
- assertArrayEquals(new Byte[] { -1 }, new Int(Int.TAG, null, 255).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x0}, new Int(Int.TAG, null, 0).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x1}, new Int(Int.TAG, null, 1).encodeValueDER());
+ assertArrayEquals(new Byte[]{-1}, new Int(Int.TAG, null, 255).encodeValueDER());
// Multiple bytes
- assertArrayEquals(new Byte[] { 0x01, 0x00 }, new Int(Int.TAG, null, 256).encodeValueDER());
- assertArrayEquals(new Byte[] { -1, -1 }, new Int(Int.TAG, null, 65535).encodeValueDER());
- assertArrayEquals(new Byte[] { 0x01, 0x00, 0x00 }, new Int(Int.TAG, null, 65536).encodeValueDER());
- assertArrayEquals(new Byte[] { -1, -1, -1 }, new Int(Int.TAG, null, 16777215).encodeValueDER());
- assertArrayEquals(new Byte[] { 0x01, 0x00, 0x00, 0x00 }, new Int(Int.TAG, null, 16777216).encodeValueDER());
- assertArrayEquals(new Byte[] { -1, -1, -1, -1 }, new Int(Int.TAG, null, 4294967295L).encodeValueDER());
- assertArrayEquals(new Byte[] { -1, -1, -1, -1 }, new Int(Int.TAG, null, 4294967295L).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x01, 0x00}, new Int(Int.TAG, null, 256).encodeValueDER());
+ assertArrayEquals(new Byte[]{-1, -1}, new Int(Int.TAG, null, 65535).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x01, 0x00, 0x00}, new Int(Int.TAG, null, 65536).encodeValueDER());
+ assertArrayEquals(new Byte[]{-1, -1, -1}, new Int(Int.TAG, null, 16777215).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x01, 0x00, 0x00, 0x00}, new Int(Int.TAG, null, 16777216).encodeValueDER());
+ assertArrayEquals(new Byte[]{-1, -1, -1, -1}, new Int(Int.TAG, null, 4294967295L).encodeValueDER());
+ assertArrayEquals(new Byte[]{-1, -1, -1, -1}, new Int(Int.TAG, null, 4294967295L).encodeValueDER());
// 2 ^ 63 + 1
- assertArrayEquals(new Byte[] { -128, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+ assertArrayEquals(new Byte[]{-128, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
new Int(Int.TAG, null, Long.parseUnsignedLong("9223372036854775809")).encodeValueDER());
// Test no leading zeros
// Not 0x00, 0xFF
- assertArrayEquals(new Byte[] { -1 }, new Int(Int.TAG, null, 255).encodeValueDER());
+ assertArrayEquals(new Byte[]{-1}, new Int(Int.TAG, null, 255).encodeValueDER());
// Test no leading ones
// Not 0xFF, 0x80
- assertArrayEquals(new Byte[] { -128 }, new Int(Int.TAG, null, -128).encodeValueDER());
+ assertArrayEquals(new Byte[]{-128}, new Int(Int.TAG, null, -128).encodeValueDER());
// Encode DER
- assertArrayEquals(new Byte[] { 0x02, 2, 0x01, 0x00 }, new Int(Int.TAG, null, 256).encodeDER());
+ assertArrayEquals(new Byte[]{0x02, 2, 0x01, 0x00}, new Int(Int.TAG, null, 256).encodeDER());
}
@Test
void testParse() throws ParseException {
// Single-byte
- assertEquals(0, new Int(new BytesReader(new Byte[] { 0x2, 1, 0x0 }), false).getLong());
- assertEquals(1, new Int(new BytesReader(new Byte[] { 0x2, 1, 0x1 }), false).getLong());
- assertEquals(-1, new Int(new BytesReader(new Byte[] { 0x2, 1, -1 }), false).getLong());
+ assertEquals(0, new Int(new BytesReader(new Byte[]{0x2, 1, 0x0}), false).getLong());
+ assertEquals(1, new Int(new BytesReader(new Byte[]{0x2, 1, 0x1}), false).getLong());
+ assertEquals(-1, new Int(new BytesReader(new Byte[]{0x2, 1, -1}), false).getLong());
// Multiple bytes
assertEquals(256,
- new Int(new BytesReader(new Byte[] { 0x2, 2, 0x01, 0x00 }), false).getLong());
+ new Int(new BytesReader(new Byte[]{0x2, 2, 0x01, 0x00}), false).getLong());
assertEquals(-1,
- new Int(new BytesReader(new Byte[] { 0x2, 2, -1, -1 }), false).getLong());
+ new Int(new BytesReader(new Byte[]{0x2, 2, -1, -1}), false).getLong());
assertEquals(65536,
- new Int(new BytesReader(new Byte[] { 0x2, 3, 0x01, 0x00, 0x00 }), false).getLong());
+ new Int(new BytesReader(new Byte[]{0x2, 3, 0x01, 0x00, 0x00}), false).getLong());
assertEquals(-1,
- new Int(new BytesReader(new Byte[] { 0x2, 3, -1, -1, -1 }), false).getLong());
+ new Int(new BytesReader(new Byte[]{0x2, 3, -1, -1, -1}), false).getLong());
assertEquals(16777216,
- new Int(new BytesReader(new Byte[] { 0x2, 4, 0x01, 0x00, 0x00, 0x00 }), false).getLong());
+ new Int(new BytesReader(new Byte[]{0x2, 4, 0x01, 0x00, 0x00, 0x00}), false).getLong());
assertEquals(-1,
- new Int(new BytesReader(new Byte[] { 0x2, 4, -1, -1, -1, -1 }), false).getLong());
+ new Int(new BytesReader(new Byte[]{0x2, 4, -1, -1, -1, -1}), false).getLong());
assertEquals(4294967296L,
- new Int(new BytesReader(new Byte[] { 0x2, 5, 0x01, 0x00, 0x00, 0x00, 0x00 }),false).getLong());
+ new Int(new BytesReader(new Byte[]{0x2, 5, 0x01, 0x00, 0x00, 0x00, 0x00}), false).getLong());
// 2 ^ 63 + 1
assertEquals(Long.parseUnsignedLong("9223372036854775809"),
- new Int(new BytesReader(new Byte[] { 0x2, 9, 0x00, -128, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }),
+ new Int(new BytesReader(new Byte[]{0x2, 9, 0x00, -128, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}),
false).getValue().longValue());
// Test no leading zeros
// Not 0x00, 0xFF
- assertEquals(255, new Int(new BytesReader(new Byte[] { 0x02, 0x2, 0x0, -1 }), false).getLong());
+ assertEquals(255, new Int(new BytesReader(new Byte[]{0x02, 0x2, 0x0, -1}), false).getLong());
// Test no leading ones
// Not 0xFF, 0x80
- assertArrayEquals(new Byte[] { -128 }, new Int(Int.TAG, null, -128).encodeValueDER());
+ assertArrayEquals(new Byte[]{-128}, new Int(Int.TAG, null, -128).encodeValueDER());
}
@Test
void testParseFail() {
// Not enough bytes
assertThrows(ParseException.class, () ->
- new Int(new BytesReader(new Byte[]{ 0x2, 0x7, -1, -1, -1, -1, -1, -1 }),
+ new Int(new BytesReader(new Byte[]{0x2, 0x7, -1, -1, -1, -1, -1, -1}),
false));
// Zero len
assertThrows(ParseException.class, () ->
- new Int(new BytesReader(new Byte[]{ 0x2, 0x0, -1, -1, -1, -1, -1, -1 }),
+ new Int(new BytesReader(new Byte[]{0x2, 0x0, -1, -1, -1, -1, -1, -1}),
false));
}
}