aboutsummaryrefslogtreecommitdiff
path: root/src/test/model
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 05:35:17 +0800
committerYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 05:35:17 +0800
commit28fa18278c1f3a87722d5e8b78f581526a30bb38 (patch)
tree2f23f6e2e222a78f40809ec37e8b28a29cba3d3c /src/test/model
parent0bcc057e741af3fbc108f42b75f9d42f48f6a51e (diff)
downloadjca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar.gz
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar.bz2
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.zip
Fix lint
Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
Diffstat (limited to 'src/test/model')
-rw-r--r--src/test/model/TestConstants.java187
-rw-r--r--src/test/model/asn1/ASN1LengthTest.java39
-rw-r--r--src/test/model/asn1/ASN1ObjectTest.java67
-rw-r--r--src/test/model/asn1/BitStringTest.java42
-rw-r--r--src/test/model/asn1/BoolTest.java20
-rw-r--r--src/test/model/asn1/GeneralizedTimeTest.java14
-rw-r--r--src/test/model/asn1/IA5StringTest.java24
-rw-r--r--src/test/model/asn1/IntTest.java58
-rw-r--r--src/test/model/asn1/NullTest.java10
-rw-r--r--src/test/model/asn1/ObjectIdentifierTest.java60
-rw-r--r--src/test/model/asn1/OctetStringTest.java25
-rw-r--r--src/test/model/asn1/PrintableStringTest.java22
-rw-r--r--src/test/model/asn1/TagClassTest.java2
-rw-r--r--src/test/model/asn1/TagTest.java46
-rw-r--r--src/test/model/asn1/UTF8StringTest.java18
-rw-r--r--src/test/model/asn1/UtcTimeTest.java14
-rw-r--r--src/test/model/asn1/parsing/BytesReaderTest.java36
-rw-r--r--src/test/model/csr/AttributeTest.java2
-rw-r--r--src/test/model/csr/AttributesTest.java14
-rw-r--r--src/test/model/csr/CertificationRequestInfoTest.java54
-rw-r--r--src/test/model/csr/CertificationRequestTest.java46
-rw-r--r--src/test/model/csr/ValuesTest.java7
-rw-r--r--src/test/model/pki/AlgorithmIdentifierTest.java12
-rw-r--r--src/test/model/pki/SubjectPublicKeyInfoTest.java65
-rw-r--r--src/test/model/pki/cert/CertificateTest.java19
-rw-r--r--src/test/model/pki/cert/ExtensionTest.java42
-rw-r--r--src/test/model/pki/cert/TbsCertificateTest.java10
-rw-r--r--src/test/model/pki/cert/ValidityTest.java18
-rw-r--r--src/test/model/pki/crl/CertificateListContentTest.java13
-rw-r--r--src/test/model/pki/crl/CertificateListTest.java22
-rw-r--r--src/test/model/pki/crl/RevokedCertificateTest.java9
-rw-r--r--src/test/model/x501/AttributeTypeAndValueTest.java4
-rw-r--r--src/test/model/x501/NameTest.java2
-rw-r--r--src/test/model/x501/RelativeDistinguishedNameTest.java13
34 files changed, 503 insertions, 533 deletions
diff --git a/src/test/model/TestConstants.java b/src/test/model/TestConstants.java
index f0ba35a..04a3aa7 100644
--- a/src/test/model/TestConstants.java
+++ b/src/test/model/TestConstants.java
@@ -33,7 +33,6 @@ import static model.asn1.ASN1Object.TAG_SEQUENCE;
import static model.asn1.ASN1Object.TAG_SET;
import static model.asn1.ObjectIdentifier.OID_EXTENSION_REQUEST;
import static model.asn1.ObjectIdentifier.TAG;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public final class TestConstants {
@@ -76,7 +75,7 @@ public final class TestConstants {
public static final Attribute CSR_ATTR_1;
- public static final Byte[] CSR_ATTR_1_DER = new Byte[] {
+ public static final Byte[] CSR_ATTR_1_DER = new Byte[]{
0x30, 0x1C,
0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, -126, 0x37, 0x0D, 0x02, 0x03, 0x31, 0x0E, 0x16,
0x0C, 0x31, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x39, 0x30, 0x34, 0x35, 0x2E, 0x32
@@ -89,7 +88,7 @@ public final class TestConstants {
0x06, 0x4D, 0x69, 0x6C, 0x61, 0x6E, 0x6F
};
public static final RelativeDistinguishedName L_MILANO;
- public static final Byte[] CN_TEST_ED25519_DER = new Byte[] {
+ public static final Byte[] CN_TEST_ED25519_DER = new Byte[]{
0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C,
0x0C, 0x54, 0x65, 0x73, 0x74, 0x20, 0x65, 0x64,
0x32, 0x35, 0x35, 0x31, 0x39,
@@ -122,33 +121,33 @@ public final class TestConstants {
/**
* Certificate:
- * Data:
- * Version: 3 (0x2)
- * Serial Number:
- * 70:fa:0f:fa:a6:d7:f4:b4:93:05:5d:a9:d3:e4:42:a8:52:60:b3:f8
- * Signature Algorithm: ecdsa-with-SHA256
- * Issuer: CN = Yuuta Root CA, C = CA
- * Validity
- * Not Before: Jun 23 02:50:46 2023 GMT
- * Not After : Jun 23 02:50:46 2048 GMT
- * Subject: CN = Yuuta Root CA, C = CA
- * Subject Public Key Info:
- * Public Key Algorithm: id-ecPublicKey
- * Public-Key: (256 bit)
- * pub:
- * ASN1 OID: prime256v1
- * NIST CURVE: P-256
- * X509v3 extensions:
- * X509v3 Subject Key Identifier:
- * 78:92:E0:6C:70:F5:A3:BE:02:EE:44:BA:A7:8C:DA:D6:B5:43:A7:93
- * X509v3 Authority Key Identifier:
- * 78:92:E0:6C:70:F5:A3:BE:02:EE:44:BA:A7:8C:DA:D6:B5:43:A7:93
- * X509v3 Basic Constraints: critical
- * CA:TRUE
- * X509v3 Key Usage: critical
- * Digital Signature, Certificate Sign, CRL Sign
- * Signature Algorithm: ecdsa-with-SHA256
- * Signature Value:
+ * Data:
+ * Version: 3 (0x2)
+ * Serial Number:
+ * 70:fa:0f:fa:a6:d7:f4:b4:93:05:5d:a9:d3:e4:42:a8:52:60:b3:f8
+ * Signature Algorithm: ecdsa-with-SHA256
+ * Issuer: CN = Yuuta Root CA, C = CA
+ * Validity
+ * Not Before: Jun 23 02:50:46 2023 GMT
+ * Not After : Jun 23 02:50:46 2048 GMT
+ * Subject: CN = Yuuta Root CA, C = CA
+ * Subject Public Key Info:
+ * Public Key Algorithm: id-ecPublicKey
+ * Public-Key: (256 bit)
+ * pub:
+ * ASN1 OID: prime256v1
+ * NIST CURVE: P-256
+ * X509v3 extensions:
+ * X509v3 Subject Key Identifier:
+ * 78:92:E0:6C:70:F5:A3:BE:02:EE:44:BA:A7:8C:DA:D6:B5:43:A7:93
+ * X509v3 Authority Key Identifier:
+ * 78:92:E0:6C:70:F5:A3:BE:02:EE:44:BA:A7:8C:DA:D6:B5:43:A7:93
+ * X509v3 Basic Constraints: critical
+ * CA:TRUE
+ * X509v3 Key Usage: critical
+ * Digital Signature, Certificate Sign, CRL Sign
+ * Signature Algorithm: ecdsa-with-SHA256
+ * Signature Value:
*/
public static final String CERT_L1_ECC_PEM =
"-----BEGIN CERTIFICATE-----\n" +
@@ -165,37 +164,37 @@ public final class TestConstants {
"-----END CERTIFICATE-----";
/**
* Certificate:
- * Data:
- * Version: 3 (0x2)
- * Serial Number:
- * 3e:10:93:9d:e4:57:8d:39:87:fd:ff:42:7b:da:65:5b:1f:21:cb:07
- * Signature Algorithm: ecdsa-with-SHA512
- * Issuer: CN = Yuuta Root CA, C = CA
- * Validity
- * Not Before: Jun 24 00:15:22 2023 GMT
- * Not After : Jun 21 00:15:22 2033 GMT
- * Subject: DC = MOE, DC = YUUTA, DC = AD, CN = Yuuta Home Issuing CA
- * Subject Public Key Info:
- * Public Key Algorithm: rsaEncryption
- * Public-Key: (4096 bit)
- * Modulus:
- * Exponent: 65537 (0x10001)
- * X509v3 extensions:
- * X509v3 Subject Key Identifier:
- * B1:C2:A7:81:63:66:4B:72:0A:DD:FD:7D:20:29:BD:6B:49:09:61:C0
- * X509v3 Authority Key Identifier:
- * 78:92:E0:6C:70:F5:A3:BE:02:EE:44:BA:A7:8C:DA:D6:B5:43:A7:93
- * X509v3 Basic Constraints: critical
- * CA:TRUE, pathlen:0
- * X509v3 Key Usage: critical
- * Digital Signature, Certificate Sign, CRL Sign
- * X509v3 CRL Distribution Points:
- * Full Name:
- * URI:http://home.yuuta.moe/pki/rootca.crl
- * Authority Information Access:
- * CA Issuers - URI:http://home.yuuta.moe/pki/rootca.crt
- * Signature Algorithm: ecdsa-with-SHA512
- * Signature Value:
+ * Data:
+ * Version: 3 (0x2)
+ * Serial Number:
+ * 3e:10:93:9d:e4:57:8d:39:87:fd:ff:42:7b:da:65:5b:1f:21:cb:07
+ * Signature Algorithm: ecdsa-with-SHA512
+ * Issuer: CN = Yuuta Root CA, C = CA
+ * Validity
+ * Not Before: Jun 24 00:15:22 2023 GMT
+ * Not After : Jun 21 00:15:22 2033 GMT
+ * Subject: DC = MOE, DC = YUUTA, DC = AD, CN = Yuuta Home Issuing CA
+ * Subject Public Key Info:
+ * Public Key Algorithm: rsaEncryption
+ * Public-Key: (4096 bit)
+ * Modulus:
+ * Exponent: 65537 (0x10001)
+ * X509v3 extensions:
+ * X509v3 Subject Key Identifier:
+ * B1:C2:A7:81:63:66:4B:72:0A:DD:FD:7D:20:29:BD:6B:49:09:61:C0
+ * X509v3 Authority Key Identifier:
+ * 78:92:E0:6C:70:F5:A3:BE:02:EE:44:BA:A7:8C:DA:D6:B5:43:A7:93
+ * X509v3 Basic Constraints: critical
+ * CA:TRUE, pathlen:0
+ * X509v3 Key Usage: critical
+ * Digital Signature, Certificate Sign, CRL Sign
+ * X509v3 CRL Distribution Points:
+ * Full Name:
+ * URI:http://home.yuuta.moe/pki/rootca.crl
+ * Authority Information Access:
+ * CA Issuers - URI:http://home.yuuta.moe/pki/rootca.crt
+ * Signature Algorithm: ecdsa-with-SHA512
+ * Signature Value:
*/
public static final String CERT_L2_RSA_PEM =
"-----BEGIN CERTIFICATE-----\n" +
@@ -226,22 +225,22 @@ public final class TestConstants {
/**
* Certificate:
- * Data:
- * Version: 1 (0x0)
- * Serial Number: 3580 (0xdfc)
- * Signature Algorithm: sha1WithRSAEncryption
- * Issuer: C = JP, ST = Tokyo, L = Chuo-ku, O = Frank4DD, OU = WebCert Support, CN = Frank4DD Web CA, emailAddress = support@frank4dd.com
- * Validity
- * Not Before: Aug 22 05:27:41 2012 GMT
- * Not After : Aug 21 05:27:41 2017 GMT
- * Subject: C = JP, ST = Tokyo, O = Frank4DD, CN = www.example.com
- * Subject Public Key Info:
- * Public Key Algorithm: rsaEncryption
- * Public-Key: (2048 bit)
- * Modulus:
- * Exponent: 65537 (0x10001)
- * Signature Algorithm: sha1WithRSAEncryption
- * Signature Value:
+ * Data:
+ * Version: 1 (0x0)
+ * Serial Number: 3580 (0xdfc)
+ * Signature Algorithm: sha1WithRSAEncryption
+ * Issuer: C = JP, ST = Tokyo, L = Chuo-ku, O = Frank4DD, OU = WebCert Support, CN = Frank4DD Web CA, emailAddress = support@frank4dd.com
+ * Validity
+ * Not Before: Aug 22 05:27:41 2012 GMT
+ * Not After : Aug 21 05:27:41 2017 GMT
+ * Subject: C = JP, ST = Tokyo, O = Frank4DD, CN = www.example.com
+ * Subject Public Key Info:
+ * Public Key Algorithm: rsaEncryption
+ * Public-Key: (2048 bit)
+ * Modulus:
+ * Exponent: 65537 (0x10001)
+ * Signature Algorithm: sha1WithRSAEncryption
+ * Signature Value:
*/
public static final String CERT_V1_PEM =
"-----BEGIN CERTIFICATE-----\n" +
@@ -310,13 +309,13 @@ public final class TestConstants {
});
CSR_ATTR_2 = new Attribute(
- ASN1Object.TAG_SEQUENCE, null,
- new ObjectIdentifier(ObjectIdentifier.TAG, null, OID_EXTENSION_REQUEST),
+ ASN1Object.TAG_SEQUENCE, null,
+ new ObjectIdentifier(ObjectIdentifier.TAG, null, OID_EXTENSION_REQUEST),
CSR_ATTR_VALUES_2);
CSR_ATTR_1 = new Attribute(
TAG_SEQUENCE, null,
- new ObjectIdentifier(TAG, null, new Integer[]{ 1, 3, 6, 1, 4, 1, 311, 13, 2, 3 }),
+ new ObjectIdentifier(TAG, null, new Integer[]{1, 3, 6, 1, 4, 1, 311, 13, 2, 3}),
new Values(TAG_SET, null, new ASN1Object[]{
new IA5String(IA5String.TAG, null, "10.0.19045.2")
})
@@ -432,7 +431,7 @@ public final class TestConstants {
ObjectIdentifier.OID_EC_PUBLIC_KEY),
new ObjectIdentifier(ObjectIdentifier.TAG, null,
ObjectIdentifier.OID_PRIME256_V1)),
- new BitString(BitString.TAG, null, 0, new Byte[]{ 1, 2, 3 })),
+ new BitString(BitString.TAG, null, 0, new Byte[]{1, 2, 3})),
new Extensions(ASN1Object.TAG_SEQUENCE,
new Tag(TagClass.CONTEXT_SPECIFIC, false, 3),
new Extension[]{
@@ -441,13 +440,13 @@ public final class TestConstants {
ObjectIdentifier.OID_BASIC_CONSTRAINTS),
new Bool(Bool.TAG, null, true),
new OctetString(OctetString.TAG, null,
- new Byte[]{ 0x30, 0x06, 0x01, 0x01, -1, 0x02, 0x01, 0x00 })),
+ new Byte[]{0x30, 0x06, 0x01, 0x01, -1, 0x02, 0x01, 0x00})),
new Extension(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null,
ObjectIdentifier.OID_KEY_USAGE),
new Bool(Bool.TAG, null, true),
new OctetString(OctetString.TAG, null,
- new Byte[]{ 0x03, 0x02, 0x01, -122 }))
+ new Byte[]{0x03, 0x02, 0x01, -122}))
}));
REVOKED_CESSATION =
@@ -461,15 +460,15 @@ public final class TestConstants {
new UtcTime(UtcTime.TAG, null, ZonedDateTime.now(ZoneId.of("UTC"))),
Reason.KEY_COMPROMISE);
REVOKED_CESSATION_DER = combine((byte) 0x30,
- REVOKED_CESSATION.getSerialNumber().encodeDER(),
- REVOKED_CESSATION.getRevocationDate().encodeDER(),
+ REVOKED_CESSATION.getSerialNumber().encodeDER(),
+ REVOKED_CESSATION.getRevocationDate().encodeDER(),
+ combine((byte) 0x30,
combine((byte) 0x30,
- combine((byte) 0x30,
- new ObjectIdentifier(ObjectIdentifier.TAG, null,
- ObjectIdentifier.OID_CRL_REASON).encodeDER(),
- new OctetString(OctetString.TAG, null,
- new Byte[]{ 0x0A, 0x01, (byte) Reason.CESSATION_OF_OPERATION.getVal() })
- .encodeDER())));
+ new ObjectIdentifier(ObjectIdentifier.TAG, null,
+ ObjectIdentifier.OID_CRL_REASON).encodeDER(),
+ new OctetString(OctetString.TAG, null,
+ new Byte[]{0x0A, 0x01, (byte) Reason.CESSATION_OF_OPERATION.getVal()})
+ .encodeDER())));
REVOKED_KEY_COMPROMISE_DER = combine((byte) 0x30,
REVOKED_KEY_COMPROMISE.getSerialNumber().encodeDER(),
REVOKED_KEY_COMPROMISE.getRevocationDate().encodeDER(),
@@ -478,7 +477,7 @@ public final class TestConstants {
new ObjectIdentifier(ObjectIdentifier.TAG, null,
ObjectIdentifier.OID_CRL_REASON).encodeDER(),
new OctetString(OctetString.TAG, null,
- new Byte[]{ 0x0A, 0x01, (byte) Reason.KEY_COMPROMISE.getVal() })
+ new Byte[]{0x0A, 0x01, (byte) Reason.KEY_COMPROMISE.getVal()})
.encodeDER())));
CRL_CONTENT_1 =
new CertificateListContent(ASN1Object.TAG_SEQUENCE, null,
@@ -536,8 +535,8 @@ public final class TestConstants {
public static Byte[] combine(Byte tag, Byte[]... vals) {
return Stream.of(Collections.singletonList(tag),
- Arrays.asList(new ASN1Length(Arrays.stream(vals).mapToInt(b -> b.length).sum()).encodeDER()),
- Arrays.stream(vals).flatMap(Arrays::stream).collect(Collectors.toList()))
+ Arrays.asList(new ASN1Length(Arrays.stream(vals).mapToInt(b -> b.length).sum()).encodeDER()),
+ Arrays.stream(vals).flatMap(Arrays::stream).collect(Collectors.toList()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/test/model/asn1/ASN1LengthTest.java b/src/test/model/asn1/ASN1LengthTest.java
index 44aed8e..55da5ec 100644
--- a/src/test/model/asn1/ASN1LengthTest.java
+++ b/src/test/model/asn1/ASN1LengthTest.java
@@ -2,7 +2,6 @@ package model.asn1;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.asn1.parsing.BytesReaderTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@@ -16,31 +15,31 @@ public class ASN1LengthTest {
@Test
void testParse() throws Exception { // TODO: Exception
- BytesReader reader = new BytesReader(new Byte[]{ 0x0 });
+ BytesReader reader = new BytesReader(new Byte[]{0x0});
assertEquals(0, new ASN1Length(reader).getLength());
assertEquals(1, reader.getIndex());
- reader = new BytesReader(new Byte[]{ 0x20 });
+ reader = new BytesReader(new Byte[]{0x20});
assertEquals(0x20, new ASN1Length(reader).getLength());
assertEquals(1, reader.getIndex());
- reader = new BytesReader(new Byte[]{ -127, 0x30 });
+ reader = new BytesReader(new Byte[]{-127, 0x30});
assertEquals(0x30, new ASN1Length(reader).getLength());
assertEquals(2, reader.getIndex());
- reader = new BytesReader(new Byte[]{ -126, -22, 0x60 });
+ reader = new BytesReader(new Byte[]{-126, -22, 0x60});
assertEquals(60000, new ASN1Length(reader).getLength());
assertEquals(3, reader.getIndex());
- reader = new BytesReader(new Byte[]{ -127, 127 });
+ reader = new BytesReader(new Byte[]{-127, 127});
assertEquals(127, new ASN1Length(reader).getLength());
assertEquals(2, reader.getIndex());
- reader = new BytesReader(new Byte[]{ -124, 1, 1, 1, 1 });
+ reader = new BytesReader(new Byte[]{-124, 1, 1, 1, 1});
assertEquals(16843009, new ASN1Length(reader).getLength());
assertEquals(5, reader.getIndex());
- reader = new BytesReader(new Byte[]{ -127, -97 });
+ reader = new BytesReader(new Byte[]{-127, -97});
assertEquals(159, new ASN1Length(reader).getLength());
assertEquals(2, reader.getIndex());
}
@@ -49,46 +48,46 @@ public class ASN1LengthTest {
void testParseFail() throws ParseException {
// First byte 0b10000000
assertThrows(ParseException.class, () ->
- new ASN1Length(new BytesReader(new Byte[]{ -128 }))
+ new ASN1Length(new BytesReader(new Byte[]{-128}))
);
// First byte 0b11111111
assertThrows(ParseException.class, () ->
- new ASN1Length(new BytesReader(new Byte[]{ -1 }))
+ new ASN1Length(new BytesReader(new Byte[]{-1}))
);
// Multibyte, requested 2 bytes but have none.
assertThrows(ParseException.class, () ->
- new ASN1Length(new BytesReader(new Byte[]{ -126 }))
+ new ASN1Length(new BytesReader(new Byte[]{-126}))
);
// Multibyte, requested 2 bytes but have one.
assertThrows(ParseException.class, () ->
- new ASN1Length(new BytesReader(new Byte[]{ -126, 0x1 }))
+ new ASN1Length(new BytesReader(new Byte[]{-126, 0x1}))
);
// But this one should work (0b01111111)
- new ASN1Length(new BytesReader(new Byte[]{ -127, 127 }));
+ new ASN1Length(new BytesReader(new Byte[]{-127, 127}));
// Multibyte, too long.
assertThrows(ParseException.class, () ->
- new ASN1Length(new BytesReader(new Byte[]{ -124, -1, -1, -1, -1 }))
+ new ASN1Length(new BytesReader(new Byte[]{-124, -1, -1, -1, -1}))
);
// But this one should work, except for it is too large
- new ASN1Length(new BytesReader(new Byte[]{ -125, -1, -1, -1 }));
+ new ASN1Length(new BytesReader(new Byte[]{-125, -1, -1, -1}));
}
@Test
void testEncode() {
// Short form
- assertArrayEquals(new Byte[]{ 0x0 }, new ASN1Length(0).encodeDER());
- assertArrayEquals(new Byte[]{ 0x1 }, new ASN1Length(1).encodeDER());
- assertArrayEquals(new Byte[]{ 127 }, new ASN1Length(127).encodeDER());
+ assertArrayEquals(new Byte[]{0x0}, new ASN1Length(0).encodeDER());
+ assertArrayEquals(new Byte[]{0x1}, new ASN1Length(1).encodeDER());
+ assertArrayEquals(new Byte[]{127}, new ASN1Length(127).encodeDER());
// Long form
// 0b10000001, 0b10000000
- assertArrayEquals(new Byte[]{ -127, -128 }, new ASN1Length(128).encodeDER());
+ assertArrayEquals(new Byte[]{-127, -128}, new ASN1Length(128).encodeDER());
// 0b10000010, 0b11111111, 0b11111111
- assertArrayEquals(new Byte[]{ -126, -1, -1 }, new ASN1Length(65535).encodeDER());
+ assertArrayEquals(new Byte[]{-126, -1, -1}, new ASN1Length(65535).encodeDER());
}
}
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),
diff --git a/src/test/model/asn1/BitStringTest.java b/src/test/model/asn1/BitStringTest.java
index c893b36..b2472fd 100644
--- a/src/test/model/asn1/BitStringTest.java
+++ b/src/test/model/asn1/BitStringTest.java
@@ -9,11 +9,11 @@ import static org.junit.jupiter.api.Assertions.*;
public class BitStringTest {
@Test
void testConstructor() {
- assertArrayEquals(new Byte[]{ 0x2, 0x3 },
- new BitString(BitString.TAG, null, 0, new Byte[]{ 0x2, 0x3 })
+ assertArrayEquals(new Byte[]{0x2, 0x3},
+ new BitString(BitString.TAG, null, 0, new Byte[]{0x2, 0x3})
.getVal());
assertEquals(3,
- new BitString(BitString.TAG, null, 3, new Byte[]{ 0x2, 0x8 })
+ new BitString(BitString.TAG, null, 3, new Byte[]{0x2, 0x8})
.getUnused());
}
@@ -21,55 +21,55 @@ public class BitStringTest {
void testConvert() {
// 00000010 00001000
// 00000000 01000001 = 65
- assertArrayEquals(new Byte[]{ 65 },
- new BitString(BitString.TAG, null, 3, new Byte[]{ 0x2, 0x8 })
+ assertArrayEquals(new Byte[]{65},
+ new BitString(BitString.TAG, null, 3, new Byte[]{0x2, 0x8})
.getConvertedVal());
- assertArrayEquals(new Byte[]{ 0x2, 0x8 },
- new BitString(BitString.TAG, null, 0, new Byte[]{ 0x2, 0x8 })
+ assertArrayEquals(new Byte[]{0x2, 0x8},
+ new BitString(BitString.TAG, null, 0, new Byte[]{0x2, 0x8})
.getConvertedVal());
}
@Test
void testParse() throws ParseException {
- assertArrayEquals(new Byte[]{ 0x6e, 0x5d, -64 },
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x06, 0x6e, 0x5d, -64 }), false)
+ assertArrayEquals(new Byte[]{0x6e, 0x5d, -64},
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x06, 0x6e, 0x5d, -64}), false)
.getVal());
assertEquals(6,
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x06, 0x6e, 0x5d, -64 }), false)
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x06, 0x6e, 0x5d, -64}), false)
.getUnused());
- assertArrayEquals(new Byte[]{ 0x01, -71, 0x77 },
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x06, 0x6e, 0x5d, -64 }), false)
+ assertArrayEquals(new Byte[]{0x01, -71, 0x77},
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x06, 0x6e, 0x5d, -64}), false)
.getConvertedVal());
}
@Test
void testParseFail() {
assertThrows(ParseException.class, () ->
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04 }), false));
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04}), false));
// 0b11100000
assertThrows(ParseException.class, () ->
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x06, 0x6e, 0x5d, -32 }), false));
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x06, 0x6e, 0x5d, -32}), false));
// 0b11000001
assertThrows(ParseException.class, () ->
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x06, 0x6e, 0x5d, -63 }), false));
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x06, 0x6e, 0x5d, -63}), false));
// Unused bits = 8
assertThrows(ParseException.class, () ->
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x08, 0x6e, 0x5d, -64 }), false));
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x08, 0x6e, 0x5d, -64}), false));
// Unused bits = 6 -> 7
assertThrows(ParseException.class, () ->
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x07, 0x6e, 0x5d, -64 }), false));
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x07, 0x6e, 0x5d, -64}), false));
// Illegal unused bits: 8 and -1
assertThrows(ParseException.class, () ->
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x08, 0x6e, 0x5d, -64 }), false));
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x08, 0x6e, 0x5d, -64}), false));
assertThrows(ParseException.class, () ->
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, -1, 0x6e, 0x5d, -64 }), false));
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, -1, 0x6e, 0x5d, -64}), false));
}
@Test
void testEncode() throws ParseException {
- assertArrayEquals(new Byte[]{ 0x03, 0x04, 0x06, 0x6e, 0x5d, -64 },
- new BitString(new BytesReader(new Byte[]{ 0x03, 0x04, 0x06, 0x6e, 0x5d, -64 }), false)
+ assertArrayEquals(new Byte[]{0x03, 0x04, 0x06, 0x6e, 0x5d, -64},
+ new BitString(new BytesReader(new Byte[]{0x03, 0x04, 0x06, 0x6e, 0x5d, -64}), false)
.encodeDER());
}
}
diff --git a/src/test/model/asn1/BoolTest.java b/src/test/model/asn1/BoolTest.java
index fed3152..cff1a3e 100644
--- a/src/test/model/asn1/BoolTest.java
+++ b/src/test/model/asn1/BoolTest.java
@@ -15,31 +15,31 @@ public class BoolTest {
@Test
void testParse() throws ParseException {
- assertFalse(new Bool(new BytesReader(new Byte[]{ 0x1, 1, 0 }), false)
- .getValue());
- assertTrue(new Bool(new BytesReader(new Byte[]{ 0x1, 1, -1 }), false)
+ assertFalse(new Bool(new BytesReader(new Byte[]{0x1, 1, 0}), false)
+ .getValue());
+ assertTrue(new Bool(new BytesReader(new Byte[]{0x1, 1, -1}), false)
.getValue());
}
@Test
void testParseFail() throws ParseException {
assertThrows(ParseException.class, () ->
- new Bool(new BytesReader(new Byte[]{ 0x1, 0 }), false));
+ new Bool(new BytesReader(new Byte[]{0x1, 0}), false));
assertThrows(ParseException.class, () ->
- new Bool(new BytesReader(new Byte[]{ 0x1, 1 }), false));
+ new Bool(new BytesReader(new Byte[]{0x1, 1}), false));
assertThrows(ParseException.class, () ->
- new Bool(new BytesReader(new Byte[]{ 0x1, 1, 1 }), false));
+ new Bool(new BytesReader(new Byte[]{0x1, 1, 1}), false));
assertThrows(ParseException.class, () ->
- new Bool(new BytesReader(new Byte[]{ 0x1, 1, -2 }), false));
+ new Bool(new BytesReader(new Byte[]{0x1, 1, -2}), false));
assertThrows(ParseException.class, () ->
- new Bool(new BytesReader(new Byte[]{ 0x1, 2, -1, 2 }), false));
+ new Bool(new BytesReader(new Byte[]{0x1, 2, -1, 2}), false));
}
@Test
void testEncode() {
- assertArrayEquals(new Byte[]{ 0 },
+ assertArrayEquals(new Byte[]{0},
new Bool(Bool.TAG, null, false).encodeValueDER());
- assertArrayEquals(new Byte[]{ -1 },
+ assertArrayEquals(new Byte[]{-1},
new Bool(Bool.TAG, null, true).encodeValueDER());
}
}
diff --git a/src/test/model/asn1/GeneralizedTimeTest.java b/src/test/model/asn1/GeneralizedTimeTest.java
index 4660de7..4ca5b72 100644
--- a/src/test/model/asn1/GeneralizedTimeTest.java
+++ b/src/test/model/asn1/GeneralizedTimeTest.java
@@ -14,20 +14,20 @@ public class GeneralizedTimeTest {
void testConstructor() throws ParseException {
final ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
assertEquals(now, new GeneralizedTime(GeneralizedTime.TAG, null, now).getTimestamp());
- final ASN1Time parsed = new GeneralizedTime(new BytesReader(new Byte[] {
+ final ASN1Time parsed = new GeneralizedTime(new BytesReader(new Byte[]{
0x18, 15,
'1', '9', '1', '9', '0', '8', '1', '0', '1', '1', '4', '5', '1', '4', 'Z'
}), false);
assertEquals("19190810114514Z",
parsed.toString());
assertEquals(ZonedDateTime.of(1919, 8, 10, 11, 45, 14,
- 0, ZoneId.of("UTC")),
+ 0, ZoneId.of("UTC")),
parsed.getTimestamp());
}
@Test
void testParse() throws ParseException {
- ASN1Time parsed = new GeneralizedTime(new BytesReader(new Byte[] {
+ ASN1Time parsed = new GeneralizedTime(new BytesReader(new Byte[]{
0x18, 15,
'2', '0', '2', '3', '0', '9', '2', '7', '1', '1', '4', '5', '1', '4', 'Z'
}), false);
@@ -36,7 +36,7 @@ public class GeneralizedTimeTest {
parsed.getTimestamp());
// No seconds
- parsed = new GeneralizedTime(new BytesReader(new Byte[] {
+ parsed = new GeneralizedTime(new BytesReader(new Byte[]{
0x18, 13,
'2', '0', '2', '3', '0', '9', '2', '7', '1', '1', '4', '5', 'Z'
}), false);
@@ -96,20 +96,20 @@ public class GeneralizedTimeTest {
@Test
void testEncode() throws ParseException {
- assertEquals("20230927114514Z", new GeneralizedTime(new BytesReader(new Byte[] {
+ assertEquals("20230927114514Z", new GeneralizedTime(new BytesReader(new Byte[]{
-95, 17,
0x18, 15,
'2', '0', '2', '3', '0', '9', '2', '7', '1', '1', '4', '5', '1', '4', 'Z'
}), true).toString());
// No seconds
- assertEquals("202309271145Z", new GeneralizedTime(new BytesReader(new Byte[] {
+ assertEquals("202309271145Z", new GeneralizedTime(new BytesReader(new Byte[]{
-95, 15,
0x18, 13,
'2', '0', '2', '3', '0', '9', '2', '7', '1', '1', '4', '5', 'Z'
}), true).toString());
// To byte array
- assertArrayEquals(new Byte[] {
+ assertArrayEquals(new Byte[]{
0x18, 13,
'2', '0', '2', '3', '0', '9', '2', '7', '1', '1', '4', '5', 'Z'
}, new GeneralizedTime(GeneralizedTime.TAG, null, ZonedDateTime.of(2023, 9,
diff --git a/src/test/model/asn1/IA5StringTest.java b/src/test/model/asn1/IA5StringTest.java
index dfaa1aa..8bec6c4 100644
--- a/src/test/model/asn1/IA5StringTest.java
+++ b/src/test/model/asn1/IA5StringTest.java
@@ -32,25 +32,25 @@ public class IA5StringTest {
void testIllegalStrings() {
assertThrows(ParseException.class,
() -> new IA5String(IA5String.TAG, null,
- stringToTest + new String(new byte[]{ -128 }, StandardCharsets.UTF_8)));
+ stringToTest + new String(new byte[]{-128}, StandardCharsets.UTF_8)));
assertThrows(ParseException.class,
() -> new IA5String(IA5String.TAG, null,
- stringToTest + new String(new byte[]{ -1 }, StandardCharsets.UTF_8)));
+ stringToTest + new String(new byte[]{-1}, StandardCharsets.UTF_8)));
}
@Test
void testEncode() throws ParseException {
assertArrayEquals(
- new Byte[] { 0x00, 0x01, 0x02 },
- new IA5String(IA5String.TAG, null, new String(new byte[]{ 0, 1, 2}, StandardCharsets.UTF_8))
+ new Byte[]{0x00, 0x01, 0x02},
+ new IA5String(IA5String.TAG, null, new String(new byte[]{0, 1, 2}, StandardCharsets.UTF_8))
.encodeValueDER());
assertArrayEquals(
- new Byte[] {
+ new Byte[]{
0x16, 0x02, // Tag - Length
0x68, 0x69 // Value
}, new IA5String(IA5String.TAG, null, "hi").encodeDER());
assertArrayEquals(
- new Byte[] {
+ new Byte[]{
-85, 0x05, // Parent Tag - Length
0x16, 0x03, // Inner Tag - Length
0x68, 0x69, 0x69 // Value
@@ -62,18 +62,18 @@ public class IA5StringTest {
@Test
void testParse() throws ParseException {
assertEquals("123",
- new IA5String(new BytesReader(new Byte[]{ 0x16, 3, '1', '2', '3' }), false)
+ new IA5String(new BytesReader(new Byte[]{0x16, 3, '1', '2', '3'}), false)
.getString());
assertEquals("",
- new IA5String(new BytesReader(new Byte[]{ 0x16, 0 }), false)
+ new IA5String(new BytesReader(new Byte[]{0x16, 0}), false)
.getString());
}
@Test
void testParseFail() {
- assertThrows(ParseException.class, () ->
- new IA5String(new BytesReader(new Byte[]{ 0x16, 3, '1', '2' }), false));
- assertThrows(ParseException.class, () ->
- new IA5String(new BytesReader(new Byte[]{ 0x16, 2, '1', -128 }), false));
+ assertThrows(ParseException.class, () ->
+ new IA5String(new BytesReader(new Byte[]{0x16, 3, '1', '2'}), false));
+ assertThrows(ParseException.class, () ->
+ new IA5String(new BytesReader(new Byte[]{0x16, 2, '1', -128}), false));
}
}
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));
}
}
diff --git a/src/test/model/asn1/NullTest.java b/src/test/model/asn1/NullTest.java
index 4ec2c64..a6512d8 100644
--- a/src/test/model/asn1/NullTest.java
+++ b/src/test/model/asn1/NullTest.java
@@ -17,22 +17,22 @@ public class NullTest {
@Test
void testEncode() {
assertEquals(0, new Null(Null.TAG, null).encodeValueDER().length);
- assertArrayEquals(new Byte[] {
+ assertArrayEquals(new Byte[]{
0x5, 0x0 // Tag - Length
}, new Null(Null.TAG, null).encodeDER());
}
@Test
void testParse() throws ParseException {
- new Null(new BytesReader(new Byte[]{ 0x5, 0x0 }), false);
- new Null(new BytesReader(new Byte[]{ -95, 2, 0x5, 0x0 }), true);
+ new Null(new BytesReader(new Byte[]{0x5, 0x0}), false);
+ new Null(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true);
}
@Test
void testParseFail() {
assertThrows(ParseException.class, () ->
- new Null(new BytesReader(new Byte[]{ 0x5, 0x2 }), false));
+ new Null(new BytesReader(new Byte[]{0x5, 0x2}), false));
assertThrows(ParseException.class, () ->
- new Null(new BytesReader(new Byte[]{ 0x5, 0x2, 1, 1 }), false));
+ new Null(new BytesReader(new Byte[]{0x5, 0x2, 1, 1}), false));
}
}
diff --git a/src/test/model/asn1/ObjectIdentifierTest.java b/src/test/model/asn1/ObjectIdentifierTest.java
index f6f1049..367e349 100644
--- a/src/test/model/asn1/ObjectIdentifierTest.java
+++ b/src/test/model/asn1/ObjectIdentifierTest.java
@@ -9,18 +9,18 @@ import static org.junit.jupiter.api.Assertions.*;
public class ObjectIdentifierTest {
@Test
void testConstructor() {
- assertArrayEquals(new Integer[]{ 1, 3, 6, 1, 4},
- new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{ 1, 3, 6, 1, 4 }).getInts());
- assertArrayEquals(new Integer[]{ 1, 2, 3, 4, 5},
- new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{ 1, 2, 3, 4, 5 }).getInts());
+ assertArrayEquals(new Integer[]{1, 3, 6, 1, 4},
+ new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{1, 3, 6, 1, 4}).getInts());
+ assertArrayEquals(new Integer[]{1, 2, 3, 4, 5},
+ new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{1, 2, 3, 4, 5}).getInts());
}
@Test
void testToString() {
assertEquals("1.3.6.1.4",
- new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{ 1, 3, 6, 1, 4 }).toString());
+ new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{1, 3, 6, 1, 4}).toString());
assertEquals("1.2.3.4.5.6",
- new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{ 1, 2, 3, 4, 5, 6 }).toString());
+ new ObjectIdentifier(ObjectIdentifier.TAG, null, new Integer[]{1, 2, 3, 4, 5, 6}).toString());
assertEquals("CN",
new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_CN).toString());
assertEquals("SN",
@@ -39,18 +39,18 @@ public class ObjectIdentifierTest {
@Test
void testEncode() {
- assertArrayEquals(new Byte[]{ 0x55, 0x04, 0x0A },
+ assertArrayEquals(new Byte[]{0x55, 0x04, 0x0A},
new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_O).encodeValueDER());
- assertArrayEquals(new Byte[]{ 0x67, -127, 0x0C, 0x01, 0x02, 0x01 },
+ assertArrayEquals(new Byte[]{0x67, -127, 0x0C, 0x01, 0x02, 0x01},
new ObjectIdentifier(ObjectIdentifier.TAG, null,
- new Integer[]{ 2, 23, 140, 1, 2, 1 }).encodeValueDER());
- assertArrayEquals(new Byte[]{ 0x2B, 0x06, 0x01, 0x04, 0x01, -126, -33, 0x13, 0x01, 0x01, 0x01 },
+ new Integer[]{2, 23, 140, 1, 2, 1}).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x2B, 0x06, 0x01, 0x04, 0x01, -126, -33, 0x13, 0x01, 0x01, 0x01},
new ObjectIdentifier(ObjectIdentifier.TAG, null,
- new Integer[]{ 1, 3, 6, 1, 4, 1, 44947, 1, 1, 1 }).encodeValueDER());
- assertArrayEquals(new Byte[]{ 0x2A, -122, 0x48, -50, 0x3D, 0x02, 0x01 },
+ new Integer[]{1, 3, 6, 1, 4, 1, 44947, 1, 1, 1}).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x2A, -122, 0x48, -50, 0x3D, 0x02, 0x01},
new ObjectIdentifier(ObjectIdentifier.TAG, null,
- new Integer[]{ 1, 2, 840, 10045, 2, 1 }).encodeValueDER());
- assertArrayEquals(new Byte[]{ 0x2A, -122, 0x48, -122, -9, 0x0D, 0x01, 0x01, 0x0B },
+ new Integer[]{1, 2, 840, 10045, 2, 1}).encodeValueDER());
+ assertArrayEquals(new Byte[]{0x2A, -122, 0x48, -122, -9, 0x0D, 0x01, 0x01, 0x0B},
new ObjectIdentifier(ObjectIdentifier.TAG, null,
ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION).encodeValueDER());
@@ -59,31 +59,31 @@ public class ObjectIdentifierTest {
@Test
void testParse() throws ParseException {
assertArrayEquals(ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION,
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x6, 0x9, 0x2A, -122, 0x48, -122, -9, 0x0D,
- 0x01, 0x01, 0x0B }),false).getInts());
- assertArrayEquals(new Integer[]{ 1, 2, 840, 10045, 2, 1 },
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x6, 7, 0x2A, -122, 0x48, -50, 0x3D, 0x02, 0x01 }),
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x6, 0x9, 0x2A, -122, 0x48, -122, -9, 0x0D,
+ 0x01, 0x01, 0x0B}), false).getInts());
+ assertArrayEquals(new Integer[]{1, 2, 840, 10045, 2, 1},
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x6, 7, 0x2A, -122, 0x48, -50, 0x3D, 0x02, 0x01}),
false).getInts());
- assertArrayEquals(new Integer[]{ 0, 2, 840, 10045, 2, 1 },
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x6, 7, 2, -122, 0x48, -50, 0x3D, 0x02, 0x01 }),
+ assertArrayEquals(new Integer[]{0, 2, 840, 10045, 2, 1},
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x6, 7, 2, -122, 0x48, -50, 0x3D, 0x02, 0x01}),
false).getInts());
- assertArrayEquals(new Integer[]{ 2, 2, 840, 10045, 2, 1 },
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x6, 7, 82, -122, 0x48, -50, 0x3D, 0x02, 0x01 }),
+ assertArrayEquals(new Integer[]{2, 2, 840, 10045, 2, 1},
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x6, 7, 82, -122, 0x48, -50, 0x3D, 0x02, 0x01}),
false).getInts());
- assertArrayEquals(new Integer[]{ 2, 42, 840, 10045, 2, 1 },
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x6, 7, 122, -122, 0x48, -50, 0x3D, 0x02, 0x01 }),
+ assertArrayEquals(new Integer[]{2, 42, 840, 10045, 2, 1},
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x6, 7, 122, -122, 0x48, -50, 0x3D, 0x02, 0x01}),
false).getInts());
- assertArrayEquals(new Integer[]{ 1, 2, 840, 113549, 1, 9, 14 },
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x06, 0x09, 0x2A, -122, 0x48, -122, -9, 0x0D, 0x01,
- 0x09, 0x0E }), false).getInts());
+ assertArrayEquals(new Integer[]{1, 2, 840, 113549, 1, 9, 14},
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x06, 0x09, 0x2A, -122, 0x48, -122, -9, 0x0D, 0x01,
+ 0x09, 0x0E}), false).getInts());
}
@Test
void testParseFail() {
assertThrows(ParseException.class, () ->
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x6, 0x0 }), false));
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x6, 0x0}), false));
assertThrows(ParseException.class, () ->
- new ObjectIdentifier(new BytesReader(new Byte[]{ 0x6, 0x9, 0x2A, -122, 0x48, -122, -9, 0x0D,
- 0x01, 0x01, -117 }), false));
+ new ObjectIdentifier(new BytesReader(new Byte[]{0x6, 0x9, 0x2A, -122, 0x48, -122, -9, 0x0D,
+ 0x01, 0x01, -117}), false));
}
}
diff --git a/src/test/model/asn1/OctetStringTest.java b/src/test/model/asn1/OctetStringTest.java
index 9e6e8a9..91825e9 100644
--- a/src/test/model/asn1/OctetStringTest.java
+++ b/src/test/model/asn1/OctetStringTest.java
@@ -2,36 +2,33 @@ package model.asn1;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class OctetStringTest {
@Test
void testConstructor() {
- assertArrayEquals(new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
- new OctetString(OctetString.TAG, null, new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 })
+ assertArrayEquals(new Byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
+ new OctetString(OctetString.TAG, null, new Byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05})
.getBytes());
- assertArrayEquals(new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
- new OctetString(OctetString.TAG, null, new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 })
+ assertArrayEquals(new Byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
+ new OctetString(OctetString.TAG, null, new Byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05})
.encodeValueDER());
}
@Test
void testEncode() throws ParseException {
- assertArrayEquals(new Byte[]{ 0x04, 0x06, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
- new OctetString(OctetString.TAG, null, new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 })
+ assertArrayEquals(new Byte[]{0x04, 0x06, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
+ new OctetString(OctetString.TAG, null, new Byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05})
.encodeDER());
}
@Test
void testParse() throws ParseException {
- assertArrayEquals(new Byte[]{ 0x0A, 0x0B, 0x0C },
- new OctetString(new BytesReader(new Byte[]{ 0x4, 3, 0x0A, 0x0B, 0x0C }), false)
+ assertArrayEquals(new Byte[]{0x0A, 0x0B, 0x0C},
+ new OctetString(new BytesReader(new Byte[]{0x4, 3, 0x0A, 0x0B, 0x0C}), false)
.getBytes());
}
@@ -39,6 +36,6 @@ public class OctetStringTest {
void testParseFail() {
// EOF
assertThrows(ParseException.class, () ->
- new OctetString(new BytesReader(new Byte[]{ 0x4, 2, 0x0 }), false));
+ new OctetString(new BytesReader(new Byte[]{0x4, 2, 0x0}), false));
}
}
diff --git a/src/test/model/asn1/PrintableStringTest.java b/src/test/model/asn1/PrintableStringTest.java
index f46f400..c6eb7b1 100644
--- a/src/test/model/asn1/PrintableStringTest.java
+++ b/src/test/model/asn1/PrintableStringTest.java
@@ -21,24 +21,24 @@ public class PrintableStringTest {
void testIllegalStrings() {
ILLEGAL_CHARS_TO_TEST.chars()
.forEach(c ->
- assertThrows(ParseException.class,
- () -> new PrintableString(PrintableString.TAG, null, Character.toString(c)),
- String.format("Expected failing validation by char '%c'.", c))
+ assertThrows(ParseException.class,
+ () -> new PrintableString(PrintableString.TAG, null, Character.toString(c)),
+ String.format("Expected failing validation by char '%c'.", c))
);
}
@Test
void testEncode() throws ParseException {
assertArrayEquals(
- new Byte[] { 0x68, 0x68, 0x68 },
+ new Byte[]{0x68, 0x68, 0x68},
new PrintableString(PrintableString.TAG, null, "hhh").encodeValueDER());
assertArrayEquals(
- new Byte[] {
+ new Byte[]{
0x13, 0x02, // Tag - Length
0x68, 0x69 // Value
}, new PrintableString(PrintableString.TAG, null, "hi").encodeDER());
assertArrayEquals(
- new Byte[] {
+ new Byte[]{
-86, 0x05, // Parent Tag - Length
0x13, 0x03, // Inner Tag - Length
0x68, 0x69, 0x69 // Value
@@ -50,10 +50,10 @@ public class PrintableStringTest {
@Test
void testParse() throws ParseException {
assertEquals("123",
- new PrintableString(new BytesReader(new Byte[]{ 0x13, 3, '1', '2', '3' }), false)
+ new PrintableString(new BytesReader(new Byte[]{0x13, 3, '1', '2', '3'}), false)
.getString());
assertEquals("",
- new PrintableString(new BytesReader(new Byte[]{ 0x13, 0, '1', '2', '3' }), false)
+ new PrintableString(new BytesReader(new Byte[]{0x13, 0, '1', '2', '3'}), false)
.getString());
}
@@ -61,11 +61,11 @@ public class PrintableStringTest {
void testParseFail() {
// EOF
assertThrows(ParseException.class, () ->
- new PrintableString(new BytesReader(new Byte[]{ 0x13, 1 }), false));
+ new PrintableString(new BytesReader(new Byte[]{0x13, 1}), false));
// Illegal chars
assertThrows(ParseException.class, () ->
- new PrintableString(new BytesReader(new Byte[]{ 0x13, 2, '1', '*' }), false));
+ new PrintableString(new BytesReader(new Byte[]{0x13, 2, '1', '*'}), false));
assertThrows(ParseException.class, () ->
- new PrintableString(new BytesReader(new Byte[]{ 0x13, 2, '1', '@' }), false));
+ new PrintableString(new BytesReader(new Byte[]{0x13, 2, '1', '@'}), false));
}
}
diff --git a/src/test/model/asn1/TagClassTest.java b/src/test/model/asn1/TagClassTest.java
index d510618..e7d6531 100644
--- a/src/test/model/asn1/TagClassTest.java
+++ b/src/test/model/asn1/TagClassTest.java
@@ -2,7 +2,7 @@ package model.asn1;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TagClassTest {
@Test
diff --git a/src/test/model/asn1/TagTest.java b/src/test/model/asn1/TagTest.java
index 02df91f..a5d5d5f 100644
--- a/src/test/model/asn1/TagTest.java
+++ b/src/test/model/asn1/TagTest.java
@@ -24,35 +24,35 @@ public class TagTest {
void testParseSuccess() throws ParseException {
// Test basic parsing
assertEquals(0x1,
- new Tag(new BytesReader(new Byte[]{ 0x1 })).getNumber());
+ new Tag(new BytesReader(new Byte[]{0x1})).getNumber());
assertEquals(TagClass.UNIVERSAL,
- new Tag(new BytesReader(new Byte[]{ 0x1 })).getCls());
- assertFalse(new Tag(new BytesReader(new Byte[]{ 0x1 })).isConstructive());
+ new Tag(new BytesReader(new Byte[]{0x1})).getCls());
+ assertFalse(new Tag(new BytesReader(new Byte[]{0x1})).isConstructive());
// Test basic parsing with different class
assertEquals(5,
- new Tag(new BytesReader(new Byte[]{ 101 })).getNumber());
+ new Tag(new BytesReader(new Byte[]{101})).getNumber());
assertEquals(TagClass.APPLICATION,
- new Tag(new BytesReader(new Byte[]{ 101 })).getCls());
- assertTrue(new Tag(new BytesReader(new Byte[]{ 101 })).isConstructive());
+ new Tag(new BytesReader(new Byte[]{101})).getCls());
+ assertTrue(new Tag(new BytesReader(new Byte[]{101})).isConstructive());
// Test different classes
assertEquals(TagClass.UNIVERSAL,
- new Tag(new BytesReader(new Byte[]{ 1 })).getCls()); // 0b00000001
+ new Tag(new BytesReader(new Byte[]{1})).getCls()); // 0b00000001
assertEquals(TagClass.PRIVATE,
- new Tag(new BytesReader(new Byte[]{ -63 })).getCls()); // 0b11000001
+ new Tag(new BytesReader(new Byte[]{-63})).getCls()); // 0b11000001
assertEquals(TagClass.CONTEXT_SPECIFIC,
- new Tag(new BytesReader(new Byte[]{ -127 })).getCls()); // 0b10000001
+ new Tag(new BytesReader(new Byte[]{-127})).getCls()); // 0b10000001
assertEquals(TagClass.APPLICATION,
- new Tag(new BytesReader(new Byte[]{ 65 })).getCls()); // 0b01000001
+ new Tag(new BytesReader(new Byte[]{65})).getCls()); // 0b01000001
// Test different numbers
assertEquals(0x10,
- new Tag(new BytesReader(new Byte[]{ 0x10 })).getNumber());
+ new Tag(new BytesReader(new Byte[]{0x10})).getNumber());
assertEquals(31,
- new Tag(new BytesReader(new Byte[]{ 31 })).getNumber());
+ new Tag(new BytesReader(new Byte[]{31})).getNumber());
// Test constructive bit
- assertFalse(new Tag(new BytesReader(new Byte[]{ 0x1 })).isConstructive());
- assertTrue(new Tag(new BytesReader(new Byte[]{ 33 })).isConstructive());
+ assertFalse(new Tag(new BytesReader(new Byte[]{0x1})).isConstructive());
+ assertTrue(new Tag(new BytesReader(new Byte[]{33})).isConstructive());
// Test modification
- BytesReader reader = new BytesReader(new Byte[]{ 33 });
+ BytesReader reader = new BytesReader(new Byte[]{33});
assertEquals(0, reader.getIndex());
new Tag(reader);
assertEquals(1, reader.getIndex());
@@ -62,25 +62,25 @@ public class TagTest {
void testParseFail() {
// No enough bytes
assertThrows(ParseException.class, () -> {
- BytesReader reader = new BytesReader(new Byte[]{ 33 });
+ BytesReader reader = new BytesReader(new Byte[]{33});
reader.require(1, true);
new Tag(reader);
});
// Number zero
- assertThrows(ParseException.class, () -> new Tag(new BytesReader(new Byte[]{ 0 })));
+ assertThrows(ParseException.class, () -> new Tag(new BytesReader(new Byte[]{0})));
}
@Test
void testEncode() {
// Basic encoding
- assertArrayEquals(new Byte[]{ 1 }, new Tag(TagClass.UNIVERSAL, false, 1).encodeDER());
- assertArrayEquals(new Byte[]{ 31 }, new Tag(TagClass.UNIVERSAL, false, 31).encodeDER());
+ assertArrayEquals(new Byte[]{1}, new Tag(TagClass.UNIVERSAL, false, 1).encodeDER());
+ assertArrayEquals(new Byte[]{31}, new Tag(TagClass.UNIVERSAL, false, 31).encodeDER());
// With different class
- assertArrayEquals(new Byte[]{ -127 }, new Tag(TagClass.CONTEXT_SPECIFIC, false, 1).encodeDER());
- assertArrayEquals(new Byte[]{ -61 }, new Tag(TagClass.PRIVATE, false, 3).encodeDER());
- assertArrayEquals(new Byte[]{ 71 }, new Tag(TagClass.APPLICATION, false, 7).encodeDER());
+ assertArrayEquals(new Byte[]{-127}, new Tag(TagClass.CONTEXT_SPECIFIC, false, 1).encodeDER());
+ assertArrayEquals(new Byte[]{-61}, new Tag(TagClass.PRIVATE, false, 3).encodeDER());
+ assertArrayEquals(new Byte[]{71}, new Tag(TagClass.APPLICATION, false, 7).encodeDER());
// With different constructive bit
- assertArrayEquals(new Byte[]{ 63 }, new Tag(TagClass.UNIVERSAL, true, 31).encodeDER());
+ assertArrayEquals(new Byte[]{63}, new Tag(TagClass.UNIVERSAL, true, 31).encodeDER());
}
@Test
diff --git a/src/test/model/asn1/UTF8StringTest.java b/src/test/model/asn1/UTF8StringTest.java
index a2518ae..4e879f4 100644
--- a/src/test/model/asn1/UTF8StringTest.java
+++ b/src/test/model/asn1/UTF8StringTest.java
@@ -5,16 +5,14 @@ import model.asn1.parsing.BytesReader;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
public class UTF8StringTest {
- private static final String[] UTF8_CHARS = new String[] {
- new String(new byte[]{ -16, -97, -113, -77, -17, -72, -113, -30,
- -128, -115, -30, -102, -89, -17, -72, -113 }, StandardCharsets.UTF_8),
- new String(new byte[]{ -16, -97, -112, -79 }, StandardCharsets.UTF_8)
+ private static final String[] UTF8_CHARS = new String[]{
+ new String(new byte[]{-16, -97, -113, -77, -17, -72, -113, -30,
+ -128, -115, -30, -102, -89, -17, -72, -113}, StandardCharsets.UTF_8),
+ new String(new byte[]{-16, -97, -112, -79}, StandardCharsets.UTF_8)
};
@Test
@@ -36,7 +34,7 @@ public class UTF8StringTest {
}, new UTF8String(UTF8String.TAG, null, UTF8_CHARS[0] + UTF8_CHARS[1])
.encodeValueDER());
assertArrayEquals(
- new Byte[] {
+ new Byte[]{
0x0C, 6, // Tag - Length
0x68, 0x69, // Value
-16, -97, -112, -79
@@ -46,12 +44,12 @@ public class UTF8StringTest {
@Test
void testParse() throws ParseException {
assertEquals(UTF8_CHARS[0],
- new UTF8String(new BytesReader(new Byte[]{ 0x0C, 16,
+ new UTF8String(new BytesReader(new Byte[]{0x0C, 16,
-16, -97, -113, -77, -17, -72, -113, -30,
-128, -115, -30, -102, -89, -17, -72, -113
}), false).getString());
assertEquals("",
- new UTF8String(new BytesReader(new Byte[]{ 0x0C, 0, '1', '2', '3' }), false)
+ new UTF8String(new BytesReader(new Byte[]{0x0C, 0, '1', '2', '3'}), false)
.getString());
}
@@ -59,6 +57,6 @@ public class UTF8StringTest {
void testParseFail() {
// EOF
assertThrows(ParseException.class, () ->
- new UTF8String(new BytesReader(new Byte[]{ 0x0C, 1 }), false));
+ new UTF8String(new BytesReader(new Byte[]{0x0C, 1}), false));
}
}
diff --git a/src/test/model/asn1/UtcTimeTest.java b/src/test/model/asn1/UtcTimeTest.java
index 5ba7e13..41b5a9e 100644
--- a/src/test/model/asn1/UtcTimeTest.java
+++ b/src/test/model/asn1/UtcTimeTest.java
@@ -15,20 +15,20 @@ public class UtcTimeTest {
final ZonedDateTime now = ZonedDateTime.now();
assertEquals(now, new UtcTime(UtcTime.TAG, null, now).getTimestamp());
- final ASN1Time parsed = new UtcTime(new BytesReader(new Byte[] {
+ final ASN1Time parsed = new UtcTime(new BytesReader(new Byte[]{
0x17, 13,
'1', '9', '0', '8', '1', '0', '1', '1', '4', '5', '1', '4', 'Z'
}), false);
assertEquals("190810114514Z",
parsed.toString());
assertEquals(ZonedDateTime.of(2019, 8, 10, 11, 45, 14,
- 0, ZoneId.of("UTC")),
+ 0, ZoneId.of("UTC")),
parsed.getTimestamp());
}
@Test
void testParse() throws ParseException {
- ASN1Time parsed = new UtcTime(new BytesReader(new Byte[] {
+ ASN1Time parsed = new UtcTime(new BytesReader(new Byte[]{
0x17, 13,
'2', '3', '0', '9', '2', '7', '1', '1', '4', '5', '1', '4', 'Z'
}), false);
@@ -38,7 +38,7 @@ public class UtcTimeTest {
parsed.getTimestamp());
// No seconds
- parsed = new UtcTime(new BytesReader(new Byte[] {
+ parsed = new UtcTime(new BytesReader(new Byte[]{
0x17, 11,
'2', '3', '0', '9', '2', '7', '1', '1', '4', '5', 'Z'
}), false);
@@ -98,20 +98,20 @@ public class UtcTimeTest {
@Test
void testEncode() throws ParseException {
- assertEquals("230927114514Z", new UtcTime(new BytesReader(new Byte[] {
+ assertEquals("230927114514Z", new UtcTime(new BytesReader(new Byte[]{
-95, 15,
0x17, 13,
'2', '3', '0', '9', '2', '7', '1', '1', '4', '5', '1', '4', 'Z'
}), true).toString());
// No seconds
- assertEquals("2309271145Z", new UtcTime(new BytesReader(new Byte[] {
+ assertEquals("2309271145Z", new UtcTime(new BytesReader(new Byte[]{
-95, 13,
0x17, 11,
'2', '3', '0', '9', '2', '7', '1', '1', '4', '5', 'Z'
}), true).toString());
// To byte array
- assertArrayEquals(new Byte[] {
+ assertArrayEquals(new Byte[]{
0x17, 11,
'2', '3', '0', '9', '2', '7', '1', '1', '4', '5', 'Z'
}, new UtcTime(UtcTime.TAG, null, ZonedDateTime.of(2023, 9,
diff --git a/src/test/model/asn1/parsing/BytesReaderTest.java b/src/test/model/asn1/parsing/BytesReaderTest.java
index 3b63a79..93c2765 100644
--- a/src/test/model/asn1/parsing/BytesReaderTest.java
+++ b/src/test/model/asn1/parsing/BytesReaderTest.java
@@ -13,14 +13,14 @@ public class BytesReaderTest {
@BeforeEach
void setup() {
- target = new BytesReader(new Byte[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
+ target = new BytesReader(new Byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
}
@Test
void testConstructor() {
assertEquals(0, target.getIndex());
assertEquals(10, target.getRawInput().length);
- assertArrayEquals(new Byte[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, target.getRawInput());
+ assertArrayEquals(new Byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, target.getRawInput());
}
@Test
@@ -34,19 +34,19 @@ public class BytesReaderTest {
void testRead() {
assertEquals(10, target.bytesRemaining());
assertEquals(0, target.getIndex());
- assertArrayEquals(new Byte[]{ 1, 2 }, target.read(2, true));
+ assertArrayEquals(new Byte[]{1, 2}, target.read(2, true));
assertEquals(8, target.bytesRemaining());
assertEquals(2, target.getIndex());
- assertArrayEquals(new Byte[]{ 3 }, target.read(1, false));
+ assertArrayEquals(new Byte[]{3}, target.read(1, false));
assertEquals(8, target.bytesRemaining());
assertEquals(2, target.getIndex());
- assertArrayEquals(new Byte[]{ 3, 4, 5, 6, 7 }, target.read(5, true));
+ assertArrayEquals(new Byte[]{3, 4, 5, 6, 7}, target.read(5, true));
assertEquals(3, target.bytesRemaining());
assertEquals(7, target.getIndex());
- assertArrayEquals(new Byte[]{ 8, 9, 10 }, target.read(3, false));
+ assertArrayEquals(new Byte[]{8, 9, 10}, target.read(3, false));
assertEquals(3, target.bytesRemaining());
assertEquals(7, target.getIndex());
- assertArrayEquals(new Byte[]{ 8, 9, 10 }, target.read(3, true));
+ assertArrayEquals(new Byte[]{8, 9, 10}, target.read(3, true));
assertEquals(0, target.bytesRemaining());
assertEquals(10, target.getIndex());
}
@@ -55,11 +55,11 @@ public class BytesReaderTest {
void testRequire() throws Exception { // TODO: Exception testing
assertEquals(10, target.bytesRemaining());
assertEquals(0, target.getIndex());
- assertArrayEquals(new Byte[]{ 1, 2 }, target.require(2, true));
- assertArrayEquals(new Byte[]{ 3, 4, 5, 6, 7, 8, 9 }, target.require(7, true));
- assertArrayEquals(new Byte[]{ 10 }, target.require(1, false));
+ assertArrayEquals(new Byte[]{1, 2}, target.require(2, true));
+ assertArrayEquals(new Byte[]{3, 4, 5, 6, 7, 8, 9}, target.require(7, true));
+ assertArrayEquals(new Byte[]{10}, target.require(1, false));
assertThrows(ParseException.class, () -> target.require(2, true));
- assertArrayEquals(new Byte[]{ 10 }, target.require(1, true));
+ assertArrayEquals(new Byte[]{10}, target.require(1, true));
assertThrows(ParseException.class, () -> target.require(1, true));
}
@@ -67,18 +67,18 @@ public class BytesReaderTest {
void testValidateSize() throws Exception { // TODO: Exception testing
assertEquals(10, target.bytesRemaining());
assertEquals(0, target.getIndex());
- assertArrayEquals(new Byte[]{ 1, 2 }, target.require(2, true));
- assertArrayEquals(new Byte[]{ 3, 4, 5, 6, 7, 8, 9 }, target.require(7, true));
- assertArrayEquals(new Byte[]{ 10 }, target.require(1, false));
+ assertArrayEquals(new Byte[]{1, 2}, target.require(2, true));
+ assertArrayEquals(new Byte[]{3, 4, 5, 6, 7, 8, 9}, target.require(7, true));
+ assertArrayEquals(new Byte[]{10}, target.require(1, false));
target.validateSize(1);
assertThrows(ParseException.class, () -> target.validateSize(2));
- assertArrayEquals(new Byte[]{ 10 }, target.require(1, true));
+ assertArrayEquals(new Byte[]{10}, target.require(1, true));
assertThrows(ParseException.class, () -> target.validateSize(1));
}
@Test
void testDetectTag() throws Exception {
- final BytesReader reader = new BytesReader(new Byte[]{ -95, 0 });
+ final BytesReader reader = new BytesReader(new Byte[]{-95, 0});
assertTrue(reader.detectTag(new Tag(TagClass.CONTEXT_SPECIFIC, true, 1)));
assertFalse(reader.detectTag(new Tag(TagClass.CONTEXT_SPECIFIC, true, 0)));
assertFalse(reader.detectTag(new Tag(TagClass.UNIVERSAL, true, 0)));
@@ -87,9 +87,9 @@ public class BytesReaderTest {
@Test
void testGetTag() throws Exception {
- BytesReader reader = new BytesReader(new Byte[]{ -95, 0 });
+ BytesReader reader = new BytesReader(new Byte[]{-95, 0});
assertEquals(1, reader.getTag(false).getNumber());
- reader = new BytesReader(new Byte[]{ -96, 0, -95, 0 });
+ reader = new BytesReader(new Byte[]{-96, 0, -95, 0});
assertEquals(1, reader.getTag(true).getNumber());
}
}
diff --git a/src/test/model/csr/AttributeTest.java b/src/test/model/csr/AttributeTest.java
index f4daa4c..4899072 100644
--- a/src/test/model/csr/AttributeTest.java
+++ b/src/test/model/csr/AttributeTest.java
@@ -5,7 +5,7 @@ import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import org.junit.jupiter.api.Test;
-import static model.asn1.ObjectIdentifier.*;
+import static model.asn1.ObjectIdentifier.OID_EXTENSION_REQUEST;
import static org.junit.jupiter.api.Assertions.*;
public class AttributeTest {
diff --git a/src/test/model/csr/AttributesTest.java b/src/test/model/csr/AttributesTest.java
index 86a0112..eebdbfb 100644
--- a/src/test/model/csr/AttributesTest.java
+++ b/src/test/model/csr/AttributesTest.java
@@ -24,12 +24,12 @@ public class AttributesTest {
@Test
void testParse() throws ParseException {
final Attributes parsed = new Attributes(new BytesReader(new Byte[]{
- -96, 30,
- 0x30, 0x1C,
- 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, -126, 0x37, 0x0D, 0x02, 0x03,
- 0x31, 0x0E,
- 0x16, 0x0C, 0x31, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x39, 0x30, 0x34, 0x35, 0x2E, 0x32
- }), false);
+ -96, 30,
+ 0x30, 0x1C,
+ 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, -126, 0x37, 0x0D, 0x02, 0x03,
+ 0x31, 0x0E,
+ 0x16, 0x0C, 0x31, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x39, 0x30, 0x34, 0x35, 0x2E, 0x32
+ }), false);
assertEquals(1, parsed.getArray().length);
assertEquals("10.0.19045.2", parsed.getArray()[0].getValues().getArray()[0].toString());
}
@@ -59,7 +59,7 @@ public class AttributesTest {
Byte[] a2 = TestConstants.CSR_ATTR_2.encodeDER();
Byte[] a1 = TestConstants.CSR_ATTR_1.encodeDER();
assertArrayEquals(
- Stream.of(Arrays.asList(new Byte[]{ 0x31, (byte)(a2.length + a1.length) }),
+ Stream.of(Arrays.asList(new Byte[]{0x31, (byte) (a2.length + a1.length)}),
Arrays.asList(a2),
Arrays.asList(a1))
.flatMap(Collection::stream)
diff --git a/src/test/model/csr/CertificationRequestInfoTest.java b/src/test/model/csr/CertificationRequestInfoTest.java
index fe2633f..bb7ae38 100644
--- a/src/test/model/csr/CertificationRequestInfoTest.java
+++ b/src/test/model/csr/CertificationRequestInfoTest.java
@@ -12,7 +12,7 @@ import static model.TestConstants.mutate;
import static org.junit.jupiter.api.Assertions.*;
public class CertificationRequestInfoTest {
- static final Byte[] CSR_1 = new Byte[] {
+ static final Byte[] CSR_1 = new Byte[]{
0x30, -126, 0x02, 0x03, // SEQUENCE CertificationRequestInfo
0x02, 0x01, 0x00, // Version
0x30, 0x1c, // SEQUENCE Subject
@@ -22,30 +22,30 @@ public class CertificationRequestInfoTest {
0x0c, 0x11, 0x4d, 0x49, 0x4b, 0x55, 0x2e, 0x41, // PrintableString (MIKU.AD.YUUTA.MOE)
0x44, 0x2e, 0x59, 0x55, 0x55, 0x54, 0x41, 0x2e,
0x4d, 0x4f, 0x45,
- 0x30, -127, -97, // SEQUENCE SubjectPublicKeyInfo
+ 0x30, -127, -97, // SEQUENCE SubjectPublicKeyInfo
0x30, 0x0d, // SEQUENCE AlgorithmIdentifier
- 0x06, 0x09, 0x2a, -122, 0x48, -122, -9, 0x0d, // OID (rsaEncryption)
+ 0x06, 0x09, 0x2a, -122, 0x48, -122, -9, 0x0d, // OID (rsaEncryption)
0x01, 0x01, 0x01,
0x05, 0x00, // Null (Parameter)
0x03, -127, -115, 0x00, 0x30, -127, -119, 0x02, // BIT STRING (subjectPublicKey)
- -127, -127, 0x00, -67, -1, 0x4e, 0x6d, -22,
- 0x62, 0x6a, 0x11, -120, 0x77, 0x0a, -92, 0x32,
- -124, -37, 0x22, 0x2f, 0x3d, 0x5d, 0x2a, 0x63,
- -71, -109, 0x11, -50, -92, 0x4f, -119, 0x3b,
- 0x14, 0x3b, -54, 0x3c, -106, -42, 0x11, 0x42,
- 0x78, -110, 0x68, -100, -25, -25, -50, 0x75,
- -101, 0x21, 0x41, -34, -31, -85, -13, 0x1e,
- 0x51, -81, 0x25, 0x4f, -1, 0x56, 0x77, 0x5e,
- -30, 0x27, -104, 0x34, 0x67, -28, -56, 0x55,
- 0x6a, 0x3c, 0x6f, -38, -85, -63, 0x5f, 0x16,
- 0x7a, -93, -19, -35, 0x7f, 0x35, 0x0f, -47,
- -7, -22, -12, -24, -48, 0x25, 0x6d, -114,
- 0x66, 0x1a, 0x53, -77, 0x67, 0x32, -69, -39,
- 0x57, -42, -65, -13, 0x5f, 0x6f, 0x53, 0x6d,
- 0x62, -95, 0x42, 0x12, 0x7b, 0x13, 0x4f, 0x1a,
- -26, 0x00, -72, -32, 0x2b, -83, 0x3c, 0x35,
+ -127, -127, 0x00, -67, -1, 0x4e, 0x6d, -22,
+ 0x62, 0x6a, 0x11, -120, 0x77, 0x0a, -92, 0x32,
+ -124, -37, 0x22, 0x2f, 0x3d, 0x5d, 0x2a, 0x63,
+ -71, -109, 0x11, -50, -92, 0x4f, -119, 0x3b,
+ 0x14, 0x3b, -54, 0x3c, -106, -42, 0x11, 0x42,
+ 0x78, -110, 0x68, -100, -25, -25, -50, 0x75,
+ -101, 0x21, 0x41, -34, -31, -85, -13, 0x1e,
+ 0x51, -81, 0x25, 0x4f, -1, 0x56, 0x77, 0x5e,
+ -30, 0x27, -104, 0x34, 0x67, -28, -56, 0x55,
+ 0x6a, 0x3c, 0x6f, -38, -85, -63, 0x5f, 0x16,
+ 0x7a, -93, -19, -35, 0x7f, 0x35, 0x0f, -47,
+ -7, -22, -12, -24, -48, 0x25, 0x6d, -114,
+ 0x66, 0x1a, 0x53, -77, 0x67, 0x32, -69, -39,
+ 0x57, -42, -65, -13, 0x5f, 0x6f, 0x53, 0x6d,
+ 0x62, -95, 0x42, 0x12, 0x7b, 0x13, 0x4f, 0x1a,
+ -26, 0x00, -72, -32, 0x2b, -83, 0x3c, 0x35,
-103, 0x18, 0x51, 0x02, 0x03, 0x01, 0x00, 0x01,
- -96, -126, 0x01, 0x3c, // SEQUENCE (attributes)
+ -96, -126, 0x01, 0x3c, // SEQUENCE (attributes)
0x30, 0x1c, 0x06, 0x0a, // SEQUENCE (attribute)
0x2b, 0x06, 0x01, 0x04, 0x01, -126, 0x37, 0x0d,
0x02, 0x03, 0x31, 0x0e, 0x16, 0x0c, 0x31, 0x30,
@@ -76,10 +76,10 @@ public class CertificationRequestInfoTest {
0x6f, 0x00, 0x76, 0x00, 0x69, 0x00, 0x64, 0x00,
0x65, 0x00, 0x72, 0x03, 0x01, 0x00,
0x30, 0x70, 0x06, 0x09, // SEQUENCE (attribute)
- 0x2a, -122, 0x48, -122, -9, 0x0d, 0x01, 0x09,
+ 0x2a, -122, 0x48, -122, -9, 0x0d, 0x01, 0x09,
0x0e, 0x31, 0x63, 0x30, 0x61, 0x30, 0x0e, 0x06,
- 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, -1, 0x04,
- 0x04, 0x03, 0x02, 0x05, -96, 0x30, 0x13, 0x06,
+ 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, -1, 0x04,
+ 0x04, 0x03, 0x02, 0x05, -96, 0x30, 0x13, 0x06,
0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a,
0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
0x03, 0x01, 0x30, 0x1b, 0x06, 0x09, 0x2b, 0x06,
@@ -87,9 +87,9 @@ public class CertificationRequestInfoTest {
0x0e, 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b,
0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30,
0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
- 0x04, 0x14, -15, 0x3e, -110, -16, 0x4d, 0x1b,
- -47, 0x6e, 0x53, 0x7f, -102, 0x1d, 0x19, -75,
- 0x5e, -22, 0x64, 0x7f, 0x1f, -110,
+ 0x04, 0x14, -15, 0x3e, -110, -16, 0x4d, 0x1b,
+ -47, 0x6e, 0x53, 0x7f, -102, 0x1d, 0x19, -75,
+ 0x5e, -22, 0x64, 0x7f, 0x1f, -110,
};
@Test
@@ -104,7 +104,7 @@ public class CertificationRequestInfoTest {
ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION),
new Null(Null.TAG, null)),
new BitString(BitString.TAG, null,
- 0, new Byte[]{ 1, 2, 3, 4, 5 })),
+ 0, new Byte[]{1, 2, 3, 4, 5})),
TestConstants.CSR_ATTRS_2);
assertEquals(CertificationRequestInfo.VERSION_V1, info.getVersion().getLong());
assertEquals(3, info.getSubject().getRdnSequence().length);
diff --git a/src/test/model/csr/CertificationRequestTest.java b/src/test/model/csr/CertificationRequestTest.java
index 962e90b..689f39d 100644
--- a/src/test/model/csr/CertificationRequestTest.java
+++ b/src/test/model/csr/CertificationRequestTest.java
@@ -18,25 +18,25 @@ import static org.junit.jupiter.api.Assertions.*;
public class CertificationRequestTest {
private static final Byte[] CSR_1 = Stream.of(
// SEQUENCE (CertificationRequest)
- Arrays.asList(new Byte[]{ 0x30, -126, 0x02, -102 }),
+ Arrays.asList(new Byte[]{0x30, -126, 0x02, -102}),
// SEQUENCE (CertificationRequestInfo)
Arrays.asList(CertificationRequestInfoTest.CSR_1),
// SEQUENCE (AlgorithmIdentifier)
Arrays.asList(new Byte[]{
0x30, 0x0D, 0x06, 0x09, 0x2A, -122, 0x48, -122,
- -9, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00
+ -9, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00
}),
// BIT STRING (Signature)
Arrays.asList(new Byte[]{
0x03, -127, -127,
- 0x00, 0x6F, 0x61, 0x5C, -25, 0x29, 0x48, 0x3F,
- -78, 0x1B, -117, 0x2C, -93, -114, 0x7D, -77,
- 0x62, 0x14, 0x21, 0x4B, -99, 0x74, -95, -93,
- 0x16, 0x38, 0x31, 0x40, 0x5E, 0x72, -77, -55,
- 0x6D, -69, 0x19, -108, 0x52, -95, 0x19, -121,
- -81, -71, 0x74, -123, 0x6B, -27, -20, 0x4C,
- -126, 0x42, -89, 0x66, 0x6A, 0x52, -34, 0x62,
- 0x72, 0x40, 0x2C, -79, 0x78, -117, -100, -70,
+ 0x00, 0x6F, 0x61, 0x5C, -25, 0x29, 0x48, 0x3F,
+ -78, 0x1B, -117, 0x2C, -93, -114, 0x7D, -77,
+ 0x62, 0x14, 0x21, 0x4B, -99, 0x74, -95, -93,
+ 0x16, 0x38, 0x31, 0x40, 0x5E, 0x72, -77, -55,
+ 0x6D, -69, 0x19, -108, 0x52, -95, 0x19, -121,
+ -81, -71, 0x74, -123, 0x6B, -27, -20, 0x4C,
+ -126, 0x42, -89, 0x66, 0x6A, 0x52, -34, 0x62,
+ 0x72, 0x40, 0x2C, -79, 0x78, -117, -100, -70,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -53,23 +53,23 @@ public class CertificationRequestTest {
final CertificationRequest request = new CertificationRequest(
ASN1Object.TAG_SEQUENCE, null,
new CertificationRequestInfo(
- ASN1Object.TAG_SEQUENCE, null,
- new Int(Int.TAG, null, CertificationRequestInfo.VERSION_V1),
- TestConstants.NAME_2,
- new SubjectPublicKeyInfo(ASN1Object.TAG_SEQUENCE, null,
- new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
- new ObjectIdentifier(ObjectIdentifier.TAG, null,
- ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION),
- new Null(Null.TAG, null)),
- new BitString(BitString.TAG, null,
- 0, new Byte[]{ 1, 2, 3, 4, 5 })),
- TestConstants.CSR_ATTRS_2),
+ ASN1Object.TAG_SEQUENCE, null,
+ new Int(Int.TAG, null, CertificationRequestInfo.VERSION_V1),
+ TestConstants.NAME_2,
+ new SubjectPublicKeyInfo(ASN1Object.TAG_SEQUENCE, null,
+ new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
+ new ObjectIdentifier(ObjectIdentifier.TAG, null,
+ ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION),
+ new Null(Null.TAG, null)),
+ new BitString(BitString.TAG, null,
+ 0, new Byte[]{1, 2, 3, 4, 5})),
+ TestConstants.CSR_ATTRS_2),
new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null,
ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION),
new Null(Null.TAG, null)),
new BitString(BitString.TAG, null,
- 0, new Byte[]{ 2, 4, 6, 8, 10 }));
+ 0, new Byte[]{2, 4, 6, 8, 10}));
assertEquals(CertificationRequestInfo.VERSION_V1,
request.getCertificationRequestInfo().getVersion().getLong());
@@ -77,7 +77,7 @@ public class CertificationRequestTest {
request.getCertificationRequestInfo().getSubject().getRdnSequence().length);
assertArrayEquals(ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION,
request.getSignatureAlgorithm().getType().getInts());
- assertArrayEquals(new Byte[]{ 2, 4, 6, 8, 10 },
+ assertArrayEquals(new Byte[]{2, 4, 6, 8, 10},
request.getSignature().getConvertedVal());
}
diff --git a/src/test/model/csr/ValuesTest.java b/src/test/model/csr/ValuesTest.java
index 93229a4..5ee6070 100644
--- a/src/test/model/csr/ValuesTest.java
+++ b/src/test/model/csr/ValuesTest.java
@@ -1,19 +1,12 @@
package model.csr;
import model.asn1.ASN1Object;
-import model.asn1.Null;
-import model.asn1.ObjectIdentifier;
-import model.asn1.PrintableString;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.x501.AttributeTypeAndValue;
-import model.x501.RelativeDistinguishedName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static model.asn1.ASN1Object.TAG_SET;
-import static model.asn1.ObjectIdentifier.OID_C;
-import static model.asn1.ObjectIdentifier.OID_OU;
import static org.junit.jupiter.api.Assertions.*;
public class ValuesTest {
diff --git a/src/test/model/pki/AlgorithmIdentifierTest.java b/src/test/model/pki/AlgorithmIdentifierTest.java
index 8bcc80e..cbd2e7c 100644
--- a/src/test/model/pki/AlgorithmIdentifierTest.java
+++ b/src/test/model/pki/AlgorithmIdentifierTest.java
@@ -72,12 +72,12 @@ public class AlgorithmIdentifierTest {
@Test
void testEncode() throws ParseException {
assertArrayEquals(new Byte[]{
- 0x30, 0x0D, // SEQUENCE AlgorithmIdentifier
- 0x06, 0x09, 0x2A, -122, 0x48, -122, -9, 0x0D, // OID (sha256WithRsaEncryption)
- 0x01, 0x01, 0x0B,
- 0x05, 0x00 // Null (Parameter)
- }, new AlgorithmIdentifier(
- ASN1Object.TAG_SEQUENCE, null,
+ 0x30, 0x0D, // SEQUENCE AlgorithmIdentifier
+ 0x06, 0x09, 0x2A, -122, 0x48, -122, -9, 0x0D, // OID (sha256WithRsaEncryption)
+ 0x01, 0x01, 0x0B,
+ 0x05, 0x00 // Null (Parameter)
+ }, new AlgorithmIdentifier(
+ ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null, OID_SHA256_WITH_RSA_ENCRYPTION),
new Null(Null.TAG, null)).encodeDER());
}
diff --git a/src/test/model/pki/SubjectPublicKeyInfoTest.java b/src/test/model/pki/SubjectPublicKeyInfoTest.java
index f1cfff0..7f16330 100644
--- a/src/test/model/pki/SubjectPublicKeyInfoTest.java
+++ b/src/test/model/pki/SubjectPublicKeyInfoTest.java
@@ -7,53 +7,52 @@ import model.asn1.ObjectIdentifier;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import model.csr.CertificationRequestInfo;
-import model.csr.CertificationRequestInfoTest;
import org.junit.jupiter.api.Test;
import static model.TestConstants.mutate;
import static org.junit.jupiter.api.Assertions.*;
public class SubjectPublicKeyInfoTest {
- private static final Byte[] RSA = new Byte[] {
- 0x30, -127, -97, // SEQUENCE SubjectPublicKeyInfo
+ private static final Byte[] RSA = new Byte[]{
+ 0x30, -127, -97, // SEQUENCE SubjectPublicKeyInfo
0x30, 0x0d, // SEQUENCE AlgorithmIdentifier
- 0x06, 0x09, 0x2a, -122, 0x48, -122, -9, 0x0d, // OID (rsaEncryption)
+ 0x06, 0x09, 0x2a, -122, 0x48, -122, -9, 0x0d, // OID (rsaEncryption)
0x01, 0x01, 0x01,
0x05, 0x00, // Null (Parameter)
0x03, -127, -115, 0x00, 0x30, -127, -119, 0x02, // BIT STRING (subjectPublicKey)
- -127, -127, 0x00, -67, -1, 0x4e, 0x6d, -22,
- 0x62, 0x6a, 0x11, -120, 0x77, 0x0a, -92, 0x32,
- -124, -37, 0x22, 0x2f, 0x3d, 0x5d, 0x2a, 0x63,
- -71, -109, 0x11, -50, -92, 0x4f, -119, 0x3b,
- 0x14, 0x3b, -54, 0x3c, -106, -42, 0x11, 0x42,
- 0x78, -110, 0x68, -100, -25, -25, -50, 0x75,
- -101, 0x21, 0x41, -34, -31, -85, -13, 0x1e,
- 0x51, -81, 0x25, 0x4f, -1, 0x56, 0x77, 0x5e,
- -30, 0x27, -104, 0x34, 0x67, -28, -56, 0x55,
- 0x6a, 0x3c, 0x6f, -38, -85, -63, 0x5f, 0x16,
- 0x7a, -93, -19, -35, 0x7f, 0x35, 0x0f, -47,
- -7, -22, -12, -24, -48, 0x25, 0x6d, -114,
- 0x66, 0x1a, 0x53, -77, 0x67, 0x32, -69, -39,
- 0x57, -42, -65, -13, 0x5f, 0x6f, 0x53, 0x6d,
- 0x62, -95, 0x42, 0x12, 0x7b, 0x13, 0x4f, 0x1a,
- -26, 0x00, -72, -32, 0x2b, -83, 0x3c, 0x35,
+ -127, -127, 0x00, -67, -1, 0x4e, 0x6d, -22,
+ 0x62, 0x6a, 0x11, -120, 0x77, 0x0a, -92, 0x32,
+ -124, -37, 0x22, 0x2f, 0x3d, 0x5d, 0x2a, 0x63,
+ -71, -109, 0x11, -50, -92, 0x4f, -119, 0x3b,
+ 0x14, 0x3b, -54, 0x3c, -106, -42, 0x11, 0x42,
+ 0x78, -110, 0x68, -100, -25, -25, -50, 0x75,
+ -101, 0x21, 0x41, -34, -31, -85, -13, 0x1e,
+ 0x51, -81, 0x25, 0x4f, -1, 0x56, 0x77, 0x5e,
+ -30, 0x27, -104, 0x34, 0x67, -28, -56, 0x55,
+ 0x6a, 0x3c, 0x6f, -38, -85, -63, 0x5f, 0x16,
+ 0x7a, -93, -19, -35, 0x7f, 0x35, 0x0f, -47,
+ -7, -22, -12, -24, -48, 0x25, 0x6d, -114,
+ 0x66, 0x1a, 0x53, -77, 0x67, 0x32, -69, -39,
+ 0x57, -42, -65, -13, 0x5f, 0x6f, 0x53, 0x6d,
+ 0x62, -95, 0x42, 0x12, 0x7b, 0x13, 0x4f, 0x1a,
+ -26, 0x00, -72, -32, 0x2b, -83, 0x3c, 0x35,
-103, 0x18, 0x51, 0x02, 0x03, 0x01, 0x00, 0x01,
};
- private static final Byte[] ECC = new Byte[] {
+ private static final Byte[] ECC = new Byte[]{
0x30, 0x59, // SEQUENCE SubjectPublicKeyInfo
0x30, 0x13, // SEQUENCE AlgorithmIdentifier
- 0x06, 0x07, 0x2A, -122, 0x48, -50, 0x3D, 0x02, 0x01, // OID (ecPublicKey)
- 0x06, 0x08, 0x2A, -122, 0x48, -50, 0x3D, 0x03, 0x01, // OID Parameter (prime256v1)
+ 0x06, 0x07, 0x2A, -122, 0x48, -50, 0x3D, 0x02, 0x01, // OID (ecPublicKey)
+ 0x06, 0x08, 0x2A, -122, 0x48, -50, 0x3D, 0x03, 0x01, // OID Parameter (prime256v1)
0x07,
0x03, 0x42, // BIT STRING
- 0x00, 0x04, 0x1D, -24, 0x71, -68, -35, 0x48, 0x70,
- 0x26, 0x71, 0x6C, -35, 0x04, 0x5B, 0x3F, 0x5D, -34,
+ 0x00, 0x04, 0x1D, -24, 0x71, -68, -35, 0x48, 0x70,
+ 0x26, 0x71, 0x6C, -35, 0x04, 0x5B, 0x3F, 0x5D, -34,
0x14, 0x31, -117, 0x3F, 0x31, -128, 0x18, 0x2A, 0x33,
- -27, 0x19, -122, 0x13, -42, -25, 0x48, 0x2F, -107,
- 0x15, 0x3A, 0x59, -115, -19, 0x09, -28, 0x53, 0x1A,
- -13, 0x61, -78, 0x35, 0x61, 0x6E, 0x66, 0x5F, 0x5F,
- -49, 0x0A, -30, 0x65, 0x65, 0x3D, 0x22, 0x2B, 0x30,
+ -27, 0x19, -122, 0x13, -42, -25, 0x48, 0x2F, -107,
+ 0x15, 0x3A, 0x59, -115, -19, 0x09, -28, 0x53, 0x1A,
+ -13, 0x61, -78, 0x35, 0x61, 0x6E, 0x66, 0x5F, 0x5F,
+ -49, 0x0A, -30, 0x65, 0x65, 0x3D, 0x22, 0x2B, 0x30,
0x71, 0x2C, 0x24
};
@@ -66,16 +65,16 @@ public class SubjectPublicKeyInfoTest {
ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION),
new Null(Null.TAG, null)),
new BitString(BitString.TAG, null,
- 0, new Byte[]{ 1, 2, 3}))
+ 0, new Byte[]{1, 2, 3}))
.getAlgorithm().getType().getInts());
- assertArrayEquals(new Byte[]{ 1, 2, 3 },
+ assertArrayEquals(new Byte[]{1, 2, 3},
new SubjectPublicKeyInfo(ASN1Object.TAG_SEQUENCE, null,
new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null,
ObjectIdentifier.OID_SHA256_WITH_RSA_ENCRYPTION),
new Null(Null.TAG, null)),
new BitString(BitString.TAG, null,
- 0, new Byte[]{ 1, 2, 3}))
+ 0, new Byte[]{1, 2, 3}))
.getSubjectPublicKey().getConvertedVal());
}
@@ -109,7 +108,7 @@ public class SubjectPublicKeyInfoTest {
// Incorrect public key tag
assertThrows(ParseException.class, () -> {
new CertificationRequestInfo(new BytesReader(mutate(RSA, 18, BitString.TAG.getNumber(), 0x31)),
- false);
+ false);
});
}
}
diff --git a/src/test/model/pki/cert/CertificateTest.java b/src/test/model/pki/cert/CertificateTest.java
index 70564fc..5fb2e82 100644
--- a/src/test/model/pki/cert/CertificateTest.java
+++ b/src/test/model/pki/cert/CertificateTest.java
@@ -1,20 +1,15 @@
package model.pki.cert;
import model.TestConstants;
-import model.asn1.*;
+import model.asn1.ASN1Object;
+import model.asn1.BitString;
+import model.asn1.Null;
+import model.asn1.ObjectIdentifier;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.csr.CertificationRequest;
-import model.csr.CertificationRequestInfo;
-import model.csr.CertificationRequestInfoTest;
import model.pki.AlgorithmIdentifier;
-import model.pki.SubjectPublicKeyInfo;
import org.junit.jupiter.api.Test;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.stream.Stream;
-
import static model.TestConstants.mutate;
import static org.junit.jupiter.api.Assertions.*;
@@ -26,13 +21,13 @@ public class CertificateTest {
new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_RSA_ENCRYPTION),
new Null(Null.TAG, null)),
- new BitString(BitString.TAG, null, 0, new Byte[]{ 1, 2, 3 }));
+ new BitString(BitString.TAG, null, 0, new Byte[]{1, 2, 3}));
assertEquals(TbsCertificate.VERSION_V3,
certificate.getCertificate().getVersion().getLong());
assertArrayEquals(ObjectIdentifier.OID_RSA_ENCRYPTION,
certificate.getSignatureAlgorithm().getType().getInts());
- assertArrayEquals(new Byte[]{ 1, 2, 3 },
+ assertArrayEquals(new Byte[]{1, 2, 3},
certificate.getSignature().getConvertedVal());
}
@@ -57,7 +52,7 @@ public class CertificateTest {
void testParseFail() {
// Incorrect certificate tag
assertThrows(ParseException.class, () ->
- new Certificate(new BytesReader(mutate(TestConstants.CERT_L1_ECC, 4, 0x30, 0x31)), false)
+ new Certificate(new BytesReader(mutate(TestConstants.CERT_L1_ECC, 4, 0x30, 0x31)), false)
);
// Incorrect signatureAlgorithm tag
assertThrows(ParseException.class, () ->
diff --git a/src/test/model/pki/cert/ExtensionTest.java b/src/test/model/pki/cert/ExtensionTest.java
index 06561ba..e00cbc5 100644
--- a/src/test/model/pki/cert/ExtensionTest.java
+++ b/src/test/model/pki/cert/ExtensionTest.java
@@ -11,19 +11,19 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ExtensionTest {
- static final Byte[] EXT_SUBJECT_KEY_ID = new Byte[] {
+ static final Byte[] EXT_SUBJECT_KEY_ID = new Byte[]{
0x30, 0x1D, // SEQUENCE Extension
0x06, 0x03, 0x55, 0x1D, 0x0E, // OID subjectKeyIdentifier
0x04, 0x16, // OCTET STRING
- 0x04, 0x14, -79, -62, -89, -127, 0x63, 0x66,
- 0x4B, 0x72, 0x0A, -35, -3, 0x7D, 0x20, 0x29,
- -67, 0x6B, 0x49, 0x09, 0x61, -64
+ 0x04, 0x14, -79, -62, -89, -127, 0x63, 0x66,
+ 0x4B, 0x72, 0x0A, -35, -3, 0x7D, 0x20, 0x29,
+ -67, 0x6B, 0x49, 0x09, 0x61, -64
};
- static final Byte[] EXT_KEY_USAGE = new Byte[] {
+ static final Byte[] EXT_KEY_USAGE = new Byte[]{
0x30, 0x0E, // SEQUENCE Extension
0x06, 0x03, 0x55, 0x1D, 0x0F, // OID keyUsage
- 0x01, 0x01, -1, // BOOLEAN critical
+ 0x01, 0x01, -1, // BOOLEAN critical
0x04, 0x04, // OCTET STRING
0x03, 0x02, 0x01, -122
};
@@ -33,10 +33,10 @@ public class ExtensionTest {
final Extension ext = new Extension(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_BASIC_CONSTRAINTS),
new Bool(Bool.TAG, null, true),
- new OctetString(OctetString.TAG, null, new Byte[]{ 0x30, 0x03, 0x01, 0x01, -1 }));
+ new OctetString(OctetString.TAG, null, new Byte[]{0x30, 0x03, 0x01, 0x01, -1}));
assertArrayEquals(ObjectIdentifier.OID_BASIC_CONSTRAINTS, ext.getExtnId().getInts());
assertTrue(ext.getCritical().getValue());
- assertArrayEquals(new Byte[]{ 0x30, 0x03, 0x01, 0x01, -1 }, ext.getExtnValue().getBytes());
+ assertArrayEquals(new Byte[]{0x30, 0x03, 0x01, 0x01, -1}, ext.getExtnValue().getBytes());
}
@Test
@@ -44,16 +44,16 @@ public class ExtensionTest {
Extension parsed = new Extension(new BytesReader(EXT_SUBJECT_KEY_ID), false);
assertArrayEquals(ObjectIdentifier.OID_SUBJECT_KEY_IDENTIFIER, parsed.getExtnId().getInts());
assertNull(parsed.getCritical());
- assertArrayEquals(new Byte[] {
- 0x04, 0x14, -79, -62, -89, -127, 0x63, 0x66,
- 0x4B, 0x72, 0x0A, -35, -3, 0x7D, 0x20, 0x29,
- -67, 0x6B, 0x49, 0x09, 0x61, -64
+ assertArrayEquals(new Byte[]{
+ 0x04, 0x14, -79, -62, -89, -127, 0x63, 0x66,
+ 0x4B, 0x72, 0x0A, -35, -3, 0x7D, 0x20, 0x29,
+ -67, 0x6B, 0x49, 0x09, 0x61, -64
}, parsed.getExtnValue().getBytes());
parsed = new Extension(new BytesReader(EXT_KEY_USAGE), false);
assertArrayEquals(ObjectIdentifier.OID_KEY_USAGE, parsed.getExtnId().getInts());
assertTrue(parsed.getCritical().getValue());
- assertArrayEquals(new Byte[] {
+ assertArrayEquals(new Byte[]{
0x03, 0x02, 0x01, -122
}, parsed.getExtnValue().getBytes());
}
@@ -68,7 +68,7 @@ public class ExtensionTest {
assertThrows(ParseException.class, () -> new Extension(new BytesReader(new Byte[]{
0x30, 0x0E, // SEQUENCE Extension
0x07, 0x03, 0x55, 0x1D, 0x0F, // OID keyUsage
- 0x01, 0x01, -1, // BOOLEAN critical
+ 0x01, 0x01, -1, // BOOLEAN critical
0x04, 0x04, // OCTET STRING
0x03, 0x02, 0x01, -122
}), false));
@@ -76,7 +76,7 @@ public class ExtensionTest {
assertThrows(ParseException.class, () -> new Extension(new BytesReader(new Byte[]{
0x30, 0x0E, // SEQUENCE Extension
0x06, 0x03, 0x55, 0x1D, 0x0F, // OID keyUsage
- 0x05, 0x01, -1, // BOOLEAN critical
+ 0x05, 0x01, -1, // BOOLEAN critical
0x04, 0x04, // OCTET STRING
0x03, 0x02, 0x01, -122
}), false));
@@ -84,7 +84,7 @@ public class ExtensionTest {
assertThrows(ParseException.class, () -> new Extension(new BytesReader(new Byte[]{
0x30, 0x0E, // SEQUENCE Extension
0x06, 0x03, 0x55, 0x1D, 0x0F, // OID keyUsage
- 0x01, 0x01, -1, // BOOLEAN critical
+ 0x01, 0x01, -1, // BOOLEAN critical
0x09, 0x04, // OCTET STRING
0x03, 0x02, 0x01, -122
}), false));
@@ -103,15 +103,15 @@ public class ExtensionTest {
assertArrayEquals(EXT_SUBJECT_KEY_ID, new Extension(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_SUBJECT_KEY_IDENTIFIER),
null,
- new OctetString(OctetString.TAG, null, new Byte[] {
- 0x04, 0x14, -79, -62, -89, -127, 0x63, 0x66,
- 0x4B, 0x72, 0x0A, -35, -3, 0x7D, 0x20, 0x29,
- -67, 0x6B, 0x49, 0x09, 0x61, -64
+ new OctetString(OctetString.TAG, null, new Byte[]{
+ 0x04, 0x14, -79, -62, -89, -127, 0x63, 0x66,
+ 0x4B, 0x72, 0x0A, -35, -3, 0x7D, 0x20, 0x29,
+ -67, 0x6B, 0x49, 0x09, 0x61, -64
})).encodeDER());
assertArrayEquals(EXT_KEY_USAGE, new Extension(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_KEY_USAGE),
new Bool(Bool.TAG, null, true),
- new OctetString(OctetString.TAG, null, new Byte[] {
+ new OctetString(OctetString.TAG, null, new Byte[]{
0x03, 0x02, 0x01, -122
})).encodeDER());
}
diff --git a/src/test/model/pki/cert/TbsCertificateTest.java b/src/test/model/pki/cert/TbsCertificateTest.java
index be26eb9..972f59a 100644
--- a/src/test/model/pki/cert/TbsCertificateTest.java
+++ b/src/test/model/pki/cert/TbsCertificateTest.java
@@ -1,9 +1,11 @@
package model.pki.cert;
-import model.asn1.*;
+import model.TestConstants;
+import model.asn1.ASN1Object;
+import model.asn1.Null;
+import model.asn1.ObjectIdentifier;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.TestConstants;
import org.junit.jupiter.api.Test;
import java.math.BigInteger;
@@ -52,13 +54,13 @@ public class TbsCertificateTest {
false);
assertEquals(TbsCertificate.VERSION_V3, parsed.getVersion().getLong());
assertEquals(0, parsed.getSerialNumber().getValue()
- .compareTo(new BigInteger("644983544608556543477205958886697401602227090424")));
+ .compareTo(new BigInteger("644983544608556543477205958886697401602227090424")));
assertArrayEquals(ObjectIdentifier.OID_ECDSA_WITH_SHA256,
parsed.getSignature().getType().getInts());
assertNull(parsed.getSignature().getParameters());
assertEquals("CN=Yuuta Root CA,C=CA", parsed.getIssuer().toString());
assertEquals(ZonedDateTime.of(2023, 6, 23,
- 2, 50, 46, 0, ZoneId.of("UTC")),
+ 2, 50, 46, 0, ZoneId.of("UTC")),
parsed.getValidity().getNotBefore().getTimestamp());
assertEquals(ZonedDateTime.of(2048, 6, 23,
2, 50, 46, 0, ZoneId.of("UTC")),
diff --git a/src/test/model/pki/cert/ValidityTest.java b/src/test/model/pki/cert/ValidityTest.java
index eba5092..2471ced 100644
--- a/src/test/model/pki/cert/ValidityTest.java
+++ b/src/test/model/pki/cert/ValidityTest.java
@@ -1,7 +1,9 @@
package model.pki.cert;
-import jdk.jshell.EvalException;
-import model.asn1.*;
+import model.asn1.ASN1Object;
+import model.asn1.ASN1Time;
+import model.asn1.GeneralizedTime;
+import model.asn1.UtcTime;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import org.junit.jupiter.api.BeforeEach;
@@ -81,7 +83,7 @@ public class ValidityTest {
// Too short
assertThrows(ParseException.class, () ->
- new Validity(new BytesReader(new Byte[] {
+ new Validity(new BytesReader(new Byte[]{
0x30, 0x0
}), false));
assertThrows(ParseException.class, () -> {
@@ -107,11 +109,11 @@ public class ValidityTest {
final Byte[] utcBytes = utc.encodeDER();
final Byte[] genBytes = gen.encodeDER();
- assertArrayEquals(Stream.of(Arrays.asList(new Byte[]{ 0x30, (byte) (utcBytes.length + genBytes.length) }),
- Arrays.asList(utcBytes),
- Arrays.asList(genBytes))
- .flatMap(Collection::stream)
- .toArray(Byte[]::new),
+ assertArrayEquals(Stream.of(Arrays.asList(new Byte[]{0x30, (byte) (utcBytes.length + genBytes.length)}),
+ Arrays.asList(utcBytes),
+ Arrays.asList(genBytes))
+ .flatMap(Collection::stream)
+ .toArray(Byte[]::new),
new Validity(ASN1Object.TAG_SEQUENCE, null, utc, gen)
.encodeDER());
}
diff --git a/src/test/model/pki/crl/CertificateListContentTest.java b/src/test/model/pki/crl/CertificateListContentTest.java
index ec18629..948df35 100644
--- a/src/test/model/pki/crl/CertificateListContentTest.java
+++ b/src/test/model/pki/crl/CertificateListContentTest.java
@@ -1,18 +1,9 @@
package model.pki.crl;
-import model.TestConstants;
-import model.asn1.*;
-import model.asn1.exceptions.ParseException;
-import model.pki.AlgorithmIdentifier;
-import model.x501.AttributeTypeAndValue;
-import model.x501.Name;
-import model.x501.RelativeDistinguishedName;
-import org.junit.jupiter.api.BeforeEach;
+import model.asn1.GeneralizedTime;
+import model.asn1.ObjectIdentifier;
import org.junit.jupiter.api.Test;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-
import static model.TestConstants.*;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/model/pki/crl/CertificateListTest.java b/src/test/model/pki/crl/CertificateListTest.java
index 0f4f06c..c117c16 100644
--- a/src/test/model/pki/crl/CertificateListTest.java
+++ b/src/test/model/pki/crl/CertificateListTest.java
@@ -5,17 +5,13 @@ import model.asn1.ASN1Object;
import model.asn1.BitString;
import model.asn1.Null;
import model.asn1.ObjectIdentifier;
-import model.asn1.exceptions.ParseException;
-import model.asn1.parsing.BytesReader;
import model.pki.AlgorithmIdentifier;
-import model.pki.cert.Certificate;
-import model.pki.cert.TbsCertificate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static model.TestConstants.combine;
-import static model.TestConstants.mutate;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class CertificateListTest {
private CertificateList crl;
@@ -27,7 +23,7 @@ public class CertificateListTest {
new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_RSA_ENCRYPTION),
new Null(Null.TAG, null)),
- new BitString(BitString.TAG, null, 0, new Byte[]{ 1, 2, 3 }));
+ new BitString(BitString.TAG, null, 0, new Byte[]{1, 2, 3}));
}
@Test
@@ -35,18 +31,18 @@ public class CertificateListTest {
assertEquals(2, crl.getCrl().getRevokedCertificates().length);
assertArrayEquals(ObjectIdentifier.OID_RSA_ENCRYPTION,
crl.getSignatureAlgorithm().getType().getInts());
- assertArrayEquals(new Byte[]{ 1, 2, 3 },
+ assertArrayEquals(new Byte[]{1, 2, 3},
crl.getSignature().getConvertedVal());
}
@Test
void testEncode() {
assertArrayEquals(combine((byte) 0x30,
- TestConstants.CRL_CONTENT_1_DER,
- new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
- new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_RSA_ENCRYPTION),
- new Null(Null.TAG, null)).encodeDER(),
- new BitString(BitString.TAG, null, 0, new Byte[]{ 1, 2, 3 }).encodeDER()),
+ TestConstants.CRL_CONTENT_1_DER,
+ new AlgorithmIdentifier(ASN1Object.TAG_SEQUENCE, null,
+ new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_RSA_ENCRYPTION),
+ new Null(Null.TAG, null)).encodeDER(),
+ new BitString(BitString.TAG, null, 0, new Byte[]{1, 2, 3}).encodeDER()),
crl.encodeDER());
}
}
diff --git a/src/test/model/pki/crl/RevokedCertificateTest.java b/src/test/model/pki/crl/RevokedCertificateTest.java
index 659e421..744e578 100644
--- a/src/test/model/pki/crl/RevokedCertificateTest.java
+++ b/src/test/model/pki/crl/RevokedCertificateTest.java
@@ -1,14 +1,11 @@
package model.pki.crl;
-import model.asn1.*;
-import org.junit.jupiter.api.BeforeEach;
+import model.asn1.UtcTime;
import org.junit.jupiter.api.Test;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-
import static model.TestConstants.*;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class RevokedCertificateTest {
@Test
diff --git a/src/test/model/x501/AttributeTypeAndValueTest.java b/src/test/model/x501/AttributeTypeAndValueTest.java
index ea9c17e..7739e55 100644
--- a/src/test/model/x501/AttributeTypeAndValueTest.java
+++ b/src/test/model/x501/AttributeTypeAndValueTest.java
@@ -32,8 +32,8 @@ public class AttributeTypeAndValueTest {
0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x49, 0x54
}), false).getType().getInts());
assertEquals("IT", ((PrintableString) new AttributeTypeAndValue(new BytesReader(new Byte[]{
- 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x49, 0x54
- }), false).getValue()).getString());
+ 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x49, 0x54
+ }), false).getValue()).getString());
// CN = Test ed25519
assertArrayEquals(OID_CN, new AttributeTypeAndValue(new BytesReader(new Byte[]{
diff --git a/src/test/model/x501/NameTest.java b/src/test/model/x501/NameTest.java
index c649798..22307f2 100644
--- a/src/test/model/x501/NameTest.java
+++ b/src/test/model/x501/NameTest.java
@@ -1,8 +1,8 @@
package model.x501;
+import model.TestConstants;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.TestConstants;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/model/x501/RelativeDistinguishedNameTest.java b/src/test/model/x501/RelativeDistinguishedNameTest.java
index d066010..8d92357 100644
--- a/src/test/model/x501/RelativeDistinguishedNameTest.java
+++ b/src/test/model/x501/RelativeDistinguishedNameTest.java
@@ -1,13 +1,14 @@
package model.x501;
-import model.asn1.*;
+import model.TestConstants;
+import model.asn1.ASN1Object;
+import model.asn1.Null;
+import model.asn1.ObjectIdentifier;
+import model.asn1.PrintableString;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.TestConstants;
import org.junit.jupiter.api.Test;
-import java.util.Arrays;
-
import static model.asn1.ASN1Object.TAG_SET;
import static model.asn1.ObjectIdentifier.OID_C;
import static model.asn1.ObjectIdentifier.OID_OU;
@@ -48,13 +49,13 @@ public class RelativeDistinguishedNameTest {
void testParseFail() {
// Invalid child tag
assertThrows(ParseException.class, () ->
- new RelativeDistinguishedName(new BytesReader(new Byte[] {
+ new RelativeDistinguishedName(new BytesReader(new Byte[]{
0x31, 0x0F,
0x31, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C,
0x06, 0x4D, 0x69, 0x6C, 0x61, 0x6E, 0x6F
}), false));
assertThrows(ParseException.class, () ->
- new RelativeDistinguishedName(new BytesReader(new Byte[] {
+ new RelativeDistinguishedName(new BytesReader(new Byte[]{
0x31, 0x23,
// CN
0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C,