Whitespace check-in

pull/795/head
Jeffrey Walton 2019-01-21 22:16:49 -05:00
parent c62bf2b147
commit b8f7348c61
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 170 additions and 162 deletions

View File

@ -1251,48 +1251,56 @@ bool TestRounding()
#if defined(CRYPTOPP_EXTENDED_VALIDATION) #if defined(CRYPTOPP_EXTENDED_VALIDATION)
struct ASN1_TestTuple struct ASN1_TestTuple
{ {
ASN1_TestTuple(int _disposition, int _tag, const char* _data, size_t _len) { ASN1_TestTuple(int tag, int result, const char* data, size_t len) {
disposition = _disposition; m_result = result;
tag = _tag; m_tag = tag;
data = std::string(_data, _len); m_data = std::string(data, len);
} }
std::string Name() const { std::string Name() const {
return Id2String(); return Id2String();
} }
const byte* Data() const { const byte* Data() const {
return reinterpret_cast<const byte*>(&data[0]); return reinterpret_cast<const byte*>(&m_data[0]);
} }
size_t Size() const { size_t Size() const {
return data.size(); return m_data.size();
} }
std::string Id2String() const int Tag() const {
{ return m_tag;
switch(tag) }
{
case BIT_STRING:
return "BIT_STRING";
case OCTET_STRING:
return "OCTET_STRING";
case INTEGER:
return "INTEGER";
case UTF8_STRING:
return "UTF8_STRING";
case PRINTABLE_STRING:
return "PRINTABLE_STRING";
case IA5_STRING:
return "IA5_STRING";
default:
return "Unknown";
}
}
std::string data; int Result() const {
int disposition; return m_result;
int tag; }
std::string Id2String() const
{
switch(m_tag)
{
case BIT_STRING:
return "BIT_STRING";
case OCTET_STRING:
return "OCTET_STRING";
case INTEGER:
return "INTEGER";
case UTF8_STRING:
return "UTF8_STRING";
case PRINTABLE_STRING:
return "PRINTABLE_STRING";
case IA5_STRING:
return "IA5_STRING";
default:
return "Unknown";
}
}
protected:
std::string m_data;
int m_tag, m_result;
}; };
bool RunASN1TestSet(const ASN1_TestTuple asnTuples[], size_t count) bool RunASN1TestSet(const ASN1_TestTuple asnTuples[], size_t count)
@ -1322,7 +1330,7 @@ bool RunASN1TestSet(const ASN1_TestTuple asnTuples[], size_t count)
try try
{ {
int tag = thisTest.tag; byte tag = (byte)thisTest.Tag();
switch (tag) switch (tag)
{ {
case BIT_STRING: case BIT_STRING:
@ -1339,22 +1347,22 @@ bool RunASN1TestSet(const ASN1_TestTuple asnTuples[], size_t count)
break; break;
case UTF8_STRING: case PRINTABLE_STRING: case IA5_STRING: case UTF8_STRING: case PRINTABLE_STRING: case IA5_STRING:
BERDecodeTextString(as1, unused2, (byte)tag); BERDecodeTextString(as1, unused2, tag);
break; break;
default: default:
BERGeneralDecoder(as1, (byte)tag); BERGeneralDecoder(as1, tag);
break; break;
} }
fail = !(thisTest.disposition == ACCEPT); fail = thisTest.Result() != ACCEPT;
} }
catch(const Exception&) catch(const Exception&)
{ {
fail = !(thisTest.disposition == REJECT); fail = thisTest.Result() != REJECT;
} }
std::cout << (fail ? "FAILED:" : "passed:") << (thisTest.disposition == ACCEPT ? " accept " : " reject "); std::cout << (fail ? "FAILED:" : "passed:") << (thisTest.Result() == ACCEPT ? " accept " : " reject ");
std::cout << asnTuples[i].Name() << " " << val << "\n"; std::cout << asnTuples[i].Name() << " " << val << "\n";
pass = !fail && pass; pass = !fail && pass;
} }
@ -1377,25 +1385,25 @@ bool TestASN1Parse()
{ {
// The first "\x00" content octet is the "initial octet" representing unused bits. In the // The first "\x00" content octet is the "initial octet" representing unused bits. In the
// primitive encoding form, there may be zero, one or more contents after the initial octet. // primitive encoding form, there may be zero, one or more contents after the initial octet.
ASN1_TestTuple(ACCEPT, BIT_STRING, "\x03\x01" "\x00", 3), // definite length, short form, initial octet, zero subsequent octets ASN1_TestTuple(BIT_STRING, ACCEPT, "\x03\x01" "\x00", 3), // definite length, short form, initial octet, zero subsequent octets
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x01" "\x08", 3), // definite length, short form, initial octet, zero subsequent octets ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x01" "\x08", 3), // definite length, short form, initial octet, zero subsequent octets
ASN1_TestTuple(ACCEPT, BIT_STRING, "\x03\x02" "\x00" "C", 4), // definite length, short form, expected subsequent octets ASN1_TestTuple(BIT_STRING, ACCEPT, "\x03\x02" "\x00" "C", 4), // definite length, short form, expected subsequent octets
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x02" "\x08" "C", 4), // too many unused bits ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x02" "\x08" "C", 4), // too many unused bits
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x7F" "\x00" "C", 4), // runt or underrun ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x7F" "\x00" "C", 4), // runt or underrun
ASN1_TestTuple(ACCEPT, BIT_STRING, "\x03\x81\x01" "\x00", 4), // definite length, long form, initial octet, zero subsequent octets ASN1_TestTuple(BIT_STRING, ACCEPT, "\x03\x81\x01" "\x00", 4), // definite length, long form, initial octet, zero subsequent octets
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x81\x01" "\x08", 4), // definite length, long form, initial octet, zero subsequent octets ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x81\x01" "\x08", 4), // definite length, long form, initial octet, zero subsequent octets
ASN1_TestTuple(ACCEPT, BIT_STRING, "\x03\x81\x02" "\x00" "C", 5), // definite length, long form ASN1_TestTuple(BIT_STRING, ACCEPT, "\x03\x81\x02" "\x00" "C", 5), // definite length, long form
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x81\x02" "\x08" "C", 5), // too many unused bits ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x81\x02" "\x08" "C", 5), // too many unused bits
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x81\xff" "\x00" "C", 5), // runt or underrun ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x81\xff" "\x00" "C", 5), // runt or underrun
ASN1_TestTuple(ACCEPT, BIT_STRING, "\x03\x82\x00\x02" "\x00" "C", 6), // definite length, long form ASN1_TestTuple(BIT_STRING, ACCEPT, "\x03\x82\x00\x02" "\x00" "C", 6), // definite length, long form
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x82\x00\x02" "\x08" "C", 6), // too many unused bits ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x82\x00\x02" "\x08" "C", 6), // too many unused bits
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x82\xff\xff" "\x00" "C", 6), // runt or underrun ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x82\xff\xff" "\x00" "C", 6), // runt or underrun
ASN1_TestTuple(ACCEPT, BIT_STRING, "\x03\x83\x00\x00\x02" "\x00" "C", 7), // definite length, long form ASN1_TestTuple(BIT_STRING, ACCEPT, "\x03\x83\x00\x00\x02" "\x00" "C", 7), // definite length, long form
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x83\x00\x00\x02" "\x08" "C", 7), // too many unused bits ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x83\x00\x00\x02" "\x08" "C", 7), // too many unused bits
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x83\xff\xff\xff" "\x00" "C", 7), // runt or underrun ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x83\xff\xff\xff" "\x00" "C", 7), // runt or underrun
ASN1_TestTuple(ACCEPT, BIT_STRING, "\x03\x84\x00\x00\x00\x02" "\x00" "C", 8), // definite length, long form ASN1_TestTuple(BIT_STRING, ACCEPT, "\x03\x84\x00\x00\x00\x02" "\x00" "C", 8), // definite length, long form
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x84\x00\x00\x00\x02" "\x08" "C", 8), // too many unused bits ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x84\x00\x00\x00\x02" "\x08" "C", 8), // too many unused bits
ASN1_TestTuple(REJECT, BIT_STRING, "\x03\x84\xff\xff\xff\xff" "\x00" "C", 8), // <== Issue 346; requires large allocation ASN1_TestTuple(BIT_STRING, REJECT, "\x03\x84\xff\xff\xff\xff" "\x00" "C", 8), // <== Issue 346; requires large allocation
}; };
pass = RunASN1TestSet(bitStrings, COUNTOF(bitStrings)) && pass; pass = RunASN1TestSet(bitStrings, COUNTOF(bitStrings)) && pass;
@ -1403,104 +1411,104 @@ bool TestASN1Parse()
const ASN1_TestTuple octetStrings[] = const ASN1_TestTuple octetStrings[] =
{ {
// In the primitive encoding form, there may be zero, one or more contents. // In the primitive encoding form, there may be zero, one or more contents.
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x00", 2), // definite length, short form, zero content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x00", 2), // definite length, short form, zero content octets
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x01" "C", 3), // definite length, short form, expected content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x01" "C", 3), // definite length, short form, expected content octets
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x02" "C", 3), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x02" "C", 3), // runt or underrun
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x7F" "C", 3), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x7F" "C", 3), // runt or underrun
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x81\x00", 3), // definite length, long form, zero content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x81\x00", 3), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x81\x01" "C", 4), // definite length, long form, expected content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x81\x01" "C", 4), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x81\x02" "C", 4), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x81\x02" "C", 4), // runt or underrun
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x81\xff" "C", 4), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x81\xff" "C", 4), // runt or underrun
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x82\x00\x00", 4), // definite length, long form, zero content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x82\x00\x00", 4), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x82\x00\x01" "C", 5), // definite length, long form, expected content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x82\x00\x01" "C", 5), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x82\x00\x02" "C", 5), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x82\x00\x02" "C", 5), // runt or underrun
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x82\xff\xff" "C", 5), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x82\xff\xff" "C", 5), // runt or underrun
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x83\x00\x00\x00", 5), // definite length, long form, zero content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x83\x00\x00\x00", 5), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x83\x00\x00\x02" "C", 6), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x83\x00\x00\x02" "C", 6), // runt or underrun
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x83\xff\xff\xff" "C", 6), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x83\xff\xff\xff" "C", 6), // runt or underrun
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, OCTET_STRING, "\x04\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets ASN1_TestTuple(OCTET_STRING, ACCEPT, "\x04\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x84\x00\x00\x00\x02" "C", 7), // runt or underrun ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x84\x00\x00\x00\x02" "C", 7), // runt or underrun
ASN1_TestTuple(REJECT, OCTET_STRING, "\x04\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation ASN1_TestTuple(OCTET_STRING, REJECT, "\x04\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation
}; };
pass = RunASN1TestSet(octetStrings, COUNTOF(octetStrings)) && pass; pass = RunASN1TestSet(octetStrings, COUNTOF(octetStrings)) && pass;
const ASN1_TestTuple utf8Strings[] = const ASN1_TestTuple utf8Strings[] =
{ {
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x00", 2), // definite length, short form, zero content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x00", 2), // definite length, short form, zero content octets
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x01" "C", 3), // definite length, short form, expected content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x01" "C", 3), // definite length, short form, expected content octets
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x02" "C", 3), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x02" "C", 3), // runt or underrun
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x7F" "C", 3), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x7F" "C", 3), // runt or underrun
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x81\x00", 3), // definite length, long form, zero content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x81\x00", 3), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x81\x01" "C", 4), // definite length, long form, expected content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x81\x01" "C", 4), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x81\x02" "C", 4), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x81\x02" "C", 4), // runt or underrun
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x81\xff" "C", 4), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x81\xff" "C", 4), // runt or underrun
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x82\x00\x00", 4), // definite length, long form, zero content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x82\x00\x00", 4), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x82\x00\x01" "C", 5), // definite length, long form, expected content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x82\x00\x01" "C", 5), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x82\x00\x02" "C", 5), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x82\x00\x02" "C", 5), // runt or underrun
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x82\xff\xff" "C", 5), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x82\xff\xff" "C", 5), // runt or underrun
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x83\x00\x00\x00", 5), // definite length, long form, zero content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x83\x00\x00\x00", 5), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x83\x00\x00\x02" "C", 6), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x83\x00\x00\x02" "C", 6), // runt or underrun
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x83\xff\xff\xff" "C", 6), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x83\xff\xff\xff" "C", 6), // runt or underrun
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, UTF8_STRING, "\x0c\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets ASN1_TestTuple(UTF8_STRING, ACCEPT, "\x0c\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x84\x00\x00\x00\x02" "C", 7), // runt or underrun ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x84\x00\x00\x00\x02" "C", 7), // runt or underrun
ASN1_TestTuple(REJECT, UTF8_STRING, "\x0c\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation ASN1_TestTuple(UTF8_STRING, REJECT, "\x0c\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation
}; };
pass = RunASN1TestSet(utf8Strings, COUNTOF(utf8Strings)) && pass; pass = RunASN1TestSet(utf8Strings, COUNTOF(utf8Strings)) && pass;
const ASN1_TestTuple printableStrings[] = const ASN1_TestTuple printableStrings[] =
{ {
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x00", 2), // definite length, short form, zero content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x00", 2), // definite length, short form, zero content octets
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x01" "C", 3), // definite length, short form, expected content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x01" "C", 3), // definite length, short form, expected content octets
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x02" "C", 3), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x02" "C", 3), // runt or underrun
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x7F" "C", 3), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x7F" "C", 3), // runt or underrun
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x81\x00", 3), // definite length, long form, zero content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x81\x00", 3), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x81\x01" "C", 4), // definite length, long form, expected content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x81\x01" "C", 4), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x81\x02" "C", 4), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x81\x02" "C", 4), // runt or underrun
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x81\xff" "C", 4), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x81\xff" "C", 4), // runt or underrun
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x82\x00\x00", 4), // definite length, long form, zero content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x82\x00\x00", 4), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x82\x00\x01" "C", 5), // definite length, long form, expected content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x82\x00\x01" "C", 5), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x82\x00\x02" "C", 5), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x82\x00\x02" "C", 5), // runt or underrun
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x82\xff\xff" "C", 5), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x82\xff\xff" "C", 5), // runt or underrun
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x83\x00\x00\x00", 5), // definite length, long form, zero content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x83\x00\x00\x00", 5), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x83\x00\x00\x02" "C", 6), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x83\x00\x00\x02" "C", 6), // runt or underrun
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x83\xff\xff\xff" "C", 6), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x83\xff\xff\xff" "C", 6), // runt or underrun
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, PRINTABLE_STRING, "\x13\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets ASN1_TestTuple(PRINTABLE_STRING, ACCEPT, "\x13\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x84\x00\x00\x00\x02" "C", 7), // runt or underrun ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x84\x00\x00\x00\x02" "C", 7), // runt or underrun
ASN1_TestTuple(REJECT, PRINTABLE_STRING, "\x13\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation ASN1_TestTuple(PRINTABLE_STRING, REJECT, "\x13\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation
}; };
pass = RunASN1TestSet(printableStrings, COUNTOF(printableStrings)) && pass; pass = RunASN1TestSet(printableStrings, COUNTOF(printableStrings)) && pass;
const ASN1_TestTuple ia5Strings[] = const ASN1_TestTuple ia5Strings[] =
{ {
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x00", 2), // definite length, short form, zero content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x00", 2), // definite length, short form, zero content octets
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x01" "C", 3), // definite length, short form, expected content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x01" "C", 3), // definite length, short form, expected content octets
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x02" "C", 3), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x02" "C", 3), // runt or underrun
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x7F" "C", 3), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x7F" "C", 3), // runt or underrun
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x81\x00", 3), // definite length, long form, zero content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x81\x00", 3), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x81\x01" "C", 4), // definite length, long form, expected content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x81\x01" "C", 4), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x81\x02" "C", 4), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x81\x02" "C", 4), // runt or underrun
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x81\xff" "C", 4), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x81\xff" "C", 4), // runt or underrun
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x82\x00\x00", 4), // definite length, long form, zero content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x82\x00\x00", 4), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x82\x00\x01" "C", 5), // definite length, long form, expected content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x82\x00\x01" "C", 5), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x82\x00\x02" "C", 5), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x82\x00\x02" "C", 5), // runt or underrun
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x82\xff\xff" "C", 5), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x82\xff\xff" "C", 5), // runt or underrun
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x83\x00\x00\x00", 5), // definite length, long form, zero content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x83\x00\x00\x00", 5), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x83\x00\x00\x02" "C", 6), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x83\x00\x00\x02" "C", 6), // runt or underrun
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x83\xff\xff\xff" "C", 6), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x83\xff\xff\xff" "C", 6), // runt or underrun
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, IA5_STRING, "\x16\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets ASN1_TestTuple(IA5_STRING, ACCEPT, "\x16\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x84\x00\x00\x00\x02" "C", 7), // runt or underrun ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x84\x00\x00\x00\x02" "C", 7), // runt or underrun
ASN1_TestTuple(REJECT, IA5_STRING, "\x16\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation ASN1_TestTuple(IA5_STRING, REJECT, "\x16\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation
}; };
pass = RunASN1TestSet(ia5Strings, COUNTOF(ia5Strings)) && pass; pass = RunASN1TestSet(ia5Strings, COUNTOF(ia5Strings)) && pass;
@ -1508,26 +1516,26 @@ bool TestASN1Parse()
const ASN1_TestTuple integerValues[] = const ASN1_TestTuple integerValues[] =
{ {
// 8.3.1 The encoding of an integer value shall be primitive. The contents octets shall consist of one or more octets. // 8.3.1 The encoding of an integer value shall be primitive. The contents octets shall consist of one or more octets.
ASN1_TestTuple(REJECT, INTEGER, "\x02\x00", 2), // definite length, short form, zero content octets ASN1_TestTuple(INTEGER, REJECT, "\x02\x00", 2), // definite length, short form, zero content octets
ASN1_TestTuple(ACCEPT, INTEGER, "\x02\x01" "C", 3), // definite length, short form, expected content octets ASN1_TestTuple(INTEGER, ACCEPT, "\x02\x01" "C", 3), // definite length, short form, expected content octets
ASN1_TestTuple(REJECT, INTEGER, "\x02\x02" "C", 3), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x02" "C", 3), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x7F" "C", 3), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x7F" "C", 3), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x81\x00", 3), // definite length, long form, zero content octets ASN1_TestTuple(INTEGER, REJECT, "\x02\x81\x00", 3), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, INTEGER, "\x02\x81\x01" "C", 4), // definite length, long form, expected content octets ASN1_TestTuple(INTEGER, ACCEPT, "\x02\x81\x01" "C", 4), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, INTEGER, "\x02\x81\x02" "C", 4), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x81\x02" "C", 4), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x81\xff" "C", 4), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x81\xff" "C", 4), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x82\x00\x00", 4), // definite length, long form, zero content octets ASN1_TestTuple(INTEGER, REJECT, "\x02\x82\x00\x00", 4), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, INTEGER, "\x02\x82\x00\x01" "C", 5), // definite length, long form, expected content octets ASN1_TestTuple(INTEGER, ACCEPT, "\x02\x82\x00\x01" "C", 5), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, INTEGER, "\x02\x82\x00\x02" "C", 5), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x82\x00\x02" "C", 5), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x82\xff\xff" "C", 5), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x82\xff\xff" "C", 5), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x83\x00\x00\x00", 5), // definite length, long form, zero content octets ASN1_TestTuple(INTEGER, REJECT, "\x02\x83\x00\x00\x00", 5), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, INTEGER, "\x02\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets ASN1_TestTuple(INTEGER, ACCEPT, "\x02\x83\x00\x00\x01" "C", 6), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, INTEGER, "\x02\x83\x00\x00\x02" "C", 6), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x83\x00\x00\x02" "C", 6), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x83\xff\xff\xff" "C", 6), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x83\xff\xff\xff" "C", 6), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets ASN1_TestTuple(INTEGER, REJECT, "\x02\x84\x00\x00\x00\x00", 6), // definite length, long form, zero content octets
ASN1_TestTuple(ACCEPT, INTEGER, "\x02\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets ASN1_TestTuple(INTEGER, ACCEPT, "\x02\x84\x00\x00\x00\x01" "C", 7), // definite length, long form, expected content octets
ASN1_TestTuple(REJECT, INTEGER, "\x02\x84\x00\x00\x00\x02" "C", 7), // runt or underrun ASN1_TestTuple(INTEGER, REJECT, "\x02\x84\x00\x00\x00\x02" "C", 7), // runt or underrun
ASN1_TestTuple(REJECT, INTEGER, "\x02\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation ASN1_TestTuple(INTEGER, REJECT, "\x02\x84\xff\xff\xff\xff" "C", 7), // <== Issue 346; requires large allocation
}; };
pass = RunASN1TestSet(integerValues, COUNTOF(integerValues)) && pass; pass = RunASN1TestSet(integerValues, COUNTOF(integerValues)) && pass;