aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/asn1/TagClass.java
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-12 12:10:33 +0800
committerYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-12 12:10:33 +0800
commitd342a45d98c4795b3a3fe1aaef5236ad4a782b55 (patch)
treef4ebc0ad962b138d9371413fcc71c97a559df506 /src/main/model/asn1/TagClass.java
parente60c9c76243cfe0a408af98dc60bedb973e815db (diff)
downloadjca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar
jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.gz
jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.bz2
jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.zip
Implement data structures from X.680, X.501, X.509, and PKCS#10, with X.690 encoding / decoding support
The implementation took four days, and it is still a little bit rough. Updated version should arrive soon. Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
Diffstat (limited to 'src/main/model/asn1/TagClass.java')
-rw-r--r--src/main/model/asn1/TagClass.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/model/asn1/TagClass.java b/src/main/model/asn1/TagClass.java
new file mode 100644
index 0000000..83dd4e9
--- /dev/null
+++ b/src/main/model/asn1/TagClass.java
@@ -0,0 +1,42 @@
+package model.asn1;
+
+/**
+ * Represents the class (UNIVERSAL, APPLICATION, PRIVATE, CONTEXT-SPECIFIC) of an ASN.1 tag. See X.680$8.1.
+ * The purpose of UNIVERSAL, APPLICATION, PRIVATE, and CONTEXT_SPECIFIC can be found in X.680 spec.
+ * For example, UNIVERSAL means tags specified in the core ASN.1 spec.
+ * 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);
+
+ private final Byte val;
+
+ /**
+ * EFFECT: Constructs the tag class with the given DER tag byte value.
+ * REQUIRES: The Byte value must have low 6bits cleared.
+ */
+ TagClass(Byte val) {
+ this.val = val;
+ }
+
+ 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;
+ }
+}