aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 06:17:57 +0800
committerYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 06:17:57 +0800
commitdf3eb7af36b6797e0c8e09a179191c329889da57 (patch)
treeb2119f13e57b2b391637f3e862b16bce3cd766a2 /src/main
parent6f82e5f3238bcc611354b20ed624d65759263032 (diff)
downloadjca-df3eb7af36b6797e0c8e09a179191c329889da57.tar
jca-df3eb7af36b6797e0c8e09a179191c329889da57.tar.gz
jca-df3eb7af36b6797e0c8e09a179191c329889da57.tar.bz2
jca-df3eb7af36b6797e0c8e09a179191c329889da57.zip
Fix coverage
Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/model/asn1/TagClass.java26
-rw-r--r--src/main/model/pki/cert/TbsCertificate.java6
2 files changed, 10 insertions, 22 deletions
diff --git a/src/main/model/asn1/TagClass.java b/src/main/model/asn1/TagClass.java
index 83dd4e9..2693512 100644
--- a/src/main/model/asn1/TagClass.java
+++ b/src/main/model/asn1/TagClass.java
@@ -7,10 +7,14 @@ package model.asn1;
* This class also represents the value to the two highest bits of DER-encoded tag values.
*/
public enum TagClass {
- UNIVERSAL(Values.UNIVERSAL),
- APPLICATION(Values.APPLICATION),
- PRIVATE(Values.PRIVATE),
- CONTEXT_SPECIFIC(Values.CONTENT_SPECIFIC);
+ // 0b00000000
+ UNIVERSAL((byte) 0x0),
+ // 0b01000000
+ APPLICATION((byte) 0x40),
+ // 0b11000000
+ PRIVATE((byte) -64),
+ // 0b10000000
+ CONTEXT_SPECIFIC((byte) -128);
private final Byte val;
@@ -25,18 +29,4 @@ public enum TagClass {
public Byte getVal() {
return val;
}
-
- /**
- * The constants of high-two-bit values for Tag DER encoding.
- */
- public static final class Values {
- // 0b00000000
- public static final Byte UNIVERSAL = 0x0;
- // 0b01000000
- public static final Byte APPLICATION = 0x40;
- // 0b11000000
- public static final Byte PRIVATE = -64;
- // 0b10000000
- public static final Byte CONTENT_SPECIFIC = -128;
- }
}
diff --git a/src/main/model/pki/cert/TbsCertificate.java b/src/main/model/pki/cert/TbsCertificate.java
index 84cf0ba..26b30f4 100644
--- a/src/main/model/pki/cert/TbsCertificate.java
+++ b/src/main/model/pki/cert/TbsCertificate.java
@@ -171,7 +171,7 @@ public class TbsCertificate extends ASN1Object {
} else {
// Enforce the extensions tag - nothing else should be here.
if (Integer.compareUnsigned(getLength(), (encoded.getIndex() - i)) != 0) {
- new Tag(encoded).enforce(new Tag(TagClass.CONTEXT_SPECIFIC, true, 3));
+ throw new ParseException("Unexpected objects after.");
}
this.extensions = null;
}
@@ -204,9 +204,7 @@ public class TbsCertificate extends ASN1Object {
*/
private void enforceVersion() throws ParseException {
if (version != null
- && (version.getLong() != VERSION_V1
- && version.getLong() != VERSION_V2
- && version.getLong() != VERSION_V3)) {
+ && (version.getLong() < VERSION_V1 || version.getLong() > VERSION_V3)) {
throw new ParseException("Illegal certificate version: " + version.getLong());
}
if (extensions != null && (version == null || version.getLong() != VERSION_V3)) {