aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-27 13:32:05 +0000
committerlloyd <[email protected]>2012-05-27 13:32:05 +0000
commitd881dedf81b97caa05740773587f865b1546dc67 (patch)
tree47d6f671a38bebabcfb149f78e23b54f67b87da9
parent4738d02a99eb371b5a22fd5547a4b63dfa77fb95 (diff)
Have BER_Deocder::decode_list actually start the SEQUENCE. All callers
did it and it would be silly for it not to. Update the two existing callers, who were both doing start_cons().decode_list().end_cons() to just call decode_list(). Add BER_Decoder::get_next so we can get arbitrarily weird types without having to break message chains. Add dummy tag arguments to the ASN1_Object decoder so it can be used from decode_optional.
-rw-r--r--src/asn1/ber_dec.cpp9
-rw-r--r--src/asn1/ber_dec.h15
-rw-r--r--src/cert/x509/x509_ext.cpp10
3 files changed, 22 insertions, 12 deletions
diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp
index dbd59988b..51b952e71 100644
--- a/src/asn1/ber_dec.cpp
+++ b/src/asn1/ber_dec.cpp
@@ -232,6 +232,12 @@ BER_Object BER_Decoder::get_next_object()
return next;
}
+BER_Decoder& BER_Decoder::get_next(BER_Object& ber)
+ {
+ ber = get_next_object();
+ return (*this);
+ }
+
/*
* Push a object back into the stream
*/
@@ -341,7 +347,8 @@ BER_Decoder::~BER_Decoder()
/*
* Request for an object to decode itself
*/
-BER_Decoder& BER_Decoder::decode(ASN1_Object& obj)
+BER_Decoder& BER_Decoder::decode(ASN1_Object& obj,
+ ASN1_Tag, ASN1_Tag)
{
obj.decode_from(*this);
return (*this);
diff --git a/src/asn1/ber_dec.h b/src/asn1/ber_dec.h
index 6b010fcc4..6ca9aa777 100644
--- a/src/asn1/ber_dec.h
+++ b/src/asn1/ber_dec.h
@@ -29,6 +29,8 @@ class BOTAN_DLL BER_Decoder
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag = UNIVERSAL);
BER_Decoder& end_cons();
+ BER_Decoder& get_next(BER_Object& ber);
+
BER_Decoder& raw_bytes(secure_vector<byte>& v);
BER_Decoder& raw_bytes(std::vector<byte>& v);
@@ -61,7 +63,9 @@ class BOTAN_DLL BER_Decoder
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
- BER_Decoder& decode(class ASN1_Object& obj);
+ BER_Decoder& decode(class ASN1_Object& obj,
+ ASN1_Tag type_tag = NO_OBJECT,
+ ASN1_Tag class_tag = NO_OBJECT);
BER_Decoder& decode_octet_string_bigint(class BigInt& b);
@@ -172,12 +176,17 @@ BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, bool clear_it)
if(clear_it)
vec.clear();
- while(more_items())
+ BER_Decoder list = start_cons(SEQUENCE);
+
+ while(list.more_items())
{
T value;
- decode(value);
+ list.decode(value);
vec.push_back(value);
}
+
+ list.end_cons();
+
return (*this);
}
diff --git a/src/cert/x509/x509_ext.cpp b/src/cert/x509/x509_ext.cpp
index 751d20266..7daa58f20 100644
--- a/src/cert/x509/x509_ext.cpp
+++ b/src/cert/x509/x509_ext.cpp
@@ -418,10 +418,7 @@ std::vector<byte> Extended_Key_Usage::encode_inner() const
*/
void Extended_Key_Usage::decode_inner(const std::vector<byte>& in)
{
- BER_Decoder(in)
- .start_cons(SEQUENCE)
- .decode_list(oids)
- .end_cons();
+ BER_Decoder(in).decode_list(oids);
}
/*
@@ -488,10 +485,7 @@ void Certificate_Policies::decode_inner(const std::vector<byte>& in)
{
std::vector<Policy_Information> policies;
- BER_Decoder(in)
- .start_cons(SEQUENCE)
- .decode_list(policies)
- .end_cons();
+ BER_Decoder(in).decode_list(policies);
oids.clear();
for(size_t i = 0; i != policies.size(); ++i)