diff options
author | lloyd <[email protected]> | 2011-12-27 20:01:05 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-12-27 20:01:05 +0000 |
commit | 8c2ab53dfd502d7019468bf24ad8e223531df8b4 (patch) | |
tree | 7f7b3a6882e99dde16b4a66188f113f707ddc95f /src/asn1/ber_dec.cpp | |
parent | cd9b85ed4124af2ceb9a91def5dc57ac23938f77 (diff) |
BER decoder extras needed by previous commit
Diffstat (limited to 'src/asn1/ber_dec.cpp')
-rw-r--r-- | src/asn1/ber_dec.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp index b31c7b903..faea4cb94 100644 --- a/src/asn1/ber_dec.cpp +++ b/src/asn1/ber_dec.cpp @@ -400,6 +400,28 @@ BER_Decoder& BER_Decoder::decode(size_t& out, } /* +* Decode a small BER encoded INTEGER +*/ +u64bit BER_Decoder::decode_constrained_integer(ASN1_Tag type_tag, + ASN1_Tag class_tag, + size_t T_bytes) + { + if(T_bytes > 8) + throw BER_Decoding_Error("Can't decode small integer over 8 bytes"); + + BigInt integer; + decode(integer, type_tag, class_tag); + + if(integer.bits() > 8*T_bytes) + throw BER_Decoding_Error("Decoded integer value larger than expected"); + + u64bit out = 0; + for(size_t i = 0; i != 8; ++i) + out = (out << 8) | integer.byte_at(8-i); + return out; + } + +/* * Decode a BER encoded INTEGER */ BER_Decoder& BER_Decoder::decode(BigInt& out, |