aboutsummaryrefslogtreecommitdiff
path: root/src/test/model/csr/AttributeTest.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/test/model/csr/AttributeTest.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/test/model/csr/AttributeTest.java')
-rw-r--r--src/test/model/csr/AttributeTest.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/test/model/csr/AttributeTest.java b/src/test/model/csr/AttributeTest.java
new file mode 100644
index 0000000..f4daa4c
--- /dev/null
+++ b/src/test/model/csr/AttributeTest.java
@@ -0,0 +1,53 @@
+package model.csr;
+
+import model.TestConstants;
+import model.asn1.exceptions.ParseException;
+import model.asn1.parsing.BytesReader;
+import org.junit.jupiter.api.Test;
+
+import static model.asn1.ObjectIdentifier.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class AttributeTest {
+ @Test
+ void testConstructor() throws ParseException {
+ assertArrayEquals(OID_EXTENSION_REQUEST, TestConstants.CSR_ATTR_2.getType().getInts());
+ assertEquals(0x21, TestConstants.CSR_ATTR_2.getValues().getArray()[1].getLength());
+ }
+
+ @Test
+ void testParse() throws ParseException {
+ final Attribute parsed = new Attribute(new BytesReader(TestConstants.CSR_ATTR_VALUES_2_DER), false);
+
+ assertArrayEquals(OID_EXTENSION_REQUEST, parsed.getType().getInts());
+ assertEquals(2, parsed.getValues().getArray().length);
+ }
+
+ @Test
+ void testParseFail() {
+ // No type
+ assertThrows(ParseException.class, () -> new Attribute(new BytesReader(new Byte[]{
+ 0x30, 0x0
+ }), false));
+ // No value
+ assertThrows(ParseException.class, () -> new Attribute(new BytesReader(new Byte[]{
+ 0x30, 0x5, 0x6, 0x3, 0x55, 0x4, 0x6
+ }), false));
+ // Incorrect type tag (should be OID)
+ assertThrows(ParseException.class, () -> new Attribute(new BytesReader(new Byte[]{
+ 0x30, 0x9, 0x7, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x49, 0x54
+ }), false));
+ // Incorrect value tag (should be SET)
+ assertThrows(ParseException.class, () -> new Attribute(new BytesReader(new Byte[]{
+ 0x30, 13,
+ 0x06, 0x09, 0x1A, -122, 0x48, -122, -9, 0x0D, 0x01, 0x09, 0x0E,
+ 0x30, 0
+ }), false));
+ }
+
+ @Test
+ void testEncode() {
+ assertArrayEquals(TestConstants.CSR_ATTR_1_DER, TestConstants.CSR_ATTR_1.encodeDER());
+ assertArrayEquals(TestConstants.CSR_ATTR_VALUES_2_DER, TestConstants.CSR_ATTR_2.encodeDER());
+ }
+}