From d342a45d98c4795b3a3fe1aaef5236ad4a782b55 Mon Sep 17 00:00:00 2001 From: Yuuta Liang Date: Thu, 12 Oct 2023 12:10:33 +0800 Subject: 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 --- src/test/model/asn1/BoolTest.java | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/model/asn1/BoolTest.java (limited to 'src/test/model/asn1/BoolTest.java') diff --git a/src/test/model/asn1/BoolTest.java b/src/test/model/asn1/BoolTest.java new file mode 100644 index 0000000..fed3152 --- /dev/null +++ b/src/test/model/asn1/BoolTest.java @@ -0,0 +1,45 @@ +package model.asn1; + +import model.asn1.exceptions.ParseException; +import model.asn1.parsing.BytesReader; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class BoolTest { + @Test + void testConstructor() { + assertTrue(new Bool(Bool.TAG, null, true).getValue()); + assertFalse(new Bool(Bool.TAG, null, false).getValue()); + } + + @Test + void testParse() throws ParseException { + assertFalse(new Bool(new BytesReader(new Byte[]{ 0x1, 1, 0 }), false) + .getValue()); + assertTrue(new Bool(new BytesReader(new Byte[]{ 0x1, 1, -1 }), false) + .getValue()); + } + + @Test + void testParseFail() throws ParseException { + assertThrows(ParseException.class, () -> + new Bool(new BytesReader(new Byte[]{ 0x1, 0 }), false)); + assertThrows(ParseException.class, () -> + new Bool(new BytesReader(new Byte[]{ 0x1, 1 }), false)); + assertThrows(ParseException.class, () -> + new Bool(new BytesReader(new Byte[]{ 0x1, 1, 1 }), false)); + assertThrows(ParseException.class, () -> + new Bool(new BytesReader(new Byte[]{ 0x1, 1, -2 }), false)); + assertThrows(ParseException.class, () -> + new Bool(new BytesReader(new Byte[]{ 0x1, 2, -1, 2 }), false)); + } + + @Test + void testEncode() { + assertArrayEquals(new Byte[]{ 0 }, + new Bool(Bool.TAG, null, false).encodeValueDER()); + assertArrayEquals(new Byte[]{ -1 }, + new Bool(Bool.TAG, null, true).encodeValueDER()); + } +} -- cgit v1.2.3