aboutsummaryrefslogtreecommitdiffstats
path: root/src/asn1/ber_dec.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 22:14:54 +0000
committerlloyd <[email protected]>2008-09-28 22:14:54 +0000
commit31204986023619c385d378e79a6511bb81ef7b78 (patch)
treece272a6585dc070f750f6875b0450d53145b935d /src/asn1/ber_dec.h
parent42c0fe76ab6d9625d0e51c68b8dd187322c991bd (diff)
Move almost all of the ASN.1, BER, and DER codec related code into new
module asn1 Move hex and base64 codecs into new codecs directory. Also move zlib and bzip2 to codecs from compress.
Diffstat (limited to 'src/asn1/ber_dec.h')
-rw-r--r--src/asn1/ber_dec.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/asn1/ber_dec.h b/src/asn1/ber_dec.h
new file mode 100644
index 000000000..9fec75832
--- /dev/null
+++ b/src/asn1/ber_dec.h
@@ -0,0 +1,130 @@
+/*************************************************
+* BER Decoder Header File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_BER_DECODER_H__
+#define BOTAN_BER_DECODER_H__
+
+#include <botan/asn1_oid.h>
+#include <botan/data_src.h>
+#include <botan/enums.h>
+
+namespace Botan {
+
+/*************************************************
+* BER Decoding Object *
+*************************************************/
+class BOTAN_DLL BER_Decoder
+ {
+ public:
+ BER_Object get_next_object();
+ void push_back(const BER_Object&);
+
+ bool more_items() const;
+ BER_Decoder& verify_end();
+ BER_Decoder& discard_remaining();
+
+ BER_Decoder start_cons(ASN1_Tag, ASN1_Tag = UNIVERSAL);
+ BER_Decoder& end_cons();
+
+ BER_Decoder& raw_bytes(MemoryRegion<byte>&);
+
+ BER_Decoder& decode_null();
+ BER_Decoder& decode(bool&);
+ BER_Decoder& decode(u32bit&);
+ BER_Decoder& decode(class BigInt&);
+ BER_Decoder& decode(MemoryRegion<byte>&, ASN1_Tag);
+
+ BER_Decoder& decode(bool&, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+ BER_Decoder& decode(u32bit&, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+ BER_Decoder& decode(class BigInt&,
+ ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+ BER_Decoder& decode(MemoryRegion<byte>&, ASN1_Tag,
+ ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+
+ BER_Decoder& decode(class ASN1_Object&);
+
+ template<typename T>
+ BER_Decoder& decode_optional(T&, ASN1_Tag, ASN1_Tag, const T& = T());
+
+ template<typename T>
+ BER_Decoder& decode_list(std::vector<T>&, bool = true);
+
+ BER_Decoder& decode_optional_string(MemoryRegion<byte>&,
+ ASN1_Tag, u16bit);
+
+ BER_Decoder(DataSource&);
+ BER_Decoder(const byte[], u32bit);
+ BER_Decoder(const MemoryRegion<byte>&);
+ BER_Decoder(const BER_Decoder&);
+ ~BER_Decoder();
+ private:
+ BER_Decoder& operator=(const BER_Decoder&) { return (*this); }
+
+ BER_Decoder* parent;
+ DataSource* source;
+ BER_Object pushed;
+ mutable bool owns;
+ };
+
+/*************************************************
+* Decode an OPTIONAL or DEFAULT element *
+*************************************************/
+template<typename T>
+BER_Decoder& BER_Decoder::decode_optional(T& out,
+ ASN1_Tag type_tag,
+ ASN1_Tag class_tag,
+ const T& default_value)
+ {
+ BER_Object obj = get_next_object();
+
+ if(obj.type_tag == type_tag && obj.class_tag == class_tag)
+ {
+ if(class_tag & CONSTRUCTED)
+ BER_Decoder(obj.value).decode(out).verify_end();
+ else
+ {
+ push_back(obj);
+ decode(out, type_tag, class_tag);
+ }
+ }
+ else
+ {
+ out = default_value;
+ push_back(obj);
+ }
+
+ return (*this);
+ }
+
+/*************************************************
+* Decode a list of homogenously typed values *
+*************************************************/
+template<typename T>
+BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, bool clear_it)
+ {
+ if(clear_it)
+ vec.clear();
+
+ while(more_items())
+ {
+ T value;
+ decode(value);
+ vec.push_back(value);
+ }
+ return (*this);
+ }
+
+/*************************************************
+* BER Decoding Functions *
+*************************************************/
+namespace BER {
+
+void BOTAN_DLL decode(BER_Decoder&, Key_Constraints&);
+
+}
+
+}
+
+#endif