libepp_nicbr
DSInfo.H
Go to the documentation of this file.
1 /* ${copyright}$ */
2 /* $Id: DSInfo.H 1086 2010-12-10 13:07:28Z eduardo $ */
7 #ifndef __DSINFO_H__
8 #define __DSINFO_H__
9 
10 #include "KeyData.H"
11 #include "StrUtil.H"
12 
13 LIBEPP_NICBR_NS_BEGIN
14 
16 class DSInfo {
17 public:
18  DSInfo& operator=(const DSInfo &dsInfo) {
19  _key_tag = dsInfo._key_tag;
20  _key_tag_f = dsInfo._key_tag_f;
21  _algo = dsInfo._algo;
22  _algo_f = dsInfo._algo_f;
23  _digest_type = dsInfo._digest_type;
24  _digest_type_f = dsInfo._digest_type_f;
25  _digest = dsInfo._digest;
26  _digest_f = dsInfo._digest_f;
27  _max_sig_life = dsInfo._max_sig_life;
28  _key_data = dsInfo._key_data;
29  _hasKeyData = dsInfo._hasKeyData;
30 
31  return *this;
32  }
33 
36  {
37  this->reset();
38  }
39 
41 
44  void set_key_tag(const unsigned int key_tag)
45  {
46  _key_tag = key_tag;
47  _key_tag_f = true;
48  }
49 
51 
54  unsigned int get_key_tag() const
55  {
56  return _key_tag;
57  }
58 
60 
63  void set_algo(const unsigned int algo)
64  {
65  _algo = algo;
66  _algo_f = true;
67  }
68 
70 
73  unsigned int get_algo() const { return _algo; }
74 
76 
79  void set_digest_type(const unsigned int digest_type)
80  {
81  _digest_type = digest_type;
82  _digest_type_f = true;
83  }
84 
86 
89  unsigned int get_digest_type() const { return _digest_type; }
90 
92 
95  void set_digest(const string& digest)
96  {
97  _digest = digest;
98  _digest_f = true;
99  }
100 
102 
105  string get_digest() const
106  {
107  return _digest;
108  }
109 
111 
114  void set_max_sig_life(const unsigned int max_sig_life)
115  {
116  _max_sig_life = max_sig_life;
117  }
118 
120 
123  unsigned int get_max_sig_life() const
124  {
125  return _max_sig_life;
126  }
127 
129 
132  void set_key_data(const KeyData &key_data)
133  {
134  _key_data = key_data;
135  _hasKeyData = true;
136  }
137 
139 
143  {
144  return _key_data;
145  }
146 
148  bool hasKeyData() const
149  {
150  return _hasKeyData;
151  }
152 
154 
157  string get_xml_format(string secDnsVersion = "1.1") const
158  {
159  string xml = "<secDNS:dsData>"
160  "<secDNS:keyTag>" + StrUtil::to_string("%u", _key_tag) +
161  "</secDNS:keyTag>"
162  "<secDNS:alg>" + StrUtil::to_string("%u", _algo) +
163  "</secDNS:alg>"
164  "<secDNS:digestType>" + StrUtil::to_string("%u", _digest_type) +
165  "</secDNS:digestType>"
166  "<secDNS:digest>" + StrUtil::esc_xml_markup(_digest) +
167  "</secDNS:digest>";
168 
169  if (_max_sig_life > 0 && secDnsVersion == "1.0") {
170  xml += "<secDNS:maxSigLife>" + StrUtil::to_string("%u", _max_sig_life) +
171  "</secDNS:maxSigLife>";
172  }
173 
174  if (_hasKeyData) {
175  xml += _key_data.get_xml_format();
176  }
177 
178  xml += "</secDNS:dsData>";
179 
180  return xml;
181  }
182 
184  void reset()
185  {
186  _key_tag = 0;
187  _algo = 0;
188  _digest_type = 0;
189  _max_sig_life = 0;
190  _digest = "";
191  _key_data.reset();
192  _key_tag_f = false;
193  _algo_f = false;
194  _digest_type_f = false;
195  _digest_f = false;
196  _hasKeyData = false;
197  }
198 
199 protected:
200  // Flags for DS Info attributes
201  bool _key_tag_f;
202  bool _algo_f;
203  bool _digest_type_f;
204  bool _digest_f;
205  bool _hasKeyData;
206 
207  // DS Info attributes
208  unsigned int _key_tag;
209  unsigned int _algo;
210  unsigned int _digest_type;
211  string _digest;
212  unsigned int _max_sig_life;
213  KeyData _key_data;
214 
215 };
216 LIBEPP_NICBR_NS_END
217 #endif //__DSINFO_H__
static string to_string(const char *format, const kind &number)
Convert number to string where the format string looks like printf format.
Definition: StrUtil.H:57
unsigned int get_algo() const
Returns the algorithm.
Definition: DSInfo.H:73
string get_digest() const
Returns the digest.
Definition: DSInfo.H:105
void set_algo(const unsigned int algo)
Sets algorithm.
Definition: DSInfo.H:63
void set_digest_type(const unsigned int digest_type)
Sets the digest type.
Definition: DSInfo.H:79
bool hasKeyData() const
Returns what it means to.
Definition: DSInfo.H:148
void reset()
Reset all object attributes.
Definition: DSInfo.H:184
unsigned int get_max_sig_life() const
Returns the maximum signature life (deprecated by RFC5910)
Definition: DSInfo.H:123
void set_key_tag(const unsigned int key_tag)
Sets key tag.
Definition: DSInfo.H:44
unsigned int get_key_tag() const
Returns the key tag.
Definition: DSInfo.H:54
unsigned int get_digest_type() const
Returns the digest type.
Definition: DSInfo.H:89
DSInfo Class.
Definition: DSInfo.H:16
string get_xml_format(string secDnsVersion="1.1") const
Returns the xml format.
Definition: DSInfo.H:157
void set_key_data(const KeyData &key_data)
Sets the key data.
Definition: DSInfo.H:132
Definition: KeyData.H:15
void set_max_sig_life(const unsigned int max_sig_life)
Sets the maximum signature life (deprecated by RFC5910)
Definition: DSInfo.H:114
static string esc_xml_markup(const string &input_txt)
Escape &'><" characters.
String Manipulation Utilities.
void set_digest(const string &digest)
Sets the digest.
Definition: DSInfo.H:95
KeyData get_key_data() const
Returns the key data.
Definition: DSInfo.H:142
DSInfo()
Default constructor.
Definition: DSInfo.H:35