aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/asn1
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 05:35:17 +0800
committerYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 05:35:17 +0800
commit28fa18278c1f3a87722d5e8b78f581526a30bb38 (patch)
tree2f23f6e2e222a78f40809ec37e8b28a29cba3d3c /src/main/model/asn1
parent0bcc057e741af3fbc108f42b75f9d42f48f6a51e (diff)
downloadjca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar.gz
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar.bz2
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.zip
Fix lint
Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
Diffstat (limited to 'src/main/model/asn1')
-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
16 files changed, 141 insertions, 140 deletions
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;