Support ENUMERATED in client DER library

This commit is contained in:
2025-02-28 00:03:47 +00:00
parent 38ef12fa02
commit 90a6eb3ab4
4 changed files with 110 additions and 57 deletions

View File

@@ -98,6 +98,32 @@ static void test_utf8string_value(string expected, Datum datum) {
}
}
static void test_decode_enumerated(uint8[] bytes, int64 expected) {
Datum datum;
try {
datum = decode(bytes);
} catch (DecodeError err) {
Test.message("Decoding failed: %s", err.message);
Test.fail();
return;
}
test_enumerated_value(expected, datum);
}
static void test_enumerated_value(int64 expected, Datum datum) {
var enumerated = datum as Enumerated;
if (enumerated == null) {
Test.message("Bytes were not decoded as an ENUMERATED");
Test.fail();
return;
}
if (enumerated.value != expected) {
Test.message(@"Expected $expected got $(enumerated.value)");
Test.fail();
return;
}
}
void main(string[] args) {
Test.init(ref args);
@@ -184,6 +210,10 @@ void main(string[] args) {
test_encode(new Der.Null(), { 0x05, 0x00 });
});
Test.add_func("/encode/enumerated/42", () => {
test_encode(new Enumerated(42), {0x0a, 0x01, 0x2a});
});
/*
* Decoding
*/
@@ -310,6 +340,9 @@ void main(string[] args) {
}
});
Test.add_func("/decode/enumerated/42", () => {
test_decode_enumerated({0x0a, 0x01, 0x2a}, 42);
});
Test.run();
}