diff options
author | Jack Lloyd <[email protected]> | 2018-06-08 05:28:02 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-06-08 05:28:02 -0400 |
commit | 4407dabb4e95488851323d134d60f893729795c3 (patch) | |
tree | 7f503a5164ec364c2fb9049f0d262ff2720ceffe /src/lib/asn1 | |
parent | e9f5de44dc0cb8045fef8c3f9bf89162b684aa97 (diff) |
Improve error reporting on unexpected EOF when decoding ASN
Diffstat (limited to 'src/lib/asn1')
-rw-r--r-- | src/lib/asn1/asn1_obj.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/lib/asn1/asn1_obj.cpp b/src/lib/asn1/asn1_obj.cpp index 987c89d96..815bc4ef8 100644 --- a/src/lib/asn1/asn1_obj.cpp +++ b/src/lib/asn1/asn1_obj.cpp @@ -33,16 +33,24 @@ void BER_Object::assert_is_a(ASN1_Tag type_tag_, ASN1_Tag class_tag_, msg << "Tag mismatch when decoding " << descr << " got "; - if(class_tag == UNIVERSAL || class_tag == CONSTRUCTED) + if(class_tag == NO_OBJECT && type_tag == NO_OBJECT) { - msg << asn1_tag_to_string(type_tag); + msg << "EOF"; } else { - msg << std::to_string(type_tag); + if(class_tag == UNIVERSAL || class_tag == CONSTRUCTED) + { + msg << asn1_tag_to_string(type_tag); + } + else + { + msg << std::to_string(type_tag); + } + + msg << "/" << asn1_class_to_string(class_tag); } - msg << "/" << asn1_class_to_string(class_tag); msg << " expected "; if(class_tag_ == UNIVERSAL || class_tag_ == CONSTRUCTED) @@ -90,6 +98,8 @@ std::string asn1_class_to_string(ASN1_Tag type) return "APPLICATION"; case CONSTRUCTED | CONTEXT_SPECIFIC: return "PRIVATE"; + case Botan::NO_OBJECT: + return "NO_OBJECT"; default: return "CLASS(" + std::to_string(static_cast<size_t>(type)) + ")"; } @@ -153,6 +163,9 @@ std::string asn1_tag_to_string(ASN1_Tag type) case Botan::BOOLEAN: return "BOOLEAN"; + case Botan::NO_OBJECT: + return "NO_OBJECT"; + default: return "TAG(" + std::to_string(static_cast<size_t>(type)) + ")"; } |