From 28fa18278c1f3a87722d5e8b78f581526a30bb38 Mon Sep 17 00:00:00 2001 From: Yuuta Liang Date: Sat, 14 Oct 2023 05:35:17 +0800 Subject: Fix lint Signed-off-by: Yuuta Liang --- src/test/model/asn1/ASN1ObjectTest.java | 67 +++++++++++++++++---------------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'src/test/model/asn1/ASN1ObjectTest.java') diff --git a/src/test/model/asn1/ASN1ObjectTest.java b/src/test/model/asn1/ASN1ObjectTest.java index ea765e6..76615c5 100644 --- a/src/test/model/asn1/ASN1ObjectTest.java +++ b/src/test/model/asn1/ASN1ObjectTest.java @@ -20,17 +20,17 @@ public class ASN1ObjectTest { false).getClass()); assertEquals(BitString.class, ASN1Object.parse(new BytesReader(new BitString(BitString.TAG, - null, 0, new Byte[]{ 1 }).encodeDER()), + null, 0, new Byte[]{1}).encodeDER()), false).getClass()); assertEquals(OctetString.class, - ASN1Object.parse(new BytesReader(new OctetString(OctetString.TAG, null, new Byte[]{ 1 }).encodeDER()), + ASN1Object.parse(new BytesReader(new OctetString(OctetString.TAG, null, new Byte[]{1}).encodeDER()), false).getClass()); assertEquals(Null.class, ASN1Object.parse(new BytesReader(new Null(Null.TAG, null).encodeDER()), false).getClass()); assertEquals(ObjectIdentifier.class, ASN1Object.parse(new BytesReader(new ObjectIdentifier(ObjectIdentifier.TAG, null, - new Integer[]{ 1, 2, 3 }).encodeDER()), + new Integer[]{1, 2, 3}).encodeDER()), false).getClass()); assertEquals(UTF8String.class, ASN1Object.parse(new BytesReader(new UTF8String(UTF8String.TAG, null, @@ -53,7 +53,7 @@ public class ASN1ObjectTest { ZonedDateTime.now(ZoneId.of("UTC"))).encodeDER()), false).getClass()); assertEquals(ASN1Object.class, - ASN1Object.parse(new BytesReader(new Byte[]{ 0x30, 1, 0x0 }), false) + ASN1Object.parse(new BytesReader(new Byte[]{0x30, 1, 0x0}), false) .getClass()); } @@ -68,53 +68,54 @@ public class ASN1ObjectTest { new ASN1Object(new Tag(TagClass.UNIVERSAL, false, 0x5), new Tag(TagClass.UNIVERSAL, false, 0x6)).getParentTag().getNumber()); } + @Test void testParseSuccess() throws ParseException { // No parent tag assertEquals(0x5, - new ASN1Object(new BytesReader(new Byte[]{ 0x5, 0x0 }), false) + new ASN1Object(new BytesReader(new Byte[]{0x5, 0x0}), false) .getTag().getNumber()); assertEquals(TagClass.UNIVERSAL, - new ASN1Object(new BytesReader(new Byte[]{ 0x5, 0x0 }), false) + new ASN1Object(new BytesReader(new Byte[]{0x5, 0x0}), false) .getTag().getCls()); - assertFalse(new ASN1Object(new BytesReader(new Byte[]{ 0x5, 0x0 }), false) + assertFalse(new ASN1Object(new BytesReader(new Byte[]{0x5, 0x0}), false) .getTag().isConstructive()); - assertNull(new ASN1Object(new BytesReader(new Byte[]{ 0x5, 0x0 }), false) + assertNull(new ASN1Object(new BytesReader(new Byte[]{0x5, 0x0}), false) .getParentTag()); - assertEquals(0, new ASN1Object(new BytesReader(new Byte[]{ 0x5, 0x0 }), false) + assertEquals(0, new ASN1Object(new BytesReader(new Byte[]{0x5, 0x0}), false) .encodeValueDER().length); - assertEquals(0, new ASN1Object(new BytesReader(new Byte[]{ 0x5, 0x0 }), false) + assertEquals(0, new ASN1Object(new BytesReader(new Byte[]{0x5, 0x0}), false) .getLength()); // With parent tag // -95 is the 2's complement represent of 0b10100001 assertEquals(0x5, - new ASN1Object(new BytesReader(new Byte[]{ -95, 2, 0x5, 0x0 }), true) + new ASN1Object(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true) .getTag().getNumber()); assertEquals(TagClass.UNIVERSAL, - new ASN1Object(new BytesReader(new Byte[]{ -95, 2, 0x5, 0x0 }), true) + new ASN1Object(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true) .getTag().getCls()); - assertFalse(new ASN1Object(new BytesReader(new Byte[]{ -95, 2, 0x5, 0x0 }), true) + assertFalse(new ASN1Object(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true) .getTag().isConstructive()); assertEquals(0x1, - new ASN1Object(new BytesReader(new Byte[]{ -95, 2, 0x5, 0x0 }), true) + new ASN1Object(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true) .getParentTag().getNumber()); assertEquals(TagClass.CONTEXT_SPECIFIC, - new ASN1Object(new BytesReader(new Byte[]{ -95, 2, 0x5, 0x0 }), true) + new ASN1Object(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true) .getParentTag().getCls()); - assertTrue(new ASN1Object(new BytesReader(new Byte[]{ -95, 2, 0x5, 0x0 }), true) + assertTrue(new ASN1Object(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true) .getParentTag().isConstructive()); // Test index - BytesReader reader = new BytesReader(new Byte[]{ 0xE, 5, 1, 2, 3, 4, 5 }); + BytesReader reader = new BytesReader(new Byte[]{0xE, 5, 1, 2, 3, 4, 5}); ASN1Object obj = new ASN1Object(reader, false); // Contents should not be read. assertEquals(2, reader.getIndex()); // But is copied - assertArrayEquals(new Byte[]{ 1, 2, 3, 4, 5 }, obj.encodeValueDER()); + assertArrayEquals(new Byte[]{1, 2, 3, 4, 5}, obj.encodeValueDER()); // If we parse an unknown type - reader = new BytesReader(new Byte[]{ 0xE, 5, 1, 2, 3, 4, 5 }); + reader = new BytesReader(new Byte[]{0xE, 5, 1, 2, 3, 4, 5}); obj = ASN1Object.parse(reader, false); // Contents should be read now assertEquals(7, reader.getIndex()); @@ -124,50 +125,50 @@ public class ASN1ObjectTest { void testParseFail() { // Value early EOF assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ 0x5, 0x1 }), false)); + new ASN1Object(new BytesReader(new Byte[]{0x5, 0x1}), false)); // Tag early EOF assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ -95, 2 }), true)); + new ASN1Object(new BytesReader(new Byte[]{-95, 2}), true)); // Length not found assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ 0x5 }), false)); + new ASN1Object(new BytesReader(new Byte[]{0x5}), false)); assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ -95, 2, 0x5 }), true)); + new ASN1Object(new BytesReader(new Byte[]{-95, 2, 0x5}), true)); // Parent tag is not CONTEXT_SPECIFIC // UNIVERSAL assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ 33, 2, 0x5, 0x0 }), true)); + new ASN1Object(new BytesReader(new Byte[]{33, 2, 0x5, 0x0}), true)); // APPLICATION assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ 97, 2, 0x5, 0x0 }), true)); + new ASN1Object(new BytesReader(new Byte[]{97, 2, 0x5, 0x0}), true)); // PRIVATE assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ -31, 2, 0x5, 0x0 }), true)); + new ASN1Object(new BytesReader(new Byte[]{-31, 2, 0x5, 0x0}), true)); // Parent tag is not constructive assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ -127, 2, 0x5, 0x0 }), true)); + new ASN1Object(new BytesReader(new Byte[]{-127, 2, 0x5, 0x0}), true)); // Parent tag length incorrect assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ -95, 0, 0x5, 0x0 }), true)); + new ASN1Object(new BytesReader(new Byte[]{-95, 0, 0x5, 0x0}), true)); assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ -95, 1, 0x5, 0x0 }), true)); + new ASN1Object(new BytesReader(new Byte[]{-95, 1, 0x5, 0x0}), true)); assertThrows(ParseException.class, () -> - new ASN1Object(new BytesReader(new Byte[]{ -95, 3, 0x5, 0x0 }), true)); + new ASN1Object(new BytesReader(new Byte[]{-95, 3, 0x5, 0x0}), true)); } @Test void testEncode() { // No parent tag - assertArrayEquals(new Byte[] { + assertArrayEquals(new Byte[]{ 0x5, 0x0 }, new Null(Null.TAG, null).encodeDER()); // Custom tag - assertArrayEquals(new Byte[] { + assertArrayEquals(new Byte[]{ 0x72, 0x0 }, new Null(new Tag(TagClass.APPLICATION, true, 0x12), null) .encodeDER()); // With parent tag - assertArrayEquals(new Byte[] { + assertArrayEquals(new Byte[]{ -95, 2, 0x72, 0x0 }, new Null(new Tag(TagClass.APPLICATION, true, 0x12), -- cgit v1.2.3