monotone

monotone Mtn Source Tree

Root/botan/der_enc.h

1/*************************************************
2* DER Encoder Header File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_DER_ENCODER_H__
7#define BOTAN_DER_ENCODER_H__
8
9#include <botan/secmem.h>
10#include <botan/enums.h>
11#include <vector>
12
13namespace Botan {
14
15/*************************************************
16* General DER Encoding Object *
17*************************************************/
18class DER_Encoder
19 {
20 public:
21 SecureVector<byte> get_contents();
22
23 DER_Encoder& start_cons(ASN1_Tag, ASN1_Tag = UNIVERSAL);
24 DER_Encoder& end_cons();
25
26 DER_Encoder& start_explicit(u16bit);
27 DER_Encoder& end_explicit();
28
29 DER_Encoder& raw_bytes(const byte[], u32bit);
30 DER_Encoder& raw_bytes(const MemoryRegion<byte>&);
31
32 DER_Encoder& encode_null();
33 DER_Encoder& encode(bool);
34 DER_Encoder& encode(u32bit);
35 DER_Encoder& encode(const class BigInt&);
36 DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag);
37 DER_Encoder& encode(const byte[], u32bit, ASN1_Tag);
38
39 DER_Encoder& encode(bool, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
40 DER_Encoder& encode(u32bit, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
41 DER_Encoder& encode(const class BigInt&, ASN1_Tag,
42 ASN1_Tag = CONTEXT_SPECIFIC);
43 DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag,
44 ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
45 DER_Encoder& encode(const byte[], u32bit, ASN1_Tag,
46 ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
47
48 template<typename T>
49 DER_Encoder& encode_optional(const T& value, const T& default_value)
50 {
51 if(value != default_value)
52 encode(value);
53 return (*this);
54 }
55
56 template<typename T>
57 DER_Encoder& encode_list(const std::vector<T>& values)
58 {
59 for(u32bit j = 0; j != values.size(); ++j)
60 encode(values[j]);
61 return (*this);
62 }
63
64 DER_Encoder& encode(const class ASN1_Object&);
65 DER_Encoder& encode_if(bool, DER_Encoder&);
66
67 DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], u32bit);
68 DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const MemoryRegion<byte>&);
69 DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const std::string&);
70 DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, byte);
71 private:
72 class DER_Sequence
73 {
74 public:
75 ASN1_Tag tag_of() const;
76 SecureVector<byte> get_contents();
77 void add_bytes(const byte[], u32bit);
78 DER_Sequence(ASN1_Tag, ASN1_Tag);
79 private:
80 ASN1_Tag type_tag, class_tag;
81 SecureVector<byte> contents;
82 std::vector< SecureVector<byte> > set_contents;
83 };
84 SecureVector<byte> contents;
85 std::vector<DER_Sequence> subsequences;
86 };
87
88}
89
90#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status