summaryrefslogtreecommitdiffabout
path: root/include/opkele/util.h
Unidiff
Diffstat (limited to 'include/opkele/util.h') (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/util.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h
index 2a7a859..edc1859 100644
--- a/include/opkele/util.h
+++ b/include/opkele/util.h
@@ -1,130 +1,133 @@
1#ifndef __OPKELE_UTIL_H 1#ifndef __OPKELE_UTIL_H
2#define __OPKELE_UTIL_H 2#define __OPKELE_UTIL_H
3 3
4#include <time.h> 4#include <time.h>
5#include <string> 5#include <string>
6#include <vector> 6#include <vector>
7#include <openssl/bn.h> 7#include <openssl/bn.h>
8#include <openssl/dh.h> 8#include <openssl/dh.h>
9 9
10namespace opkele { 10namespace opkele {
11 using std::string; 11 using std::string;
12 using std::vector; 12 using std::vector;
13 13
14 /**
15 * @brief opkele utils namespace
16 */
14 namespace util { 17 namespace util {
15 18
16 /** 19 /**
17 * Convenience class encapsulating SSL BIGNUM object for the purpose of 20 * Convenience class encapsulating SSL BIGNUM object for the purpose of
18 * automatical freeing. 21 * automatical freeing.
19 */ 22 */
20 class bignum_t { 23 class bignum_t {
21 public: 24 public:
22 BIGNUM *_bn; 25 BIGNUM *_bn;
23 26
24 bignum_t() : _bn(0) { } 27 bignum_t() : _bn(0) { }
25 bignum_t(BIGNUM *bn) : _bn(bn) { } 28 bignum_t(BIGNUM *bn) : _bn(bn) { }
26 ~bignum_t() throw() { if(_bn) BN_free(_bn); } 29 ~bignum_t() throw() { if(_bn) BN_free(_bn); }
27 30
28 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; } 31 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; }
29 32
30 operator const BIGNUM*(void) const { return _bn; } 33 operator const BIGNUM*(void) const { return _bn; }
31 operator BIGNUM*(void) { return _bn; } 34 operator BIGNUM*(void) { return _bn; }
32 }; 35 };
33 /** 36 /**
34 * Convenience clas encapsulating SSL DH object for the purpose of 37 * Convenience clas encapsulating SSL DH object for the purpose of
35 * automatic freeing. 38 * automatic freeing.
36 */ 39 */
37 class dh_t { 40 class dh_t {
38 public: 41 public:
39 DH *_dh; 42 DH *_dh;
40 43
41 dh_t() : _dh(0) { } 44 dh_t() : _dh(0) { }
42 dh_t(DH *dh) : _dh(dh) { } 45 dh_t(DH *dh) : _dh(dh) { }
43 ~dh_t() throw() { if(_dh) DH_free(_dh); } 46 ~dh_t() throw() { if(_dh) DH_free(_dh); }
44 47
45 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; } 48 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; }
46 49
47 operator const DH*(void) const { return _dh; } 50 operator const DH*(void) const { return _dh; }
48 operator DH*(void) { return _dh; } 51 operator DH*(void) { return _dh; }
49 52
50 DH* operator->() { return _dh; } 53 DH* operator->() { return _dh; }
51 const DH* operator->() const { return _dh; } 54 const DH* operator->() const { return _dh; }
52 }; 55 };
53 56
54 /** 57 /**
55 * Convert base64-encoded SSL BIGNUM to internal representation. 58 * Convert base64-encoded SSL BIGNUM to internal representation.
56 * @param b64 base64-encoded number 59 * @param b64 base64-encoded number
57 * @return SSL BIGNUM 60 * @return SSL BIGNUM
58 * @throw failed_conversion in case of error 61 * @throw failed_conversion in case of error
59 */ 62 */
60 BIGNUM *base64_to_bignum(const string& b64); 63 BIGNUM *base64_to_bignum(const string& b64);
61 /** 64 /**
62 * Convert decimal representation to SSL BIGNUM. 65 * Convert decimal representation to SSL BIGNUM.
63 * @param dec decimal representation 66 * @param dec decimal representation
64 * @return resulting BIGNUM 67 * @return resulting BIGNUM
65 * @throw failed_conversion in case of error 68 * @throw failed_conversion in case of error
66 */ 69 */
67 BIGNUM *dec_to_bignum(const string& dec); 70 BIGNUM *dec_to_bignum(const string& dec);
68 /** 71 /**
69 * Convert SSL BIGNUM data to base64 encoded string. 72 * Convert SSL BIGNUM data to base64 encoded string.
70 * @param bn BIGNUM 73 * @param bn BIGNUM
71 * @return base64encoded string 74 * @return base64encoded string
72 */ 75 */
73 string bignum_to_base64(const BIGNUM *bn); 76 string bignum_to_base64(const BIGNUM *bn);
74 77
75 /** 78 /**
76 * Convert internal time representation to w3c format 79 * Convert internal time representation to w3c format
77 * @param t internal representation 80 * @param t internal representation
78 * @return w3c time 81 * @return w3c time
79 * @throw failed_conversion in case of error 82 * @throw failed_conversion in case of error
80 */ 83 */
81 string time_to_w3c(time_t t); 84 string time_to_w3c(time_t t);
82 /** 85 /**
83 * Convert W3C time representation to internal time_t 86 * Convert W3C time representation to internal time_t
84 * @param w w3c representation 87 * @param w w3c representation
85 * @return converted time 88 * @return converted time
86 * @throw failed_conversion in case of error 89 * @throw failed_conversion in case of error
87 */ 90 */
88 time_t w3c_to_time(const string& w); 91 time_t w3c_to_time(const string& w);
89 92
90 /** 93 /**
91 * Encode string to the representation suitable for using in URL. 94 * Encode string to the representation suitable for using in URL.
92 * @param str string to encode 95 * @param str string to encode
93 * @return encoded string 96 * @return encoded string
94 * @throw failed_conversion in case of failure 97 * @throw failed_conversion in case of failure
95 */ 98 */
96 string url_encode(const string& str); 99 string url_encode(const string& str);
97 100
98 /** 101 /**
99 * Convert number to string 102 * Convert number to string
100 * @param l number 103 * @param l number
101 * @return string representation 104 * @return string representation
102 * @throw failed_conversion in case of failure 105 * @throw failed_conversion in case of failure
103 */ 106 */
104 string long_to_string(long l); 107 string long_to_string(long l);
105 /** 108 /**
106 * Convert string to number 109 * Convert string to number
107 * @param s string, containing the number 110 * @param s string, containing the number
108 * @return the number 111 * @return the number
109 * @throw failed_conversion in case of failure 112 * @throw failed_conversion in case of failure
110 */ 113 */
111 long string_to_long(const string& s); 114 long string_to_long(const string& s);
112 115
113 /** 116 /**
114 * Encode binary data using base64. 117 * Encode binary data using base64.
115 * @param data pointer to binary data 118 * @param data pointer to binary data
116 * @param length length of data 119 * @param length length of data
117 * @return encoded data 120 * @return encoded data
118 */ 121 */
119 string encode_base64(const void *data,size_t length); 122 string encode_base64(const void *data,size_t length);
120 /** 123 /**
121 * Decode binary data from base64 representation. 124 * Decode binary data from base64 representation.
122 * @param data base64-encoded data 125 * @param data base64-encoded data
123 * @param rv container for decoded binary 126 * @param rv container for decoded binary
124 */ 127 */
125 void decode_base64(const string& data,vector<unsigned char>& rv); 128 void decode_base64(const string& data,vector<unsigned char>& rv);
126 } 129 }
127 130
128} 131}
129 132
130#endif /* __OPKELE_UTIL_H */ 133#endif /* __OPKELE_UTIL_H */