aboutsummaryrefslogtreecommitdiffstats
path: root/include/der_enc.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-19 00:07:25 +0000
committerlloyd <[email protected]>2006-05-19 00:07:25 +0000
commitf090e030be53e574fecbe7cf50edfb5fdacb53e1 (patch)
tree0bff0c249a9dbcb674fcd2491ab17e3d123ef1f9 /include/der_enc.h
parenta0af7b26591f8fb79d1f06fe42548e1eb0c35e90 (diff)
Syntax changes to the BER and DER APIs to improve readability of code
that uses them. These changes are not backwards compatible, this commit updates all uses of the APIs within the library.
Diffstat (limited to 'include/der_enc.h')
-rw-r--r--include/der_enc.h49
1 files changed, 27 insertions, 22 deletions
diff --git a/include/der_enc.h b/include/der_enc.h
index b07c76172..d0e655ad7 100644
--- a/include/der_enc.h
+++ b/include/der_enc.h
@@ -6,7 +6,8 @@
#ifndef BOTAN_DER_ENCODER_H__
#define BOTAN_DER_ENCODER_H__
-#include <botan/asn1_oid.h>
+#include <botan/secmem.h>
+#include <botan/enums.h>
#include <vector>
namespace Botan {
@@ -19,21 +20,14 @@ class DER_Encoder
public:
SecureVector<byte> 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_cons(ASN1_Tag, ASN1_Tag = UNIVERSAL);
+ DER_Encoder& end_cons();
- DER_Encoder& start_sequence();
- DER_Encoder& end_sequence();
- DER_Encoder& start_set();
- DER_Encoder& end_set();
+ DER_Encoder& start_explicit(u16bit);
+ DER_Encoder& end_explicit();
- 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<byte>&);
+ DER_Encoder& raw_bytes(const byte[], u32bit);
+ DER_Encoder& raw_bytes(const MemoryRegion<byte>&);
DER_Encoder& encode_null();
DER_Encoder& encode(bool);
@@ -51,33 +45,44 @@ class DER_Encoder
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);
-
- 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<byte> get_contents();
void add_bytes(const byte[], u32bit);
- DER_Sequence(ASN1_Tag, ASN1_Tag, bool = false);
+ DER_Sequence(ASN1_Tag, ASN1_Tag);
private:
ASN1_Tag type_tag, class_tag;
- bool is_a_set;
SecureVector<byte> contents;
std::vector< SecureVector<byte> > set_contents;
};
SecureVector<byte> contents;
std::vector<DER_Sequence> subsequences;
- u32bit sequence_level;
};
}