libepp_nicbr
KeyData.H
1 /* ${copyright}$ */
2 /* $Id: DSInfo.H 1040 2009-10-01 17:49:12Z fneves $ */
7 #ifndef __KEYDATA_H__
8 #define __KEYDATA_H__
9 
10 #include "stdint.h"
11 #include "StrUtil.H"
12 
13 LIBEPP_NICBR_NS_BEGIN
14 
15 class KeyData {
16 public:
17  unsigned int get_flags() const
18  {
19  return _flags;
20  }
21 
22  unsigned int get_protocol() const
23  {
24  return _protocol;
25  }
26 
27  unsigned int get_algorithm() const
28  {
29  return _algorithm;
30  }
31 
32  string get_pub_key() const
33  {
34  return _pub_key;
35  }
36 
37  void set_flags(unsigned int flags)
38  {
39  _flags = flags;
40  }
41 
42  void set_protocol(unsigned int protocol)
43  {
44  _protocol = protocol;
45  }
46 
47  void set_algorithm(unsigned int algorithm)
48  {
49  _algorithm = algorithm;
50  }
51 
52  void set_pub_key(string pub_key)
53  {
54  _pub_key = pub_key;
55  }
56 
57  KeyData& operator=(const KeyData &key_data) {
58  _flags = key_data._flags;
59  _protocol = key_data._protocol;
60  _algorithm = key_data._algorithm;
61  _pub_key = key_data._pub_key;
62 
63  return *this;
64  }
65 
66  KeyData() {
67  this->reset();
68  }
69 
70  bool is_set() {
71  return (_flags != 0 && _protocol != 0 && _algorithm != 0 &&
72  _pub_key != "");
73  }
74 
75  void reset() {
76  _flags = 0;
77  _protocol = 0;
78  _algorithm = 0;
79  _pub_key = "";
80  }
81 
82  string get_xml_format() const
83  {
84  return "<secDNS:keyData>"
85  "<secDNS:flags>" + StrUtil::to_string("%u", _flags) +
86  "</secDNS:flags>"
87  "<secDNS:protocol>" + StrUtil::to_string("%u", _protocol) +
88  "</secDNS:protocol>"
89  "<secDNS:alg>" + StrUtil::to_string("%u", _algorithm) +
90  "</secDNS:alg>"
91  "<secDNS:pubKey>" + _pub_key +
92  "</secDNS:pubKey>" +
93  "</secDNS:keyData>";
94  }
95 
96 private:
97  uint16_t _flags;
98  uint8_t _protocol;
99  uint8_t _algorithm;
100  string _pub_key;
101 
102 };
103 LIBEPP_NICBR_NS_END
104 #endif //__KEYDATA_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
Definition: KeyData.H:15
String Manipulation Utilities.