| 37 | }; |
| 38 | |
| 39 | bool RunASN1TestSet(const ASN1_TestTuple asnTuples[], size_t count) |
| 40 | { |
| 41 | bool pass=true, fail; |
| 42 | |
| 43 | // Disposition |
| 44 | enum {REJECT=3, ACCEPT=4}; |
| 45 | |
| 46 | for(size_t i=0; i<count; i++) |
| 47 | { |
| 48 | const ASN1_TestTuple & thisTest = asnTuples[i]; |
| 49 | ArraySource as1((const byte*)thisTest.data, thisTest.len, true); |
| 50 | ArraySource as2((const byte*)thisTest.data, thisTest.len, true); |
| 51 | |
| 52 | SecByteBlock unused1; |
| 53 | std::string unused2; |
| 54 | unsigned int unused3; |
| 55 | word32 unused4; |
| 56 | word64 unused5; |
| 57 | |
| 58 | // Reporting |
| 59 | std::string val; |
| 60 | HexEncoder encoder(new StringSink(val)); |
| 61 | encoder.Put((const byte*)thisTest.data, thisTest.len); |
| 62 | encoder.MessageEnd(); |
| 63 | |
| 64 | try |
| 65 | { |
| 66 | int tag = thisTest.identifier; |
| 67 | switch (tag) |
| 68 | { |
| 69 | case BIT_STRING: |
| 70 | BERDecodeBitString(as1, unused1, unused3); |
| 71 | break; |
| 72 | |
| 73 | case OCTET_STRING: |
| 74 | BERDecodeOctetString(as1, unused1); |
| 75 | break; |
| 76 | |
| 77 | case INTEGER: |
| 78 | BERDecodeUnsigned(as1, unused4); |
| 79 | BERDecodeUnsigned<word64>(as2, unused5, byte(INTEGER), 0, W64LIT(0xffffffffffffffff)); |
| 80 | break; |
| 81 | |
| 82 | case UTF8_STRING: case PRINTABLE_STRING: case IA5_STRING: |
| 83 | BERDecodeTextString(as1, unused2, (byte)tag); |
| 84 | break; |
| 85 | |
| 86 | default: |
| 87 | BERGeneralDecoder(as1, (byte)tag); |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | fail = !(thisTest.disposition == ACCEPT); |
| 92 | } |
| 93 | catch(const Exception&) |
| 94 | { |
| 95 | fail = !(thisTest.disposition == REJECT); |
| 96 | } |