From a2c99d3270eb73ef2db5704fc54356c6b75096f8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 18 May 2006 18:33:19 +0000 Subject: Initial checkin --- include/der_enc.h | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 include/der_enc.h (limited to 'include/der_enc.h') diff --git a/include/der_enc.h b/include/der_enc.h new file mode 100644 index 000000000..b07c76172 --- /dev/null +++ b/include/der_enc.h @@ -0,0 +1,85 @@ +/************************************************* +* DER Encoder Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_DER_ENCODER_H__ +#define BOTAN_DER_ENCODER_H__ + +#include +#include + +namespace Botan { + +/************************************************* +* General DER Encoding Object * +*************************************************/ +class DER_Encoder + { + public: + SecureVector get_contents(); + + DER_Encoder& start_sequence(ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& end_sequence(ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& start_set(ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& end_set(ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + + DER_Encoder& start_sequence(); + DER_Encoder& end_sequence(); + DER_Encoder& start_set(); + DER_Encoder& end_set(); + + DER_Encoder& start_explicit(ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& end_explicit(ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + + DER_Encoder& add_raw_octets(const byte[], u32bit); + DER_Encoder& add_raw_octets(const MemoryRegion&); + + DER_Encoder& encode_null(); + DER_Encoder& encode(bool); + DER_Encoder& encode(u32bit); + DER_Encoder& encode(const class BigInt&); + DER_Encoder& encode(const MemoryRegion&, 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&, ASN1_Tag, + ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& encode(const byte[], u32bit, ASN1_Tag, + ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + + DER_Encoder& encode(const class ASN1_Object&); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], u32bit); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const MemoryRegion&); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const std::string&); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, byte); + + DER_Encoder(); + private: + DER_Encoder& start_cons(ASN1_Tag, ASN1_Tag, bool); + DER_Encoder& end_cons(ASN1_Tag, ASN1_Tag); + + class DER_Sequence + { + public: + ASN1_Tag tag_of() const; + SecureVector get_contents(); + void add_bytes(const byte[], u32bit); + DER_Sequence(ASN1_Tag, ASN1_Tag, bool = false); + private: + ASN1_Tag type_tag, class_tag; + bool is_a_set; + SecureVector contents; + std::vector< SecureVector > set_contents; + }; + SecureVector contents; + std::vector subsequences; + u32bit sequence_level; + }; + +} + +#endif -- cgit v1.2.3