aboutsummaryrefslogtreecommitdiff
path: root/src/test/model/asn1/OctetStringTest.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/asn1/OctetStringTest.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/asn1/OctetStringTest.java')
-rw-r--r--src/test/model/asn1/OctetStringTest.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/model/asn1/OctetStringTest.java b/src/test/model/asn1/OctetStringTest.java
new file mode 100644
index 0000000..9e6e8a9
--- /dev/null
+++ b/src/test/model/asn1/OctetStringTest.java
@@ -0,0 +1,44 @@
+package model.asn1;
+
+import model.asn1.exceptions.ParseException;
+import model.asn1.parsing.BytesReader;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class OctetStringTest {
+ @Test
+ void testConstructor() {
+ assertArrayEquals(new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
+ new OctetString(OctetString.TAG, null, new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 })
+ .getBytes());
+ assertArrayEquals(new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
+ new OctetString(OctetString.TAG, null, new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 })
+ .encodeValueDER());
+ }
+
+ @Test
+ void testEncode() throws ParseException {
+ assertArrayEquals(new Byte[]{ 0x04, 0x06, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
+ new OctetString(OctetString.TAG, null, new Byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 })
+ .encodeDER());
+ }
+
+ @Test
+ void testParse() throws ParseException {
+ assertArrayEquals(new Byte[]{ 0x0A, 0x0B, 0x0C },
+ new OctetString(new BytesReader(new Byte[]{ 0x4, 3, 0x0A, 0x0B, 0x0C }), false)
+ .getBytes());
+ }
+
+ @Test
+ void testParseFail() {
+ // EOF
+ assertThrows(ParseException.class, () ->
+ new OctetString(new BytesReader(new Byte[]{ 0x4, 2, 0x0 }), false));
+ }
+}