Add support for CHOICE to client DER encode/decode logic

This commit is contained in:
2025-02-25 18:17:30 +00:00
parent 046deccc26
commit 18541786e1
2 changed files with 61 additions and 3 deletions

View File

@@ -48,6 +48,8 @@ namespace StudySystemClient.Der {
private static Datum decode_datum(uint8 type, uint8[] content)
throws DecodeError {
if ((type & 0xc0) == Choice.BASE_TYPE)
return new Choice.from_content(type, content);
switch (type) {
case Boolean.TYPE:
return new Boolean.from_content(content);
@@ -262,4 +264,26 @@ namespace StudySystemClient.Der {
return elems.data;
}
}
public class Choice : Datum {
internal const uint8 BASE_TYPE = 0x80;
public int id { get; private set; }
public Datum value { get; private set; }
public Choice(int id, Datum val) {
type = BASE_TYPE | id;
content = val.encode();
this.id = id;
value = val;
}
internal Choice.from_content(uint8 type, uint8[] bytes)
throws DecodeError {
this.type = type;
content = bytes;
id = type & 0x3f;
value = decode(bytes);
}
}
}