aboutsummaryrefslogtreecommitdiffstats
path: root/src/asn1/der_enc.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/der_enc.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/der_enc.h')
-rw-r--r--src/asn1/der_enc.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/asn1/der_enc.h b/src/asn1/der_enc.h
new file mode 100644
index 000000000..5b3c11489
--- /dev/null
+++ b/src/asn1/der_enc.h
@@ -0,0 +1,89 @@
+/*************************************************
+* DER Encoder Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_DER_ENCODER_H__
+#define BOTAN_DER_ENCODER_H__
+
+#include <botan/asn1_int.h>
+#include <vector>
+
+namespace Botan {
+
+/*************************************************
+* General DER Encoding Object *
+*************************************************/
+class BOTAN_DLL DER_Encoder
+ {
+ public:
+ SecureVector<byte> get_contents();
+
+ DER_Encoder& start_cons(ASN1_Tag, ASN1_Tag = UNIVERSAL);
+ DER_Encoder& end_cons();
+
+ DER_Encoder& start_explicit(u16bit);
+ DER_Encoder& end_explicit();
+
+ DER_Encoder& raw_bytes(const byte[], u32bit);
+ DER_Encoder& raw_bytes(const MemoryRegion<byte>&);
+
+ DER_Encoder& encode_null();
+ DER_Encoder& encode(bool);
+ DER_Encoder& encode(u32bit);
+ DER_Encoder& encode(const class BigInt&);
+ DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag);
+ DER_Encoder& encode(const byte[], u32bit, ASN1_Tag);
+
+ DER_Encoder& encode(bool, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+ DER_Encoder& encode(u32bit, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+ DER_Encoder& encode(const class BigInt&, ASN1_Tag,
+ ASN1_Tag = CONTEXT_SPECIFIC);
+ DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag,
+ ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+ DER_Encoder& encode(const byte[], u32bit, ASN1_Tag,
+ ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
+
+ template<typename T>
+ DER_Encoder& encode_optional(const T& value, const T& default_value)
+ {
+ if(value != default_value)
+ encode(value);
+ return (*this);
+ }
+
+ template<typename T>
+ DER_Encoder& encode_list(const std::vector<T>& values)
+ {
+ for(u32bit j = 0; j != values.size(); ++j)
+ encode(values[j]);
+ return (*this);
+ }
+
+ DER_Encoder& encode(const class ASN1_Object&);
+ DER_Encoder& encode_if(bool, DER_Encoder&);
+
+ DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], u32bit);
+ DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const MemoryRegion<byte>&);
+ DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const std::string&);
+ DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, byte);
+ private:
+ class DER_Sequence
+ {
+ public:
+ ASN1_Tag tag_of() const;
+ SecureVector<byte> get_contents();
+ void add_bytes(const byte[], u32bit);
+ DER_Sequence(ASN1_Tag, ASN1_Tag);
+ private:
+ ASN1_Tag type_tag, class_tag;
+ SecureVector<byte> contents;
+ std::vector< SecureVector<byte> > set_contents;
+ };
+ SecureVector<byte> contents;
+ std::vector<DER_Sequence> subsequences;
+ };
+
+}
+
+#endif