Add support for CHOICE to client DER encode/decode logic
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user