diff options
author | lloyd <[email protected]> | 2010-03-19 17:59:40 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-19 17:59:40 +0000 |
commit | dab16b79c89e54e9551d30dcf54ca89432932dce (patch) | |
tree | fcd4ccce7e442006f8075f8c8a9b298aab5167b3 /src/asn1 | |
parent | 8fa0099ce0f2f488ca4c5046c6d019125d1d3b68 (diff) |
Add a couple of new helper functions to BER_Decoder:
decode_and_check takes an expected value; if the decoded value does
not match, a Decoding_Error with a specified string is thrown. Useful
for checking embedded version codes.
decode_octet_string_bigint is for decoding INTEGER values that are
stored as OCTET STRINGs. Totally obnoxious and useless, but common
especially in the ECC standards.
Diffstat (limited to 'src/asn1')
-rw-r--r-- | src/asn1/ber_dec.cpp | 8 | ||||
-rw-r--r-- | src/asn1/ber_dec.h | 25 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp index 66a27dd4e..ea0334202 100644 --- a/src/asn1/ber_dec.cpp +++ b/src/asn1/ber_dec.cpp @@ -355,6 +355,14 @@ BER_Decoder& BER_Decoder::decode(BigInt& out) return decode(out, INTEGER, UNIVERSAL); } +BER_Decoder& BER_Decoder::decode_octet_string_bigint(BigInt& out) + { + SecureVector<byte> out_vec; + decode(out_vec, OCTET_STRING); + out = BigInt::decode(&out_vec[0], out_vec.size()); + return (*this); + } + /* * Decode a BER encoded BOOLEAN */ diff --git a/src/asn1/ber_dec.h b/src/asn1/ber_dec.h index 2e38af301..3658aeba4 100644 --- a/src/asn1/ber_dec.h +++ b/src/asn1/ber_dec.h @@ -1,6 +1,6 @@ /* * BER Decoder -* (C) 1999-2008 Jack Lloyd +* (C) 1999-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -46,11 +46,30 @@ class BOTAN_DLL BER_Decoder BER_Decoder& decode(class ASN1_Object&); + BER_Decoder& decode_octet_string_bigint(class BigInt&); + + template<typename T> + BER_Decoder& decode_optional(T& out, + ASN1_Tag type_tag, + ASN1_Tag class_tag, + const T& default_value = T()); + template<typename T> - BER_Decoder& decode_optional(T&, ASN1_Tag, ASN1_Tag, const T& = T()); + BER_Decoder& decode_list(std::vector<T>& out, + bool clear_out = true); template<typename T> - BER_Decoder& decode_list(std::vector<T>&, bool = true); + BER_Decoder& decode_and_check(const T& expected, + const std::string& error_msg) + { + T actual; + decode(actual); + + if(actual != expected) + throw Decoding_Error(error_msg); + + return (*this); + } BER_Decoder& decode_optional_string(MemoryRegion<byte>&, ASN1_Tag, u16bit); |