diff options
author | Rene Meusel <[email protected]> | 2017-10-11 21:34:31 +0200 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-11-09 16:05:17 -0500 |
commit | 3bc43de0a1e8ca1e05dc8b85c0965425b15ad806 (patch) | |
tree | 8b7876886e6a87373e285b151dce94e961a36d1c /src/tests | |
parent | 2abac405f483b45ddb653f710be396d8d37936b2 (diff) |
add a failing test for an UTF-8 string and a successful test for ASCII
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_asn1.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/tests/test_asn1.cpp b/src/tests/test_asn1.cpp index 5c54f2bb4..ee809a0c8 100644 --- a/src/tests/test_asn1.cpp +++ b/src/tests/test_asn1.cpp @@ -9,6 +9,7 @@ #if defined(BOTAN_HAS_ASN1) #include <botan/der_enc.h> #include <botan/ber_dec.h> + #include <botan/asn1_str.h> #endif namespace Botan_Tests { @@ -46,6 +47,60 @@ Test::Result test_ber_stack_recursion() } +Test::Result test_asn1_utf8_ascii_parsing() + { + Test::Result result("ASN.1 ASCII parsing"); + + try + { + // \x13 - ASN1 tag for 'printable string' + // \x06 - 6 characters of payload + // ... - UTF-8 encoded (ASCII chars only) word 'Moscow' + const std::string privet = + "\x13\x06\x4D\x6F\x73\x63\x6F\x77"; + Botan::DataSource_Memory input(privet.data()); + Botan::BER_Decoder dec(input); + + Botan::ASN1_String str; + str.decode_from(dec); + + result.test_success("No crash"); + } + catch(const Botan::Decoding_Error &ex) + { + result.test_failure(ex.what()); + } + + return result; + } + +Test::Result test_asn1_utf8_parsing() + { + Test::Result result("ASN.1 UTF-8 parsing"); + + try + { + // \x0C - ASN1 tag for 'UTF8 string' + // \x0C - 12 characters of payload + // ... - UTF-8 encoded russian word for Moscow in cyrilic script + const std::string privet = + "\x0C\x0C\xD0\x9C\xD0\xBE\xD1\x81\xD0\xBA\xD0\xB2\xD0\xB0"; + Botan::DataSource_Memory input(privet.data()); + Botan::BER_Decoder dec(input); + + Botan::ASN1_String str; + str.decode_from(dec); + + result.test_success("No crash"); + } + catch(const Botan::Decoding_Error &ex) + { + result.test_failure(ex.what()); + } + + return result; + } + class ASN1_Tests final : public Test { public: @@ -54,6 +109,8 @@ class ASN1_Tests final : public Test std::vector<Test::Result> results; results.push_back(test_ber_stack_recursion()); + results.push_back(test_asn1_utf8_ascii_parsing()); + results.push_back(test_asn1_utf8_parsing()); return results; } |