Fix CHOICE DER support
This commit is contained in:
parent
18541786e1
commit
10560371ab
@ -48,7 +48,7 @@ namespace StudySystemClient.Der {
|
|||||||
|
|
||||||
private static Datum decode_datum(uint8 type, uint8[] content)
|
private static Datum decode_datum(uint8 type, uint8[] content)
|
||||||
throws DecodeError {
|
throws DecodeError {
|
||||||
if ((type & 0xc0) == Choice.BASE_TYPE)
|
if ((type & ~Choice.ID_MASK) == Choice.BASE_TYPE)
|
||||||
return new Choice.from_content(type, content);
|
return new Choice.from_content(type, content);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Boolean.TYPE:
|
case Boolean.TYPE:
|
||||||
@ -266,7 +266,8 @@ namespace StudySystemClient.Der {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Choice : Datum {
|
public class Choice : Datum {
|
||||||
internal const uint8 BASE_TYPE = 0x80;
|
internal const uint8 BASE_TYPE = 0xa0;
|
||||||
|
internal const uint8 ID_MASK = 0x1f;
|
||||||
|
|
||||||
public int id { get; private set; }
|
public int id { get; private set; }
|
||||||
public Datum value { get; private set; }
|
public Datum value { get; private set; }
|
||||||
@ -282,7 +283,7 @@ namespace StudySystemClient.Der {
|
|||||||
throws DecodeError {
|
throws DecodeError {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
content = bytes;
|
content = bytes;
|
||||||
id = type & 0x3f;
|
id = type & ID_MASK;
|
||||||
value = decode(bytes);
|
value = decode(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ void main(string[] args) {
|
|||||||
Test.add_func("/encode/choice/1:foo", () => {
|
Test.add_func("/encode/choice/1:foo", () => {
|
||||||
var choice = new Der.Choice(1, new Utf8String("foo"));
|
var choice = new Der.Choice(1, new Utf8String("foo"));
|
||||||
var expected = new uint8[] {
|
var expected = new uint8[] {
|
||||||
0x81, 0x05, 0x0c, 0x03, 0x66, 0x6f, 0x6f
|
0xa1, 0x05, 0x0c, 0x03, 0x66, 0x6f, 0x6f
|
||||||
};
|
};
|
||||||
test_encode(choice, expected);
|
test_encode(choice, expected);
|
||||||
});
|
});
|
||||||
@ -266,7 +266,7 @@ void main(string[] args) {
|
|||||||
Test.add_func("/decode/choice/1:foo", () => {
|
Test.add_func("/decode/choice/1:foo", () => {
|
||||||
var expected_id = 1;
|
var expected_id = 1;
|
||||||
var bytes = new uint8[] {
|
var bytes = new uint8[] {
|
||||||
0x81, 0x05, 0x0c, 0x03, 0x66, 0x6f, 0x6f
|
0xa1, 0x05, 0x0c, 0x03, 0x66, 0x6f, 0x6f
|
||||||
};
|
};
|
||||||
Der.Choice choice;
|
Der.Choice choice;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user