aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md28
-rw-r--r--src/main/model/asn1/ASN1Length.java14
-rw-r--r--src/main/model/asn1/ASN1Object.java73
-rw-r--r--src/main/model/asn1/ASN1String.java15
-rw-r--r--src/main/model/asn1/ASN1Time.java10
-rw-r--r--src/main/model/asn1/BitString.java10
-rw-r--r--src/main/model/asn1/Bool.java10
-rw-r--r--src/main/model/asn1/GeneralizedTime.java8
-rw-r--r--src/main/model/asn1/IA5String.java10
-rw-r--r--src/main/model/asn1/Int.java10
-rw-r--r--src/main/model/asn1/Null.java6
-rw-r--r--src/main/model/asn1/ObjectIdentifier.java74
-rw-r--r--src/main/model/asn1/PrintableString.java8
-rw-r--r--src/main/model/asn1/Tag.java12
-rw-r--r--src/main/model/asn1/UTF8String.java5
-rw-r--r--src/main/model/asn1/UtcTime.java8
-rw-r--r--src/main/model/asn1/parsing/BytesReader.java8
-rw-r--r--src/main/model/ca/CACertificate.java54
-rw-r--r--src/main/model/ca/Template.java9
-rw-r--r--src/main/model/csr/Attribute.java16
-rw-r--r--src/main/model/csr/Attributes.java4
-rw-r--r--src/main/model/csr/CertificationRequest.java16
-rw-r--r--src/main/model/csr/CertificationRequestInfo.java18
-rw-r--r--src/main/model/csr/Values.java4
-rw-r--r--src/main/model/pki/AlgorithmIdentifier.java12
-rw-r--r--src/main/model/pki/SubjectPublicKeyInfo.java10
-rw-r--r--src/main/model/pki/cert/Certificate.java16
-rw-r--r--src/main/model/pki/cert/Extension.java20
-rw-r--r--src/main/model/pki/cert/Extensions.java5
-rw-r--r--src/main/model/pki/cert/TbsCertificate.java49
-rw-r--r--src/main/model/pki/cert/Validity.java12
-rw-r--r--src/main/model/pki/crl/CertificateList.java7
-rw-r--r--src/main/model/pki/crl/CertificateListContent.java14
-rw-r--r--src/main/model/pki/crl/RevokedCertificate.java20
-rw-r--r--src/main/model/x501/AttributeTypeAndValue.java13
-rw-r--r--src/main/model/x501/Name.java4
-rw-r--r--src/main/model/x501/RelativeDistinguishedName.java4
-rw-r--r--src/main/ui/IssueScreen.java1
-rw-r--r--src/main/ui/JCA.java68
-rw-r--r--src/main/ui/MainScreen.java12
-rw-r--r--src/main/ui/Utils.java8
-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
-rw-r--r--src/test/ui/UtilsTest.java28
-rw-r--r--tests/.gitignore7
77 files changed, 875 insertions, 901 deletions
diff --git a/README.md b/README.md
index 907ba30..ce16c92 100644
--- a/README.md
+++ b/README.md
@@ -30,25 +30,25 @@ proprietary).
As a user, I want to be able to:
1. Generate a CA cryptography key-pair and its corresponding X.509 certificate
-into the program and view it. The private key must not be displayed or exported
-in any format under any circumstances for security purposes.
+ into the program and view it. The private key must not be displayed or exported
+ in any format under any circumstances for security purposes.
2. Input CSRs, edit the certificate properties (e.g., subject, not before,
-not after, serial, key usage, extended key usage, X.509v3 extensions, etc.),
-sign it using the CA private key, and get the signed certificate in DER or
-PEM-encoded-DER formats; then add that certificate to the signed-certs list.
+ not after, serial, key usage, extended key usage, X.509v3 extensions, etc.),
+ sign it using the CA private key, and get the signed certificate in DER or
+ PEM-encoded-DER formats; then add that certificate to the signed-certs list.
3. List all the certificates this CA had signed, view their properties, and
-optionally revoke any of them with a corresponding PKCS#10 reason. The
-certificates must not be deleted from the list under any circumstances but
-only revoked because some future administrators or the legal team may need
-to audit it.
+ optionally revoke any of them with a corresponding PKCS#10 reason. The
+ certificates must not be deleted from the list under any circumstances but
+ only revoked because some future administrators or the legal team may need
+ to audit it.
4. Publish base CRLs.
5. Add, enable, disable, or remove custom certificate templates (also called
-policies) that constraints what each type of certificates can and cannot have
-and their properties (e.g., TLS server certificates vs user logon certificates
-must be different in many ways), and the user will be able to choose which
-template they use after CSR input.
+ policies) that constraints what each type of certificates can and cannot have
+ and their properties (e.g., TLS server certificates vs user logon certificates
+ must be different in many ways), and the user will be able to choose which
+ template they use after CSR input.
6. View audit logs like who did what at what time for legal audit uses. Audit
-log entries must never be deleted.
+ log entries must never be deleted.
For example, the user can add arbitrary number of `Cert`'s into a `CA`
container, upon each successful sign.
diff --git a/src/main/model/asn1/ASN1Length.java b/src/main/model/asn1/ASN1Length.java
index e85689c..913b35a 100644
--- a/src/main/model/asn1/ASN1Length.java
+++ b/src/main/model/asn1/ASN1Length.java
@@ -4,8 +4,6 @@ import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import ui.Utils;
-import java.util.Arrays;
-
/**
* Represents the Length part in DER encoding. It appears after Tag and before Value. It represents the length of the
* encoded Value in bytes.
@@ -31,11 +29,11 @@ public class ASN1Length implements Encodable {
/**
* EFFECTS: Parse the length from the given DER input.
- * Throws {@link ParseException} if the input is invalid:
- * - Indefinite length
- * - Not enough bytes
- * - Initial byte 0b11111111 (See X.690$8.1.3.5)
- * - Value too long (compliant to RFC but unsupported by this program): multibyte and # of bytes > 3
+ * Throws {@link ParseException} if the input is invalid:
+ * - Indefinite length
+ * - Not enough bytes
+ * - Initial byte 0b11111111 (See X.690$8.1.3.5)
+ * - Value too long (compliant to RFC but unsupported by this program): multibyte and # of bytes > 3
* MODIFIES: reader (bytes are read, at least one byte, at most 5 bytes)
*/
public ASN1Length(BytesReader reader) throws ParseException {
@@ -78,7 +76,7 @@ public class ASN1Length implements Encodable {
// DER prefers the shortest form.
if (length <= 127) {
// Possible in a single byte.
- return new Byte[]{ (byte) length };
+ return new Byte[]{(byte) length};
} else {
// Big-endian encoding of the length. DER uses big-endian.
final Byte[] lengthBytes = Utils.valToByte(length);
diff --git a/src/main/model/asn1/ASN1Object.java b/src/main/model/asn1/ASN1Object.java
index 9b4a98c..434a6c5 100644
--- a/src/main/model/asn1/ASN1Object.java
+++ b/src/main/model/asn1/ASN1Object.java
@@ -2,14 +2,10 @@ package model.asn1;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import ui.Utils;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
/**
* Represents an encode-able ASN.1 object. It can be a SEQUENCE, an INTEGER, an OID, or any other ASN.1 type.
@@ -50,9 +46,9 @@ public class ASN1Object implements Encodable {
* of the corresponding types. However, applications may use context-specific
* or private tags for corresponding fields, either implicitly encoded or explicitly encoded.
* REQUIRES: Three cases:
- * 1. No context-specific tag: parentTag must be null.
- * 2. Implicit encoding: parentTag must be null, and the tag must be CONTEXT_SPECIFIC.
- * 3. Explicit encoding: parentTag must be constructive and CONTEXT_SPECIFIC.
+ * 1. No context-specific tag: parentTag must be null.
+ * 2. Implicit encoding: parentTag must be null, and the tag must be CONTEXT_SPECIFIC.
+ * 3. Explicit encoding: parentTag must be constructive and CONTEXT_SPECIFIC.
*/
public ASN1Object(Tag tag, Tag parentTag) {
this.tag = tag;
@@ -66,13 +62,13 @@ public class ASN1Object implements Encodable {
* and value (length = 0 if no value in DER, but never null). It will fill the value and length but will not mark
* the value as read (only the tag will be marked). Subtypes are responsible for deserializing the values. This
* method is not appropriate for parsing an unknown input (use subtypes instead) since values will be left unread.
- * Throws {@link ParseException} if input is invalid:
- * The input data must have a valid
- * parentTag (optional) - parentLength (optional) - tag - length - value (optional).
- * The value must match the corresponding type (e.g., an INTEGER value cannot go to an OctetString type).
- * The value must be supported by the corresponding type (e.g., a Printable must only contain valid chars).
- * If parentTag presents, its class must be CONTEXT_SPECIFIC, and it must be constructive.
- * If parentLength presents, it must not be 0.
+ * Throws {@link ParseException} if input is invalid:
+ * The input data must have a valid
+ * parentTag (optional) - parentLength (optional) - tag - length - value (optional).
+ * The value must match the corresponding type (e.g., an INTEGER value cannot go to an OctetString type).
+ * The value must be supported by the corresponding type (e.g., a Printable must only contain valid chars).
+ * If parentTag presents, its class must be CONTEXT_SPECIFIC, and it must be constructive.
+ * If parentLength presents, it must not be 0.
* MODIFIES: this, encoded (bytes are read)
* REQUIRES: If hasParentTag is true, parentTag and parentLength must present. Otherwise, they must be null. Assumes
* that the length won't be lower than actual. Assumes parentLength = length(tag + length + value).
@@ -108,23 +104,34 @@ public class ASN1Object implements Encodable {
* if unrecognized or application-defined (SEQUENCE or SET). It will always mark anything to be read, including
* unrecognized type values. This method is appropriate to decode an unknown input stream into known or unknown
* types. All values will be read.
- * Throws {@link ParseException} if the input is invalid.
+ * Throws {@link ParseException} if the input is invalid.
* MODIFIES: encoded
*/
public static ASN1Object parse(BytesReader encoded, boolean hasParentTag) throws ParseException {
final Tag t = encoded.getTag(hasParentTag);
switch (t.getNumber()) {
- case 0x1: return new Bool(encoded, hasParentTag);
- case 0x2: return new Int(encoded, hasParentTag);
- case 0x3: return new BitString(encoded, hasParentTag);
- case 0x4: return new OctetString(encoded, hasParentTag);
- case 0x5: return new Null(encoded, hasParentTag);
- case 0x6: return new ObjectIdentifier(encoded, hasParentTag);
- case 0xC: return new UTF8String(encoded, hasParentTag);
- case 0x13: return new PrintableString(encoded, hasParentTag);
- case 0x16: return new IA5String(encoded, hasParentTag);
- case 0x17: return new UtcTime(encoded, hasParentTag);
- case 0x18: return new GeneralizedTime(encoded, hasParentTag);
+ case 0x1:
+ return new Bool(encoded, hasParentTag);
+ case 0x2:
+ return new Int(encoded, hasParentTag);
+ case 0x3:
+ return new BitString(encoded, hasParentTag);
+ case 0x4:
+ return new OctetString(encoded, hasParentTag);
+ case 0x5:
+ return new Null(encoded, hasParentTag);
+ case 0x6:
+ return new ObjectIdentifier(encoded, hasParentTag);
+ case 0xC:
+ return new UTF8String(encoded, hasParentTag);
+ case 0x13:
+ return new PrintableString(encoded, hasParentTag);
+ case 0x16:
+ return new IA5String(encoded, hasParentTag);
+ case 0x17:
+ return new UtcTime(encoded, hasParentTag);
+ case 0x18:
+ return new GeneralizedTime(encoded, hasParentTag);
default: {
ASN1Object object = new ASN1Object(encoded, hasParentTag);
// Mark as read unconditionally because there aren't any type handlers that read them.
@@ -139,16 +146,16 @@ public class ASN1Object implements Encodable {
* The encoding will result in:
* (Parent Tag)(Tag)(Length)(Value)
* Parent Tag - Only exists if the field has a context-specific parent tag number and use explicit tagging. In this
- * case, the parent tag is the tag supplied in the constructor. If the field uses implicit tag
- * encoding or does not have a context-specific tag number, this field does not exist. This field,
- * as specified in the REQUIRES clause in the constructor, is always constructive.
+ * case, the parent tag is the tag supplied in the constructor. If the field uses implicit tag
+ * encoding or does not have a context-specific tag number, this field does not exist. This field,
+ * as specified in the REQUIRES clause in the constructor, is always constructive.
* Parent Length - The length of the following (tag, length, and value). A detailed length description, see follows.
* Tag - The tag value.
* Length - The length of the value, in number of bytes. If the length is <= 127, it will contain only a single
- * byte of length value, with the highest bit cleared. If the length is > 127, the first length byte
- * will have its highest bit set, with the remaining bits representing how many bytes are needed to
- * store the length integer. Followed are the integer, in multiple bytes, representing the length. The
- * multibyte integer are encoded in big-endian.
+ * byte of length value, with the highest bit cleared. If the length is > 127, the first length byte
+ * will have its highest bit set, with the remaining bits representing how many bytes are needed to
+ * store the length integer. Followed are the integer, in multiple bytes, representing the length. The
+ * multibyte integer are encoded in big-endian.
* Value - The value, with a total length (in bytes) corresponding to the Length field.
* REQUIRES: encodeValueDER() != null
*/
diff --git a/src/main/model/asn1/ASN1String.java b/src/main/model/asn1/ASN1String.java
index 148c564..ef7f07b 100644
--- a/src/main/model/asn1/ASN1String.java
+++ b/src/main/model/asn1/ASN1String.java
@@ -2,7 +2,6 @@ package model.asn1;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import ui.Utils;
import java.nio.charset.StandardCharsets;
@@ -15,8 +14,8 @@ public abstract class ASN1String extends ASN1Object {
/**
* EFFECTS: Constructs an ASN1String with the given tag, parent tag, and string.
- * - Throws {@link ParseException} if the string does not pass corresponding restrictions of the specific
- * string type (same as {@link ASN1String#validate(String)})
+ * - Throws {@link ParseException} if the string does not pass corresponding restrictions of the specific
+ * string type (same as {@link ASN1String#validate(String)})
* REQUIRES: For the requirements of tag and parentTag, consult {@link ASN1Object}.
*/
public ASN1String(Tag tag, Tag parentTag, String string) throws ParseException {
@@ -26,10 +25,10 @@ public abstract class ASN1String extends ASN1Object {
/**
* EFFECTS: Parse the input value. See {@link ASN1Object} with the rawString.
- * Throws {@link ParseException} when invalid:
- * - String does not pass type restrictions
- * - Early EOF
- * - Other cases as seen in {@link ASN1Object}
+ * Throws {@link ParseException} when invalid:
+ * - String does not pass type restrictions
+ * - Early EOF
+ * - Other cases as seen in {@link ASN1Object}
* MODIFIES: this, encoded (bytes are read)
*/
public ASN1String(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -38,7 +37,7 @@ public abstract class ASN1String extends ASN1Object {
/**
* EFFECTS: Validate and set the string.
- * Throws {@link ParseException} if the string is invalid.
+ * Throws {@link ParseException} if the string is invalid.
* MODIFIES: this
*/
protected void setString(String rawString) throws ParseException {
diff --git a/src/main/model/asn1/ASN1Time.java b/src/main/model/asn1/ASN1Time.java
index 08f861e..8f386f5 100644
--- a/src/main/model/asn1/ASN1Time.java
+++ b/src/main/model/asn1/ASN1Time.java
@@ -29,10 +29,10 @@ public abstract class ASN1Time extends ASN1Object {
/**
* EFFECTS: Parse and decode DER bytes into the corresponding time type. For more info on decoding, take a look at
* {@link ASN1Object}.
- * Throws {@link ParseException} if the input is invalid:
- * - Invalid date format
- * - Zero length
- * - Other circumstances (e.g., early EOF) as seen in {@link ASN1Object}
+ * Throws {@link ParseException} if the input is invalid:
+ * - Invalid date format
+ * - Zero length
+ * - Other circumstances (e.g., early EOF) as seen in {@link ASN1Object}
* MODIFIES: this, encoded
*/
public ASN1Time(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -50,7 +50,7 @@ public abstract class ASN1Time extends ASN1Object {
/**
* EFFECTS: Convert the given string into corresponding timestamp.
- * Throws {@link ParseException} if the time is malformed.
+ * Throws {@link ParseException} if the time is malformed.
*/
public abstract ZonedDateTime toDate(String str) throws ParseException;
diff --git a/src/main/model/asn1/BitString.java b/src/main/model/asn1/BitString.java
index 0561f24..3b4c32e 100644
--- a/src/main/model/asn1/BitString.java
+++ b/src/main/model/asn1/BitString.java
@@ -22,7 +22,7 @@ import java.math.BigInteger;
* 0b 00000110 01101110 01011101 11000000
* ^ 6 ^ ^ Original Number ^^Pad^
* </pre>
- *
+ * <p>
* BIT STRING has nothing to do with encoding bytes as printable strings (base10 or base16 or ASCII).
*/
public class BitString extends ASN1Object {
@@ -48,10 +48,10 @@ public class BitString extends ASN1Object {
/**
* EFFECT: Parse the input DER.
- * Throws {@link ParseException} if the input is invalid:
- * - Unused is not in 0 <= unused < 8
- * - The last byte does not have its lowest $unused bits zero
- * - Other issues found according to {@link ASN1Object}
+ * Throws {@link ParseException} if the input is invalid:
+ * - Unused is not in 0 <= unused < 8
+ * - The last byte does not have its lowest $unused bits zero
+ * - Other issues found according to {@link ASN1Object}
*/
public BitString(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
diff --git a/src/main/model/asn1/Bool.java b/src/main/model/asn1/Bool.java
index d9f1851..b400c7f 100644
--- a/src/main/model/asn1/Bool.java
+++ b/src/main/model/asn1/Bool.java
@@ -26,10 +26,10 @@ public class Bool extends ASN1Object {
/**
* EFFECTS: Parse input bytes. For more information on tags parsing, consult {@link ASN1Object}.
- * Throws {@link ParseException} if the input data is invalid:
- * - The length is not 1
- * - The value is neither 0x00 nor 0xFF
- * - Other cases as denoted in {@link ASN1Object}
+ * Throws {@link ParseException} if the input data is invalid:
+ * - The length is not 1
+ * - The value is neither 0x00 nor 0xFF
+ * - Other cases as denoted in {@link ASN1Object}
*/
public Bool(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
@@ -51,7 +51,7 @@ public class Bool extends ASN1Object {
*/
@Override
public Byte[] encodeValueDER() {
- return new Byte[]{ value ? (byte) -1 : 0 };
+ return new Byte[]{value ? (byte) -1 : 0};
}
public boolean getValue() {
diff --git a/src/main/model/asn1/GeneralizedTime.java b/src/main/model/asn1/GeneralizedTime.java
index 385642d..5482906 100644
--- a/src/main/model/asn1/GeneralizedTime.java
+++ b/src/main/model/asn1/GeneralizedTime.java
@@ -56,9 +56,9 @@ public class GeneralizedTime extends ASN1Time {
/**
* EFFECT: Parse the given DER input. Time will be assumed to be in UTC.
- * Throws {@link ParseException}:
- * - The time is not in the string format specified in class specification
- * - Other invalid input is found. See {@link ASN1Object} for more details on parsing
+ * Throws {@link ParseException}:
+ * - The time is not in the string format specified in class specification
+ * - Other invalid input is found. See {@link ASN1Object} for more details on parsing
*/
public GeneralizedTime(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
@@ -66,7 +66,7 @@ public class GeneralizedTime extends ASN1Time {
/**
* EFFECT: Parse the string into time, in the format specified in class specification.
- * Throws {@link ParseException} if the input is malformed.
+ * Throws {@link ParseException} if the input is malformed.
*/
@Override
public ZonedDateTime toDate(String str) throws ParseException {
diff --git a/src/main/model/asn1/IA5String.java b/src/main/model/asn1/IA5String.java
index ea5cf91..f8e9800 100644
--- a/src/main/model/asn1/IA5String.java
+++ b/src/main/model/asn1/IA5String.java
@@ -18,7 +18,7 @@ public class IA5String extends ASN1String {
/**
* EFFECTS: Constructs an IA5String with the given tag and string.
- * Throws {@link ParseException} if the string is invalid. It must only contain T.50 chars.
+ * Throws {@link ParseException} if the string is invalid. It must only contain T.50 chars.
* REQUIRES: For the requirements of tag and parentTag, consult {@link ASN1Object}.
*/
public IA5String(Tag tag, Tag parentTag, String string) throws ParseException {
@@ -28,10 +28,10 @@ public class IA5String extends ASN1String {
/**
* EFFECTS: Parse from user input. Tags are parsed as-per {@link ASN1Object}. The value will be parsed as UTF-8 big
* endian.
- * Throws {@link ParseException} if the encoded data is invalid:
- * - Illegal string (containing non-T.50 chars)
- * - Early EOF
- * - Other cases in {@link ASN1Object}
+ * Throws {@link ParseException} if the encoded data is invalid:
+ * - Illegal string (containing non-T.50 chars)
+ * - Early EOF
+ * - Other cases in {@link ASN1Object}
* MODIFIES: this, encoded
*/
public IA5String(BytesReader encoded, boolean hasParentTag) throws ParseException {
diff --git a/src/main/model/asn1/Int.java b/src/main/model/asn1/Int.java
index 4eeeedf..87f1505 100644
--- a/src/main/model/asn1/Int.java
+++ b/src/main/model/asn1/Int.java
@@ -41,10 +41,10 @@ public class Int extends ASN1Object {
/**
* EFFECTS: Parse input and get the int value. Tags are parsed in {@link ASN1Object}.
- * Throws {@link ParseException} if encoded value are invalid:
- * - Early EOF (not enough bytes)
- * - Zero bytes length
- * - Other issues denoted in {@link ASN1Object}
+ * Throws {@link ParseException} if encoded value are invalid:
+ * - Early EOF (not enough bytes)
+ * - Zero bytes length
+ * - Other issues denoted in {@link ASN1Object}
* MODIFIES: this, encoded
*/
public Int(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -78,7 +78,7 @@ public class Int extends ASN1Object {
/**
* EFFECTS: Get the value in long.
- * Throws {@link ArithmeticException} if the value is too large for long.
+ * Throws {@link ArithmeticException} if the value is too large for long.
*/
public long getLong() throws ArithmeticException {
return value.longValueExact();
diff --git a/src/main/model/asn1/Null.java b/src/main/model/asn1/Null.java
index 019db85..9045e14 100644
--- a/src/main/model/asn1/Null.java
+++ b/src/main/model/asn1/Null.java
@@ -24,9 +24,9 @@ public class Null extends ASN1Object {
/**
* EFFECTS: Parse input bytes. For more information on tags parsing, consult {@link ASN1Object}.
- * Throws {@link ParseException} if the input data is invalid:
- * - The length is not 0
- * - Other cases as denoted in {@link ASN1Object}
+ * Throws {@link ParseException} if the input data is invalid:
+ * - The length is not 0
+ * - Other cases as denoted in {@link ASN1Object}
*/
public Null(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
diff --git a/src/main/model/asn1/ObjectIdentifier.java b/src/main/model/asn1/ObjectIdentifier.java
index c7278db..f6e850a 100644
--- a/src/main/model/asn1/ObjectIdentifier.java
+++ b/src/main/model/asn1/ObjectIdentifier.java
@@ -5,8 +5,6 @@ import model.asn1.parsing.BytesReader;
import ui.Utils;
import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -20,49 +18,49 @@ public class ObjectIdentifier extends ASN1Object {
*/
public static final Tag TAG = new Tag(TagClass.UNIVERSAL, false, 0x6);
- public static final Integer[] OID_CN = new Integer[]{ 2, 5, 4, 3 };
- public static final Integer[] OID_SN = new Integer[]{ 2, 5, 4, 4 };
- public static final Integer[] OID_C = new Integer[]{ 2, 5, 4, 6 };
- public static final Integer[] OID_L = new Integer[]{ 2, 5, 4, 7 };
- public static final Integer[] OID_O = new Integer[]{ 2, 5, 4, 10 };
- public static final Integer[] OID_OU = new Integer[]{ 2, 5, 4, 11 };
- public static final Integer[] OID_DC = new Integer[]{ 0, 9, 2342, 19200300, 100, 1, 25 };
+ public static final Integer[] OID_CN = new Integer[]{2, 5, 4, 3};
+ public static final Integer[] OID_SN = new Integer[]{2, 5, 4, 4};
+ public static final Integer[] OID_C = new Integer[]{2, 5, 4, 6};
+ public static final Integer[] OID_L = new Integer[]{2, 5, 4, 7};
+ public static final Integer[] OID_O = new Integer[]{2, 5, 4, 10};
+ public static final Integer[] OID_OU = new Integer[]{2, 5, 4, 11};
+ public static final Integer[] OID_DC = new Integer[]{0, 9, 2342, 19200300, 100, 1, 25};
public static final Integer[] OID_EXTENSION_REQUEST =
- new Integer[]{ 1, 2, 840, 113549, 1, 9, 14 };
+ new Integer[]{1, 2, 840, 113549, 1, 9, 14};
public static final Integer[] OID_RSA_ENCRYPTION =
- new Integer[]{ 1, 2, 840, 113549, 1, 1, 1 };
+ new Integer[]{1, 2, 840, 113549, 1, 1, 1};
public static final Integer[] OID_SHA256_WITH_RSA_ENCRYPTION =
- new Integer[]{ 1, 2, 840, 113549, 1, 1, 11 };
+ new Integer[]{1, 2, 840, 113549, 1, 1, 11};
public static final Integer[] OID_EC_PUBLIC_KEY =
- new Integer[]{ 1, 2, 840, 10045, 2, 1 };
+ new Integer[]{1, 2, 840, 10045, 2, 1};
public static final Integer[] OID_ECDSA_WITH_SHA256 =
- new Integer[]{ 1, 2, 840, 10045, 4, 3, 2 };
+ new Integer[]{1, 2, 840, 10045, 4, 3, 2};
public static final Integer[] OID_ECDSA_WITH_SHA512 =
- new Integer[]{ 1, 2, 840, 10045, 4, 3, 4 };
+ new Integer[]{1, 2, 840, 10045, 4, 3, 4};
public static final Integer[] OID_PRIME256_V1 =
- new Integer[]{ 1, 2, 840, 10045, 3, 1, 7 };
+ new Integer[]{1, 2, 840, 10045, 3, 1, 7};
public static final Integer[] OID_SUBJECT_KEY_IDENTIFIER =
- new Integer[]{ 2, 5, 29, 14 };
+ new Integer[]{2, 5, 29, 14};
public static final Integer[] OID_KEY_USAGE =
- new Integer[]{ 2, 5, 29, 15 };
+ new Integer[]{2, 5, 29, 15};
public static final Integer[] OID_BASIC_CONSTRAINTS =
- new Integer[]{ 2, 5, 29, 19 };
+ new Integer[]{2, 5, 29, 19};
public static final Integer[] OID_AUTHORITY_KEY_IDENTIFIER =
- new Integer[]{ 2, 5, 29, 35 };
+ new Integer[]{2, 5, 29, 35};
public static final Integer[] OID_CRL_DISTRIBUTION_POINTS =
- new Integer[]{ 2, 5, 29, 31 };
+ new Integer[]{2, 5, 29, 31};
public static final Integer[] OID_AUTHORITY_INFO_ACCESS =
- new Integer[]{ 1, 3, 6, 1, 5, 5, 7, 1, 1 };
+ new Integer[]{1, 3, 6, 1, 5, 5, 7, 1, 1};
public static final Integer[] OID_CURVED_25519 =
- new Integer[]{ 1, 3, 101, 112 };
+ new Integer[]{1, 3, 101, 112};
public static final Integer[] OID_CRL_REASON =
- new Integer[]{ 2, 5, 29, 21 };
+ new Integer[]{2, 5, 29, 21};
private final Integer[] ints;
@@ -80,9 +78,9 @@ public class ObjectIdentifier extends ASN1Object {
/**
* EFFECTS: Parse the input DER.
- * Throws {@link ParseException} if the input is invalid:
- * - Zero bytes long
- * - A multibyte integer is unterminated until the end of input
+ * Throws {@link ParseException} if the input is invalid:
+ * - Zero bytes long
+ * - A multibyte integer is unterminated until the end of input
*/
public ObjectIdentifier(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
@@ -115,7 +113,7 @@ public class ObjectIdentifier extends ASN1Object {
List<BitSet> num = new ArrayList<>();
for (int i = 1; i < raw.length; i++) {
Byte b = raw[i];
- num.add(BitSet.valueOf(new byte[]{ (byte) (b & 127) }));
+ num.add(BitSet.valueOf(new byte[]{(byte) (b & 127)}));
if ((b & -128) == 0) {
BitSet bitSet = new BitSet(num.size() * 7);
int z = 0;
@@ -166,20 +164,20 @@ public class ObjectIdentifier extends ASN1Object {
/**
* EFFECTS: Encode the OID into DER bytes, following the DER rules as follows:
- * - First two ints: first * 40 + second
- * - Remaining: Int components are encoded as-is if they are <= 127. Otherwise, they are encoded into multiple 7bit
- * bytes, with the MSB set on every byte except for the last (rightmost byte) of each component.
- * - Integers are in big-endian.
+ * - First two ints: first * 40 + second
+ * - Remaining: Int components are encoded as-is if they are <= 127. Otherwise, they are encoded into multiple 7bit
+ * bytes, with the MSB set on every byte except for the last (rightmost byte) of each component.
+ * - Integers are in big-endian.
*/
@Override
public Byte[] encodeValueDER() {
return Stream.of(
- Arrays.asList(Utils.valToByte(ints[0] * 40 + ints[1])),
- Stream.of(ints)
- .skip(2)
- .map(ObjectIdentifier::encodeSingleInt)
- .flatMap(Collection::stream)
- .collect(Collectors.toList())
+ Arrays.asList(Utils.valToByte(ints[0] * 40 + ints[1])),
+ Stream.of(ints)
+ .skip(2)
+ .map(ObjectIdentifier::encodeSingleInt)
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList())
).flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/asn1/PrintableString.java b/src/main/model/asn1/PrintableString.java
index 73e33a6..b17ecbe 100644
--- a/src/main/model/asn1/PrintableString.java
+++ b/src/main/model/asn1/PrintableString.java
@@ -17,7 +17,7 @@ public class PrintableString extends ASN1String {
/**
* EFFECTS: Constructs with the given string.
- * Throws {@link ParseException} if the given string is illegal (contains chars out of the PrintableString set).
+ * Throws {@link ParseException} if the given string is illegal (contains chars out of the PrintableString set).
* REQUIRES: For the requirements of tag and parentTag, consult {@link ASN1Object}.
*/
public PrintableString(Tag tag, Tag parentTag, String rawString) throws ParseException {
@@ -27,9 +27,9 @@ public class PrintableString extends ASN1String {
/**
* EFFECTS: Parse from user input. Tags are parsed as-per {@link ASN1Object}. The value will be parsed as UTF-8 big
* endian.
- * Throws {@link ParseException} if the encoded data is invalid:
- * - Early EOF and other cases in {@link ASN1Object}
- * - Illegal string: Contains non-printable chars
+ * Throws {@link ParseException} if the encoded data is invalid:
+ * - Early EOF and other cases in {@link ASN1Object}
+ * - Illegal string: Contains non-printable chars
* MODIFIES: this, encoded
*/
public PrintableString(BytesReader encoded, boolean hasParentTag) throws ParseException {
diff --git a/src/main/model/asn1/Tag.java b/src/main/model/asn1/Tag.java
index 15c144f..7fb8ae4 100644
--- a/src/main/model/asn1/Tag.java
+++ b/src/main/model/asn1/Tag.java
@@ -25,9 +25,9 @@ public class Tag implements Encodable {
/**
* EFFECTS: Initialize the tag by parsing class / constructive / number from the encoded DER bytes.
- * {@link ParseException} is thrown if the input is invalid:
- * - The encoded array must have at least one byte.
- * - The tag number is zero if the class is UNIVERSAL.
+ * {@link ParseException} is thrown if the input is invalid:
+ * - The encoded array must have at least one byte.
+ * - The tag number is zero if the class is UNIVERSAL.
* REQUIRES: The highest two bits must contain the class, and then the constructive bit, and finally the low 5 bits
* must contain the tag number <= 31.
* MODIFIES: encoded (one byte read)
@@ -55,14 +55,14 @@ public class Tag implements Encodable {
if (this.cls == TagClass.UNIVERSAL && this.number == 0) {
throw new ParseException(String.format("The tag number must not be zero for UNIVERSAL tags"
- + "(byte 0x%02X @ %d)", val, encoded.getIndex()));
+ + "(byte 0x%02X @ %d)", val, encoded.getIndex()));
}
}
/**
* EFFECTS: Encode that tag as DER bytes, as follows:
* HI 7 6 | 5 | 4 3 2 1 0 LO
- * Class | C/P | Tag Number
+ * Class | C/P | Tag Number
* Notes, In the domain of this application (PKI), a single byte is always returned
* (as nothing requires high tag number). However, the return type is held as byte[]
* to 1) compliant with the spec, 2) reserve for future scalability.
@@ -79,7 +79,7 @@ public class Tag implements Encodable {
}
// Fill the high two bits with tag class
value |= cls.getVal();
- return new Byte[] { value };
+ return new Byte[]{value};
}
/**
diff --git a/src/main/model/asn1/UTF8String.java b/src/main/model/asn1/UTF8String.java
index e6b101e..932a415 100644
--- a/src/main/model/asn1/UTF8String.java
+++ b/src/main/model/asn1/UTF8String.java
@@ -5,7 +5,6 @@ import model.asn1.parsing.BytesReader;
import ui.Utils;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
/**
* Represents an ASN.1 UTF8String type. It accepts any UTF-8 chars. Because UTF-8 character set is large and its chars
@@ -19,7 +18,7 @@ public class UTF8String extends ASN1String {
/**
* EFFECTS: Constructs a UTF8String with the given tag and string.
- * Throws {@link ParseException} if the string is illegal.
+ * Throws {@link ParseException} if the string is illegal.
* REQUIRES: For the requirements of tag and parentTag, consult {@link ASN1Object}.
*/
public UTF8String(Tag tag, Tag parentTag, String string) throws ParseException {
@@ -29,7 +28,7 @@ public class UTF8String extends ASN1String {
/**
* EFFECTS: Parse from user input. Tags are parsed as-per {@link ASN1Object}. The value will be parsed as UTF-8 big
* endian.
- * Throws {@link ParseException} if the encoded data is invalid.
+ * Throws {@link ParseException} if the encoded data is invalid.
* MODIFIES: this, encoded
*/
public UTF8String(BytesReader encoded, boolean hasParentTag) throws ParseException, IllegalArgumentException {
diff --git a/src/main/model/asn1/UtcTime.java b/src/main/model/asn1/UtcTime.java
index 3acf524..7fa93d1 100644
--- a/src/main/model/asn1/UtcTime.java
+++ b/src/main/model/asn1/UtcTime.java
@@ -57,9 +57,9 @@ public class UtcTime extends ASN1Time {
/**
* EFFECT: Parse the given DER input. Time will be assumed to be in UTC.
- * Throws {@link ParseException} if invalid:
- * - The time is not in the string format specified in class specification
- * - Other invalid input is found. See {@link ASN1Object} for more details on parsing
+ * Throws {@link ParseException} if invalid:
+ * - The time is not in the string format specified in class specification
+ * - Other invalid input is found. See {@link ASN1Object} for more details on parsing
*/
public UtcTime(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
@@ -67,7 +67,7 @@ public class UtcTime extends ASN1Time {
/**
* EFFECT: Parse the string into time, in the format specified in class specification.
- * Throws {@link ParseException} if the input is malformed.
+ * Throws {@link ParseException} if the input is malformed.
*/
@Override
public ZonedDateTime toDate(String str) throws ParseException {
diff --git a/src/main/model/asn1/parsing/BytesReader.java b/src/main/model/asn1/parsing/BytesReader.java
index 3e11ea6..2a865d8 100644
--- a/src/main/model/asn1/parsing/BytesReader.java
+++ b/src/main/model/asn1/parsing/BytesReader.java
@@ -44,7 +44,7 @@ public class BytesReader {
/**
* EFFECTS: Copy the given number of bytes from [getIndex(), getIndex() + size) and optionally mark as read.
- * Throws {@link ParseException} if size > bytesRemaining().
+ * Throws {@link ParseException} if size > bytesRemaining().
* MODIFIES: this (if markAsRead == true)
* REQUIRES: size > 0
*/
@@ -55,7 +55,7 @@ public class BytesReader {
/**
* EFFECTS: Check if size <= bytesRemaining().
- * Throws {@link ParseException if not}.
+ * Throws {@link ParseException if not}.
* REQUIRES: size > 0
*/
public void validateSize(int size) throws ParseException {
@@ -69,7 +69,7 @@ public class BytesReader {
/**
* EFFECTS: Check if the next byte has the desired tag, without changing the index.
- * Throws {@link ParseException} if the input is illegal (not even a tag or EOF).
+ * Throws {@link ParseException} if the input is illegal (not even a tag or EOF).
*/
public boolean detectTag(Tag desired) throws ParseException {
final int i = index;
@@ -82,7 +82,7 @@ public class BytesReader {
/**
* EFFECTS: Get the current tag or the tag immediately following (inner) without changing the index.
- * Throws {@link ParseException} if the input is illegal (not even a tag or EOF).
+ * Throws {@link ParseException} if the input is illegal (not even a tag or EOF).
*/
public Tag getTag(boolean inner) throws ParseException {
final int i = index;
diff --git a/src/main/model/ca/CACertificate.java b/src/main/model/ca/CACertificate.java
index 36a9ac5..1bd53c9 100644
--- a/src/main/model/ca/CACertificate.java
+++ b/src/main/model/ca/CACertificate.java
@@ -5,8 +5,9 @@ import model.asn1.exceptions.ParseException;
import model.csr.*;
import model.pki.AlgorithmIdentifier;
import model.pki.SubjectPublicKeyInfo;
-import model.pki.cert.*;
import model.pki.cert.Certificate;
+import model.pki.cert.TbsCertificate;
+import model.pki.cert.Validity;
import model.pki.crl.CertificateList;
import model.pki.crl.CertificateListContent;
import model.pki.crl.RevokedCertificate;
@@ -17,12 +18,13 @@ import ui.Utils;
import java.math.BigInteger;
import java.security.*;
-import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
-import java.security.spec.RSAPrivateKeySpec;
import java.time.ZoneId;
import java.time.ZonedDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
import java.util.stream.Stream;
/**
@@ -57,7 +59,7 @@ public class CACertificate {
/**
* EFFECT: Init with a null key and null certificate, empty signed and revoked list, and serial at 1.
*/
- public CACertificate() {
+ public CACertificate() {
this.key = null;
this.certificate = null;
this.serial = 1;
@@ -79,11 +81,11 @@ public class CACertificate {
* EFFECT: Install the CA certificate.
* MODIFIES: this
* REQUIRES:
- * - The new certificate must have the same algorithm and public key as getPublicKey(), except for testing purpose
- * - It must be a v3 certificate
- * - It must have basicConstraints { cA = TRUE }
- * - It must contain key usage Digital Signature, Certificate Sign, CRL Sign
- * - getCertificate() must be null (i.e., no certificate is installed yet).
+ * - The new certificate must have the same algorithm and public key as getPublicKey(), except for testing purpose
+ * - It must be a v3 certificate
+ * - It must have basicConstraints { cA = TRUE }
+ * - It must contain key usage Digital Signature, Certificate Sign, CRL Sign
+ * - getCertificate() must be null (i.e., no certificate is installed yet).
*/
public void installCertificate(Certificate certificate) {
this.certificate = certificate;
@@ -109,7 +111,7 @@ public class CACertificate {
new Attribute[]{
new Attribute(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null,
- new Integer[]{ 1, 3, 6, 1, 4, 1, 311, 13, 2, 3 }),
+ new Integer[]{1, 3, 6, 1, 4, 1, 311, 13, 2, 3}),
new Values(ASN1Object.TAG_SET, null,
new ASN1Object[]{
new IA5String(IA5String.TAG, null,
@@ -200,26 +202,26 @@ public class CACertificate {
/**
* EFFECTS: Apply the template.
* For the new certificate:
- * - Issuer will be set to CA#getCertificate()#getSubject()
- * - The template will be applied (subject, validity, cdp)
- * - A serial number will be generated
+ * - Issuer will be set to CA#getCertificate()#getSubject()
+ * - The template will be applied (subject, validity, cdp)
+ * - A serial number will be generated
*/
private TbsCertificate generateCert(CertificationRequestInfo req, Template template) {
final ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
return new TbsCertificate(ASN1Object.TAG_SEQUENCE, null,
- new Int(Int.TAG, new Tag(TagClass.CONTEXT_SPECIFIC, true, 0),
- TbsCertificate.VERSION_V3),
- new Int(Int.TAG, null, serial++),
- getSigningAlgorithm(),
- certificate.getCertificate().getSubject(),
- new Validity(ASN1Object.TAG_SEQUENCE, null,
- new GeneralizedTime(GeneralizedTime.TAG, null, now),
- new UtcTime(UtcTime.TAG, null,
- now.plusDays(template.getValidity()))),
- template.getSubject() == null ? req.getSubject() :
+ new Int(Int.TAG, new Tag(TagClass.CONTEXT_SPECIFIC, true, 0),
+ TbsCertificate.VERSION_V3),
+ new Int(Int.TAG, null, serial++),
+ getSigningAlgorithm(),
+ certificate.getCertificate().getSubject(),
+ new Validity(ASN1Object.TAG_SEQUENCE, null,
+ new GeneralizedTime(GeneralizedTime.TAG, null, now),
+ new UtcTime(UtcTime.TAG, null,
+ now.plusDays(template.getValidity()))),
+ template.getSubject() == null ? req.getSubject() :
template.getSubject(),
- req.getSubjectPKInfo(),
- null);
+ req.getSubjectPKInfo(),
+ null);
}
/**
diff --git a/src/main/model/ca/Template.java b/src/main/model/ca/Template.java
index ff2510e..af751dc 100644
--- a/src/main/model/ca/Template.java
+++ b/src/main/model/ca/Template.java
@@ -1,14 +1,13 @@
package model.ca;
-import model.asn1.*;
+import model.asn1.ASN1Object;
+import model.asn1.ObjectIdentifier;
+import model.asn1.PrintableString;
import model.asn1.exceptions.ParseException;
-import model.pki.cert.TbsCertificate;
import model.x501.AttributeTypeAndValue;
import model.x501.Name;
import model.x501.RelativeDistinguishedName;
-import java.util.List;
-
/**
* Represents a certificate template. Certificate templates are like policies the define part of the issued certificates
* of what to have in common.
@@ -74,7 +73,7 @@ public class Template {
/**
* EFFECTS: Set the subject to CN=commonName,C=CA
- * Throws {@link ParseException} if commonName is not a valid PrintableString
+ * Throws {@link ParseException} if commonName is not a valid PrintableString
*/
public void setSubject(String commonName) throws ParseException {
if (commonName == null) {
diff --git a/src/main/model/csr/Attribute.java b/src/main/model/csr/Attribute.java
index 2fa319b..2daa000 100644
--- a/src/main/model/csr/Attribute.java
+++ b/src/main/model/csr/Attribute.java
@@ -18,7 +18,7 @@ import java.util.stream.Stream;
* values SET SIZE(1..MAX) OF ATTRIBUTE.&Type({IOSet}{@type})
* }
* </pre>
- *
+ * <p>
* Represents a key - values pair in the CSR attribute.
*/
public class Attribute extends ASN1Object {
@@ -38,7 +38,7 @@ public class Attribute extends ASN1Object {
* REQUIRES: The values must match the type. Type tag should be UNIVERSAL OID, and values should be SET OF.
*/
public Attribute(Tag tag, Tag parentTag,
- ObjectIdentifier type, Values values) {
+ ObjectIdentifier type, Values values) {
super(tag, parentTag);
this.type = type;
this.values = values;
@@ -46,11 +46,11 @@ public class Attribute extends ASN1Object {
/**
* EFFECTS: Parse input DER. Value is not checked against the type.
- * Throws {@link ASN1Object} if invalid:
- * - Any fields missing (info, algorithm, signature)
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ASN1Object} if invalid:
+ * - Any fields missing (info, algorithm, signature)
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public Attribute(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -68,7 +68,7 @@ public class Attribute extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(type.encodeDER()),
- Arrays.asList(values.encodeDER()))
+ Arrays.asList(values.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/csr/Attributes.java b/src/main/model/csr/Attributes.java
index 6819e71..302741d 100644
--- a/src/main/model/csr/Attributes.java
+++ b/src/main/model/csr/Attributes.java
@@ -31,13 +31,13 @@ public class Attributes extends ASN1Object {
/**
* EFFECT: Parse the list from input DER bytes. For details on parsing, refer to {@link ASN1Object}.
- * Throws {@link ParseException} for invalid input.
+ * Throws {@link ParseException} for invalid input.
* MODIFIES: this, encoded
*/
public Attributes(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
final List<Attribute> list = new ArrayList<>();
- for (int i = 0; i < getLength();) {
+ for (int i = 0; i < getLength(); ) {
int index = encoded.getIndex();
final Attribute attribute = new Attribute(encoded, false);
attribute.getTag().enforce(TAG_SEQUENCE);
diff --git a/src/main/model/csr/CertificationRequest.java b/src/main/model/csr/CertificationRequest.java
index c08997c..64203f9 100644
--- a/src/main/model/csr/CertificationRequest.java
+++ b/src/main/model/csr/CertificationRequest.java
@@ -20,7 +20,7 @@ import java.util.stream.Stream;
* signature BIT STRING
* }
* </pre>
- *
+ * <p>
* A CSR is used to request a certificate from a CA, using a public key. The client encodes a CSR with
* its subject name, public key, and attributes, and sign that with their private key. The private key
* must match the public key encoded in the CSR. This is to prove to the CA that the client has the private
@@ -65,11 +65,11 @@ public class CertificationRequest extends ASN1Object {
/**
* EFFECTS: Parse input DER CSR, without verifying the signature.
- * Throws {@link ParseException} if the input is invalid:
- * - Any fields missing (info, algorithm, signature)
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ParseException} if the input is invalid:
+ * - Any fields missing (info, algorithm, signature)
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public CertificationRequest(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -90,8 +90,8 @@ public class CertificationRequest extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(certificationRequestInfo.encodeDER()),
- Arrays.asList(signatureAlgorithm.encodeDER()),
- Arrays.asList(signature.encodeDER()))
+ Arrays.asList(signatureAlgorithm.encodeDER()),
+ Arrays.asList(signature.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/csr/CertificationRequestInfo.java b/src/main/model/csr/CertificationRequestInfo.java
index 425dba9..8f68ac8 100644
--- a/src/main/model/csr/CertificationRequestInfo.java
+++ b/src/main/model/csr/CertificationRequestInfo.java
@@ -28,7 +28,7 @@ import java.util.stream.Stream;
* }
*
* </pre>
- *
+ * <p>
* It represents all information of a CSR (version, subject, public key, attributes).
* It will be signed, and the signature is in {@link CertificationRequest}.
*/
@@ -71,11 +71,11 @@ public class CertificationRequestInfo extends ASN1Object {
/**
* EFFECTS: Parse the object with the given DER input.
- * Throws {@link ParseException} if the input is invalid:
- * - Any fields missing (version, subject, subjectPKInfo, attributes)
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ParseException} if the input is invalid:
+ * - Any fields missing (version, subject, subjectPKInfo, attributes)
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public CertificationRequestInfo(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -102,9 +102,9 @@ public class CertificationRequestInfo extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(version.encodeDER()),
- Arrays.asList(subject.encodeDER()),
- Arrays.asList(subjectPKInfo.encodeDER()),
- Arrays.asList(attributes.encodeDER()))
+ Arrays.asList(subject.encodeDER()),
+ Arrays.asList(subjectPKInfo.encodeDER()),
+ Arrays.asList(attributes.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/csr/Values.java b/src/main/model/csr/Values.java
index 5c1e212..f461686 100644
--- a/src/main/model/csr/Values.java
+++ b/src/main/model/csr/Values.java
@@ -36,13 +36,13 @@ public class Values extends ASN1Object {
/**
* EFFECT: Parse the list from input DER bytes. For details on parsing, refer to {@link ASN1Object}.
- * Throws {@link ParseException} for invalid input.
+ * Throws {@link ParseException} for invalid input.
* MODIFIES: this, encoded
*/
public Values(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
final List<ASN1Object> list = new ArrayList<>();
- for (int i = 0; i < getLength();) {
+ for (int i = 0; i < getLength(); ) {
int index = encoded.getIndex();
final ASN1Object value = ASN1Object.parse(encoded, false);
list.add(value);
diff --git a/src/main/model/pki/AlgorithmIdentifier.java b/src/main/model/pki/AlgorithmIdentifier.java
index 421aa5a..f7df59f 100644
--- a/src/main/model/pki/AlgorithmIdentifier.java
+++ b/src/main/model/pki/AlgorithmIdentifier.java
@@ -63,11 +63,11 @@ public class AlgorithmIdentifier extends ASN1Object {
/**
* EFFECTS: Parse input DER. Parameters are not checked against the type.
- * Throws {@link ASN1Object} if invalid:
- * - Any fields missing
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ASN1Object} if invalid:
+ * - Any fields missing
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public AlgorithmIdentifier(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -90,7 +90,7 @@ public class AlgorithmIdentifier extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(type.encodeDER()),
- parameters == null ? Collections.<Byte>emptyList() : Arrays.asList(parameters.encodeDER()))
+ parameters == null ? Collections.<Byte>emptyList() : Arrays.asList(parameters.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/pki/SubjectPublicKeyInfo.java b/src/main/model/pki/SubjectPublicKeyInfo.java
index ac72055..ca3b997 100644
--- a/src/main/model/pki/SubjectPublicKeyInfo.java
+++ b/src/main/model/pki/SubjectPublicKeyInfo.java
@@ -46,11 +46,11 @@ public class SubjectPublicKeyInfo extends ASN1Object {
/**
* EFFECTS: Parse input DER.
- * Throws {@link ASN1Object} if invalid:
- * - Any fields missing (info, algorithm, signature)
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ASN1Object} if invalid:
+ * - Any fields missing (info, algorithm, signature)
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public SubjectPublicKeyInfo(BytesReader encoded, boolean hasParentTag) throws ParseException {
diff --git a/src/main/model/pki/cert/Certificate.java b/src/main/model/pki/cert/Certificate.java
index 4e6c291..25499e3 100644
--- a/src/main/model/pki/cert/Certificate.java
+++ b/src/main/model/pki/cert/Certificate.java
@@ -42,7 +42,7 @@ import java.util.stream.Stream;
* COMPONENTS OF SIGNATURE{ToBeSigned},
* ... }
* </pre>
- *
+ * <p>
* A certificate creates a binding between the proposed subject name and the public key. It is only valid once a trusted
* CA signs it. Relying parties only need to trust a single trust anchor (the Root CA), and all of its issued certs are
* trusted. This is done through the cert tree: each certificate contains the Issued By field, indicating the DN of the
@@ -82,11 +82,11 @@ public class Certificate extends ASN1Object {
/**
* EFFECTS: Parse input DER, without verifying the signature.
- * Throws {@link ParseException} if the input is invalid:
- * - Any fields missing
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ParseException} if the input is invalid:
+ * - Any fields missing
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public Certificate(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -107,8 +107,8 @@ public class Certificate extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(certificate.encodeDER()),
- Arrays.asList(signatureAlgorithm.encodeDER()),
- Arrays.asList(signature.encodeDER()))
+ Arrays.asList(signatureAlgorithm.encodeDER()),
+ Arrays.asList(signature.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/pki/cert/Extension.java b/src/main/model/pki/cert/Extension.java
index 0c104a4..9db83b2 100644
--- a/src/main/model/pki/cert/Extension.java
+++ b/src/main/model/pki/cert/Extension.java
@@ -62,13 +62,13 @@ public class Extension extends ASN1Object {
/**
* EFFECTS: Parse input DER.
- * Throws {@link ParseException} if the input is invalid:
- * - Any fields missing
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
- * Note that critical is optional, and if it does not exist, it will be left as null, and it should be treated as
- * false.
+ * Throws {@link ParseException} if the input is invalid:
+ * - Any fields missing
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Note that critical is optional, and if it does not exist, it will be left as null, and it should be treated as
+ * false.
* MODIFIES: this, encoded
*/
public Extension(BytesReader encoded, boolean hasParentType) throws ParseException {
@@ -92,9 +92,9 @@ public class Extension extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(extnId.encodeDER()),
- critical == null ? Collections.<Byte>emptyList() :
- Arrays.asList(critical.encodeDER()),
- Arrays.asList(extnValue.encodeDER()))
+ critical == null ? Collections.<Byte>emptyList() :
+ Arrays.asList(critical.encodeDER()),
+ Arrays.asList(extnValue.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/pki/cert/Extensions.java b/src/main/model/pki/cert/Extensions.java
index 780fa2c..72d641f 100644
--- a/src/main/model/pki/cert/Extensions.java
+++ b/src/main/model/pki/cert/Extensions.java
@@ -5,7 +5,6 @@ import model.asn1.Encodable;
import model.asn1.Tag;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.x501.RelativeDistinguishedName;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,13 +32,13 @@ public class Extensions extends ASN1Object {
/**
* EFFECT: Parse the Name from input DER bytes. For details on parsing, refer to {@link ASN1Object}.
- * Throws {@link ParseException} for invalid input.
+ * Throws {@link ParseException} for invalid input.
* MODIFIES: this, encoded
*/
public Extensions(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
final List<Extension> list = new ArrayList<>();
- for (int i = 0; i < getLength();) {
+ for (int i = 0; i < getLength(); ) {
int index = encoded.getIndex();
final Extension ext = new Extension(encoded, false);
ext.getTag().enforce(TAG_SEQUENCE);
diff --git a/src/main/model/pki/cert/TbsCertificate.java b/src/main/model/pki/cert/TbsCertificate.java
index ce228af..84cf0ba 100644
--- a/src/main/model/pki/cert/TbsCertificate.java
+++ b/src/main/model/pki/cert/TbsCertificate.java
@@ -1,6 +1,9 @@
package model.pki.cert;
-import model.asn1.*;
+import model.asn1.ASN1Object;
+import model.asn1.Int;
+import model.asn1.Tag;
+import model.asn1.TagClass;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import model.pki.AlgorithmIdentifier;
@@ -45,7 +48,7 @@ import java.util.stream.Stream;
* ID id-at-uniqueIdentifier }
* UniqueIdentifier ::= BIT STRING
* </pre>
- *
+ * <p>
* NOTE that subjectUniqueIdentifier and issuerUniqueIdentifier are not supported.
*/
public class TbsCertificate extends ASN1Object {
@@ -103,21 +106,21 @@ public class TbsCertificate extends ASN1Object {
/**
* EFFECTS: Init with the given parameters. For tag and parentTag, see {@link ASN1Object}.
* REQUIRES:
- * - Version must be V1, V2, or V3.
- * - {issuer,subject}UniqueIdentifier could be null.
- * - If {issuer,subject}UniqueIdentifier presents, version must be V2 or V3.
- * - Extensions could be null.
- * - If extensions presents, version must be V3.
- * - The signature should be valid.
- * - Field and Desired Tags:
- * version CONTEXT SPECIFIC 0 (EXPLICIT), INTEGER, OPTIONAL DEFAULT v1
- * serialNumber INTEGER
- * signature SEQUENCE
- * issuer SEQUENCE
- * validity SEQUENCE
- * subject SEQUENCE
- * subjectPublicKeyInfo SEQUENCE
- * extensions CONTEXT SPECIFIC 3 (EXPLICIT), SEQUENCE, OPTIONAL
+ * - Version must be V1, V2, or V3.
+ * - {issuer,subject}UniqueIdentifier could be null.
+ * - If {issuer,subject}UniqueIdentifier presents, version must be V2 or V3.
+ * - Extensions could be null.
+ * - If extensions presents, version must be V3.
+ * - The signature should be valid.
+ * - Field and Desired Tags:
+ * version CONTEXT SPECIFIC 0 (EXPLICIT), INTEGER, OPTIONAL DEFAULT v1
+ * serialNumber INTEGER
+ * signature SEQUENCE
+ * issuer SEQUENCE
+ * validity SEQUENCE
+ * subject SEQUENCE
+ * subjectPublicKeyInfo SEQUENCE
+ * extensions CONTEXT SPECIFIC 3 (EXPLICIT), SEQUENCE, OPTIONAL
*/
public TbsCertificate(Tag tag, Tag parentTag,
final Int version,
@@ -141,12 +144,12 @@ public class TbsCertificate extends ASN1Object {
/**
* EFFECTS: Parse input DER.
- * Throws {@link ASN1Object} if invalid:
- * - Any fields missing
- * - Any fields having an incorrect parent / inner tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - extensions are specified, but the version is v1 or v2
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ASN1Object} if invalid:
+ * - Any fields missing
+ * - Any fields having an incorrect parent / inner tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - extensions are specified, but the version is v1 or v2
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public TbsCertificate(BytesReader encoded, boolean hasParentTag) throws ParseException {
diff --git a/src/main/model/pki/cert/Validity.java b/src/main/model/pki/cert/Validity.java
index 76279ed..e83d326 100644
--- a/src/main/model/pki/cert/Validity.java
+++ b/src/main/model/pki/cert/Validity.java
@@ -49,11 +49,11 @@ public class Validity extends ASN1Object {
/**
* EFFECTS: Parse input DER.
- * Throws {@link ASN1Object} if invalid:
- * - Any fields missing (info, algorithm, signature)
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ASN1Object} if invalid:
+ * - Any fields missing (info, algorithm, signature)
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public Validity(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -80,7 +80,7 @@ public class Validity extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(notBefore.encodeDER()),
- Arrays.asList(notAfter.encodeDER()))
+ Arrays.asList(notAfter.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/pki/crl/CertificateList.java b/src/main/model/pki/crl/CertificateList.java
index 5142101..8729561 100644
--- a/src/main/model/pki/crl/CertificateList.java
+++ b/src/main/model/pki/crl/CertificateList.java
@@ -3,10 +3,7 @@ package model.pki.crl;
import model.asn1.ASN1Object;
import model.asn1.BitString;
import model.asn1.Tag;
-import model.asn1.exceptions.ParseException;
-import model.asn1.parsing.BytesReader;
import model.pki.AlgorithmIdentifier;
-import model.pki.cert.TbsCertificate;
import java.util.Arrays;
import java.util.Collection;
@@ -56,8 +53,8 @@ public class CertificateList extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(crl.encodeDER()),
- Arrays.asList(signatureAlgorithm.encodeDER()),
- Arrays.asList(signature.encodeDER()))
+ Arrays.asList(signatureAlgorithm.encodeDER()),
+ Arrays.asList(signature.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/pki/crl/CertificateListContent.java b/src/main/model/pki/crl/CertificateListContent.java
index c7e901d..4cc96fb 100644
--- a/src/main/model/pki/crl/CertificateListContent.java
+++ b/src/main/model/pki/crl/CertificateListContent.java
@@ -31,7 +31,7 @@ import java.util.stream.Stream;
* ...,
* crlExtensions [0] Extensions OPTIONAL }
* </pre>
- *
+ * <p>
* A CRL is a signed object published by the CA that revokes any certificates signed by this CA before their
* expiration. Relying-parties should check the CRL from corresponding CDPs to see if the certificate to check is
* already revoked.
@@ -70,12 +70,12 @@ public class CertificateListContent extends ASN1Object {
.flatMap(Arrays::stream)
.collect(Collectors.toList());
return Stream.of(Arrays.asList(version.encodeDER()),
- Arrays.asList(signature.encodeDER()),
- Arrays.asList(issuer.encodeDER()),
- Arrays.asList(thisUpdate.encodeDER()),
- nextUpdate == null ? Collections.<Byte>emptyList() : Arrays.asList(nextUpdate.encodeDER()),
- Arrays.asList(new Tag(TagClass.UNIVERSAL, true, 0x30).encodeDER()),
- Arrays.asList(new ASN1Length(itemsEncoded.size()).encodeDER()), itemsEncoded)
+ Arrays.asList(signature.encodeDER()),
+ Arrays.asList(issuer.encodeDER()),
+ Arrays.asList(thisUpdate.encodeDER()),
+ nextUpdate == null ? Collections.<Byte>emptyList() : Arrays.asList(nextUpdate.encodeDER()),
+ Arrays.asList(new Tag(TagClass.UNIVERSAL, true, 0x30).encodeDER()),
+ Arrays.asList(new ASN1Length(itemsEncoded.size()).encodeDER()), itemsEncoded)
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/pki/crl/RevokedCertificate.java b/src/main/model/pki/crl/RevokedCertificate.java
index 457ecb8..1f0afc1 100644
--- a/src/main/model/pki/crl/RevokedCertificate.java
+++ b/src/main/model/pki/crl/RevokedCertificate.java
@@ -38,22 +38,22 @@ public class RevokedCertificate extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
final Byte[] r = new OctetString(OctetString.TAG,
- null,
- new Byte[]{ 0x0A, 0x01, (byte) reason.getVal() })
- .encodeDER();
+ null,
+ new Byte[]{0x0A, 0x01, (byte) reason.getVal()})
+ .encodeDER();
final Byte[] oid = new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_CRL_REASON)
.encodeDER();
final Byte[] seqExt = Stream.of(Arrays.asList(TAG_SEQUENCE.encodeDER()),
- Arrays.asList(new ASN1Length(r.length + oid.length).encodeDER()),
- Arrays.asList(oid),
- Arrays.asList(r))
+ Arrays.asList(new ASN1Length(r.length + oid.length).encodeDER()),
+ Arrays.asList(oid),
+ Arrays.asList(r))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
return Stream.of(Arrays.asList(serialNumber.encodeDER()),
- Arrays.asList(revocationDate.encodeDER()),
- Arrays.asList(TAG_SEQUENCE.encodeDER()),
- Arrays.asList(new ASN1Length(seqExt.length).encodeDER()),
- Arrays.asList(seqExt))
+ Arrays.asList(revocationDate.encodeDER()),
+ Arrays.asList(TAG_SEQUENCE.encodeDER()),
+ Arrays.asList(new ASN1Length(seqExt.length).encodeDER()),
+ Arrays.asList(seqExt))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/x501/AttributeTypeAndValue.java b/src/main/model/x501/AttributeTypeAndValue.java
index d43d137..54b3352 100644
--- a/src/main/model/x501/AttributeTypeAndValue.java
+++ b/src/main/model/x501/AttributeTypeAndValue.java
@@ -5,7 +5,6 @@ import model.asn1.ObjectIdentifier;
import model.asn1.Tag;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
-import model.csr.Values;
import java.util.Arrays;
import java.util.Collection;
@@ -45,11 +44,11 @@ public class AttributeTypeAndValue extends ASN1Object {
/**
* EFFECTS: Parse input DER. Value is not checked against the type.
- * Throws {@link ASN1Object} if invalid:
- * - Any fields missing
- * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
- * - Any fields with encoding instructions that violate implicit / explicit encoding rules
- * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
+ * Throws {@link ASN1Object} if invalid:
+ * - Any fields missing
+ * - Any fields having an incorrect tag (as seen in the ASN.1 definition)
+ * - Any fields with encoding instructions that violate implicit / explicit encoding rules
+ * - Other issues found during parsing the object, like early EOF (see {@link ASN1Object})
* MODIFIES: this, encoded
*/
public AttributeTypeAndValue(BytesReader encoded, boolean hasParentTag) throws ParseException {
@@ -66,7 +65,7 @@ public class AttributeTypeAndValue extends ASN1Object {
@Override
public Byte[] encodeValueDER() {
return Stream.of(Arrays.asList(type.encodeDER()),
- Arrays.asList(value.encodeDER()))
+ Arrays.asList(value.encodeDER()))
.flatMap(Collection::stream)
.toArray(Byte[]::new);
}
diff --git a/src/main/model/x501/Name.java b/src/main/model/x501/Name.java
index dd2acb6..19cde56 100644
--- a/src/main/model/x501/Name.java
+++ b/src/main/model/x501/Name.java
@@ -35,13 +35,13 @@ public class Name extends ASN1Object {
/**
* EFFECT: Parse the Name from input DER bytes. For details on parsing, refer to {@link ASN1Object}.
- * Throws {@link ParseException} for invalid input.
+ * Throws {@link ParseException} for invalid input.
* MODIFIES: this, encoded
*/
public Name(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
final List<RelativeDistinguishedName> list = new ArrayList<>();
- for (int i = 0; i < getLength();) {
+ for (int i = 0; i < getLength(); ) {
int index = encoded.getIndex();
final RelativeDistinguishedName name = new RelativeDistinguishedName(encoded, false);
name.getTag().enforce(TAG_SET);
diff --git a/src/main/model/x501/RelativeDistinguishedName.java b/src/main/model/x501/RelativeDistinguishedName.java
index 8edde09..c431f12 100644
--- a/src/main/model/x501/RelativeDistinguishedName.java
+++ b/src/main/model/x501/RelativeDistinguishedName.java
@@ -34,13 +34,13 @@ public class RelativeDistinguishedName extends ASN1Object {
/**
* EFFECT: Parse the list from input DER bytes. For details on parsing, refer to {@link ASN1Object}.
- * Throws {@link ParseException} for invalid input.
+ * Throws {@link ParseException} for invalid input.
* MODIFIES: this, encoded
*/
public RelativeDistinguishedName(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
final List<AttributeTypeAndValue> list = new ArrayList<>();
- for (int i = 0; i < getLength();) {
+ for (int i = 0; i < getLength(); ) {
int index = encoded.getIndex();
final AttributeTypeAndValue value = new AttributeTypeAndValue(encoded, false);
value.getTag().enforce(TAG_SEQUENCE);
diff --git a/src/main/ui/IssueScreen.java b/src/main/ui/IssueScreen.java
index e152b0d..93e1948 100644
--- a/src/main/ui/IssueScreen.java
+++ b/src/main/ui/IssueScreen.java
@@ -1,7 +1,6 @@
package ui;
import model.asn1.exceptions.ParseException;
-import model.asn1.parsing.BytesReader;
import model.ca.Template;
import model.csr.CertificationRequest;
import model.pki.cert.Certificate;
diff --git a/src/main/ui/JCA.java b/src/main/ui/JCA.java
index f9467ea..7892850 100644
--- a/src/main/ui/JCA.java
+++ b/src/main/ui/JCA.java
@@ -8,18 +8,16 @@ import model.ca.Template;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.time.ZonedDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Scanner;
/**
* Main program
*/
public class JCA {
/**
- * The current screen.
- */
- private UIHandler screen;
-
- /**
* Instances of the five screens;
*/
private final UIHandler mainScreen;
@@ -27,30 +25,30 @@ public class JCA {
private final UIHandler issueScreen;
private final UIHandler templatesScreen;
private final UIHandler templateSetScreen;
-
/**
* Templates
*/
private final List<Template> templates;
-
/**
* The CA
*/
private final CACertificate ca;
-
/**
* Audit logs
*/
private final List<AuditLogEntry> logs;
-
/**
* Current user
*/
private final String user;
+ /**
+ * The current screen.
+ */
+ private UIHandler screen;
/**
* EFFECTS: Init with main screen, empty templates, logs, user 'yuuta', and generate a private key with no CA cert.
- * Throws {@link NoSuchAlgorithmException} when crypto issue happens.
+ * Throws {@link NoSuchAlgorithmException} when crypto issue happens.
*/
public JCA() throws NoSuchAlgorithmException {
this.mainScreen = new MainScreen(this);
@@ -86,7 +84,7 @@ public class JCA {
/**
* EFFECTS: Read PEM from stdin, matched the given tag.
- * Throws {@link ParseException} if the input is incorrect.
+ * Throws {@link ParseException} if the input is incorrect.
*/
public Byte[] handleInputPEM(String desiredTag) throws ParseException {
final Scanner scanner = new Scanner(System.in);
@@ -144,24 +142,27 @@ public class JCA {
}
private void handleLine(String... args) {
- if (!args[0].isBlank()) {
- switch (args[0]) {
- case "help":
- screen.help();
- break;
- case "show":
- screen.show();
- break;
- case "commit":
- screen.commit();
- break;
- case "exit":
- setScreen(screen.exit());
- break;
- default:
- screen.command(args);
- break;
- }
+ if (args[0].equals("log")) {
+ getLogs().forEach(System.out::println);
+ return;
+ }
+ switch (args[0]) {
+ case "help":
+ screen.help();
+ System.out.println("log\tView audit logs");
+ break;
+ case "show":
+ screen.show();
+ break;
+ case "commit":
+ screen.commit();
+ break;
+ case "exit":
+ setScreen(screen.exit());
+ break;
+ default:
+ screen.command(args);
+ break;
}
printPS1();
}
@@ -185,7 +186,12 @@ public class JCA {
printPS1();
final Scanner scanner = new Scanner(System.in);
while (true) {
- handleLine(scanner.nextLine().split(" "));
+ String[] args = scanner.nextLine().split(" ");
+ if (args.length <= 0 || args[0].isBlank()) {
+ printPS1();
+ continue;
+ }
+ handleLine(args);
}
}
diff --git a/src/main/ui/MainScreen.java b/src/main/ui/MainScreen.java
index 69cb32c..f6abf8b 100644
--- a/src/main/ui/MainScreen.java
+++ b/src/main/ui/MainScreen.java
@@ -10,7 +10,10 @@ import model.pki.cert.Certificate;
import model.pki.crl.Reason;
import model.pki.crl.RevokedCertificate;
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Optional;
@@ -156,10 +159,6 @@ public class MainScreen implements UIHandler {
}
}
- private void handleLog() {
- session.getLogs().forEach(System.out::println);
- }
-
@Override
public void command(String... args) {
switch (args[0]) {
@@ -181,9 +180,6 @@ public class MainScreen implements UIHandler {
case "crl":
handleCRL();
return;
- case "log":
- handleLog();
- return;
}
help();
}
diff --git a/src/main/ui/Utils.java b/src/main/ui/Utils.java
index 3ed1300..6841536 100644
--- a/src/main/ui/Utils.java
+++ b/src/main/ui/Utils.java
@@ -4,11 +4,9 @@ import model.asn1.exceptions.ParseException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
/**
* Useful small methods for the whole program.
@@ -38,7 +36,7 @@ public final class Utils {
/**
* EFFECTS: Pack the big-endian bytes into a 32bit integer.
- * Throws {@link model.asn1.exceptions.ParseException} if the value is too large.
+ * Throws {@link model.asn1.exceptions.ParseException} if the value is too large.
*/
public static int bytesToInt(Byte[] array) throws ParseException {
try {
@@ -68,8 +66,8 @@ public final class Utils {
/**
* EFFECTS: Decode the input PEM file, with optional check on tags. \n must present after each line, optional after
* the last.
- * Throws {@link ParseException} if the desiredTag is specified but the input does not have the specific tag, or
- * if the input does not have any tags at all (not a PEM).
+ * Throws {@link ParseException} if the desiredTag is specified but the input does not have the specific tag, or
+ * if the input does not have any tags at all (not a PEM).
*/
public static Byte[] parsePEM(Byte[] input, String desiredTag) throws ParseException {
final String str = new String(byteToByte(input), StandardCharsets.UTF_8);
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,
diff --git a/src/test/ui/UtilsTest.java b/src/test/ui/UtilsTest.java
index a7b4a52..0b22286 100644
--- a/src/test/ui/UtilsTest.java
+++ b/src/test/ui/UtilsTest.java
@@ -11,28 +11,28 @@ import static org.junit.jupiter.api.Assertions.*;
public class UtilsTest {
@Test
void testByteToByte() {
- final byte[] primitive = new byte[]{ 1, 1, 4, 5, 1, 4 };
- final Byte[] boxed = new Byte[]{ 1, 1, 4, 5, 1, 4 };
+ final byte[] primitive = new byte[]{1, 1, 4, 5, 1, 4};
+ final Byte[] boxed = new Byte[]{1, 1, 4, 5, 1, 4};
assertArrayEquals(primitive, Utils.byteToByte(boxed));
assertArrayEquals(boxed, Utils.byteToByte(primitive));
}
@Test
void testBytesToInt() throws ParseException {
- assertEquals(1, Utils.bytesToInt(new Byte[]{ 1 }));
- assertEquals(257, Utils.bytesToInt(new Byte[]{ 1, 1 }));
- assertThrows(ParseException.class, () -> Utils.bytesToInt(new Byte[]{ 1, -1, -1, -1, -1 }));
+ assertEquals(1, Utils.bytesToInt(new Byte[]{1}));
+ assertEquals(257, Utils.bytesToInt(new Byte[]{1, 1}));
+ assertThrows(ParseException.class, () -> Utils.bytesToInt(new Byte[]{1, -1, -1, -1, -1}));
}
@Test
void testValToByte() {
- assertArrayEquals(new Byte[]{ 0 },
+ assertArrayEquals(new Byte[]{0},
Utils.valToByte(0));
- assertArrayEquals(new Byte[]{ 1 },
+ assertArrayEquals(new Byte[]{1},
Utils.valToByte(1));
- assertArrayEquals(new Byte[]{ 1, 1 },
+ assertArrayEquals(new Byte[]{1, 1},
Utils.valToByte(257));
- assertArrayEquals(new Byte[]{ -1 },
+ assertArrayEquals(new Byte[]{-1},
Utils.valToByte(-1));
}
@@ -40,8 +40,8 @@ public class UtilsTest {
void testParsePEM() throws ParseException {
assertArrayEquals(IntStream.range(0, 48).mapToObj(i -> (byte) 1).toArray(Byte[]::new),
Utils.parsePEM(Utils.byteToByte(("-----BEGIN BLABLA-----\n" +
- "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n" +
- "-----END BLABLA-----").getBytes(StandardCharsets.UTF_8)),
+ "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n" +
+ "-----END BLABLA-----").getBytes(StandardCharsets.UTF_8)),
"BLABLA"));
assertThrows(ParseException.class, () -> {
Utils.parsePEM(Utils.byteToByte(("-----BEGIN BLABLA-----\n" +
@@ -60,8 +60,8 @@ public class UtilsTest {
@Test
void testToPEM() {
assertEquals("-----BEGIN ABC-----\n" +
- "AQ==\n" +
- "-----END ABC-----",
- Utils.toPEM(new Byte[]{ 0x1 }, "ABC"));
+ "AQ==\n" +
+ "-----END ABC-----",
+ Utils.toPEM(new Byte[]{0x1}, "ABC"));
}
}
diff --git a/tests/.gitignore b/tests/.gitignore
index 237b712..507d98f 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1 +1,6 @@
-ca.key
+*.key
+*.crt
+*.txt*
+*.csr
+newcerts/
+serial