monotone

monotone Mtn Source Tree

Root/botan/ber_dec.h

1/*************************************************
2* BER Decoder Header File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_BER_DECODER_H__
7#define BOTAN_BER_DECODER_H__
8
9#include <botan/asn1_oid.h>
10#include <botan/data_src.h>
11
12namespace Botan {
13
14/*************************************************
15* BER Decoding Object *
16*************************************************/
17class BER_Decoder
18 {
19 public:
20 BER_Object get_next_object();
21 void push_back(const BER_Object&);
22
23 bool more_items() const;
24 BER_Decoder& verify_end();
25 BER_Decoder& discard_remaining();
26
27 BER_Decoder start_cons(ASN1_Tag);
28 BER_Decoder& end_cons();
29
30 BER_Decoder& raw_bytes(MemoryRegion<byte>&);
31
32 BER_Decoder& decode_null();
33 BER_Decoder& decode(bool&);
34 BER_Decoder& decode(u32bit&);
35 BER_Decoder& decode(class BigInt&);
36 BER_Decoder& decode(MemoryRegion<byte>&, ASN1_Tag);
37
38 BER_Decoder& decode(bool&, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
39 BER_Decoder& decode(u32bit&, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
40 BER_Decoder& decode(class BigInt&,
41 ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
42 BER_Decoder& decode(MemoryRegion<byte>&, ASN1_Tag,
43 ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
44
45 BER_Decoder& decode(class ASN1_Object&);
46
47 template<typename T>
48 BER_Decoder& decode_optional(T&, ASN1_Tag, ASN1_Tag, const T& = T());
49
50 template<typename T>
51 BER_Decoder& decode_list(std::vector<T>&, bool = true);
52
53 BER_Decoder& decode_optional_string(MemoryRegion<byte>&,
54 ASN1_Tag, u16bit);
55
56 BER_Decoder(DataSource&);
57 BER_Decoder(const byte[], u32bit);
58 BER_Decoder(const MemoryRegion<byte>&);
59 BER_Decoder(const BER_Decoder&);
60 ~BER_Decoder();
61 private:
62 BER_Decoder& operator=(const BER_Decoder&) { return (*this); }
63
64 BER_Decoder* parent;
65 DataSource* source;
66 BER_Object pushed;
67 mutable bool owns;
68 };
69
70/*************************************************
71* Decode an OPTIONAL or DEFAULT element *
72*************************************************/
73template<typename T>
74BER_Decoder& BER_Decoder::decode_optional(T& out,
75 ASN1_Tag type_tag,
76 ASN1_Tag class_tag,
77 const T& default_value)
78 {
79 BER_Object obj = get_next_object();
80
81 if(obj.type_tag == type_tag && obj.class_tag == class_tag)
82 {
83 if(class_tag & CONSTRUCTED)
84 BER_Decoder(obj.value).decode(out).verify_end();
85 else
86 {
87 push_back(obj);
88 decode(out, type_tag, class_tag);
89 }
90 }
91 else
92 {
93 out = default_value;
94 push_back(obj);
95 }
96
97 return (*this);
98 }
99
100/*************************************************
101* Decode a list of homogenously typed values *
102*************************************************/
103template<typename T>
104BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, bool clear_it)
105 {
106 if(clear_it)
107 vec.clear();
108
109 while(more_items())
110 {
111 T value;
112 decode(value);
113 vec.push_back(value);
114 }
115 return (*this);
116 }
117
118/*************************************************
119* BER Decoding Functions *
120*************************************************/
121namespace BER {
122
123void decode(BER_Decoder&, Key_Constraints&);
124
125}
126
127}
128
129#endif

Archive Download this file

Branches

Tags

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