From df3eb7af36b6797e0c8e09a179191c329889da57 Mon Sep 17 00:00:00 2001 From: Yuuta Liang Date: Sat, 14 Oct 2023 06:17:57 +0800 Subject: Fix coverage Signed-off-by: Yuuta Liang --- src/main/model/asn1/TagClass.java | 26 ++++++++------------------ src/main/model/pki/cert/TbsCertificate.java | 6 ++---- 2 files changed, 10 insertions(+), 22 deletions(-) (limited to 'src/main') 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)) { -- cgit v1.2.3