summaryrefslogtreecommitdiffabout
path: root/include/opkele/util.h
authorMichael Krelin <hacker@klever.net>2008-01-20 21:08:05 (UTC)
committer Michael Krelin <hacker@klever.net>2008-01-20 21:08:05 (UTC)
commit9bfb6fadf71c46bf4cb5adabba0c96c32e84c1bc (patch) (unidiff)
tree702473142242e80538c4801cc379ec98fba199dd /include/opkele/util.h
parent395a126cbf59b7a50f44da3096b68bab412ab33d (diff)
downloadlibopkele-9bfb6fadf71c46bf4cb5adabba0c96c32e84c1bc.zip
libopkele-9bfb6fadf71c46bf4cb5adabba0c96c32e84c1bc.tar.gz
libopkele-9bfb6fadf71c46bf4cb5adabba0c96c32e84c1bc.tar.bz2
the whole library rewritten
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'include/opkele/util.h') (more/less context) (show whitespace changes)
-rw-r--r--include/opkele/util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h
index 085c9e6..e9176b0 100644
--- a/include/opkele/util.h
+++ b/include/opkele/util.h
@@ -1,56 +1,57 @@
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#include <opkele/types.h>
9 10
10namespace opkele { 11namespace opkele {
11 using std::string; 12 using std::string;
12 using std::vector; 13 using std::vector;
13 14
14 /** 15 /**
15 * @brief opkele utils namespace 16 * @brief opkele utils namespace
16 */ 17 */
17 namespace util { 18 namespace util {
18 19
19 /** 20 /**
20 * Convenience class encapsulating SSL BIGNUM object for the purpose of 21 * Convenience class encapsulating SSL BIGNUM object for the purpose of
21 * automatical freeing. 22 * automatical freeing.
22 */ 23 */
23 class bignum_t { 24 class bignum_t {
24 public: 25 public:
25 BIGNUM *_bn; 26 BIGNUM *_bn;
26 27
27 bignum_t() : _bn(0) { } 28 bignum_t() : _bn(0) { }
28 bignum_t(BIGNUM *bn) : _bn(bn) { } 29 bignum_t(BIGNUM *bn) : _bn(bn) { }
29 ~bignum_t() throw() { if(_bn) BN_free(_bn); } 30 ~bignum_t() throw() { if(_bn) BN_free(_bn); }
30 31
31 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; } 32 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; }
32 33
33 operator const BIGNUM*(void) const { return _bn; } 34 operator const BIGNUM*(void) const { return _bn; }
34 operator BIGNUM*(void) { return _bn; } 35 operator BIGNUM*(void) { return _bn; }
35 }; 36 };
36 /** 37 /**
37 * Convenience clas encapsulating SSL DH object for the purpose of 38 * Convenience clas encapsulating SSL DH object for the purpose of
38 * automatic freeing. 39 * automatic freeing.
39 */ 40 */
40 class dh_t { 41 class dh_t {
41 public: 42 public:
42 DH *_dh; 43 DH *_dh;
43 44
44 dh_t() : _dh(0) { } 45 dh_t() : _dh(0) { }
45 dh_t(DH *dh) : _dh(dh) { } 46 dh_t(DH *dh) : _dh(dh) { }
46 ~dh_t() throw() { if(_dh) DH_free(_dh); } 47 ~dh_t() throw() { if(_dh) DH_free(_dh); }
47 48
48 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; } 49 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; }
49 50
50 operator const DH*(void) const { return _dh; } 51 operator const DH*(void) const { return _dh; }
51 operator DH*(void) { return _dh; } 52 operator DH*(void) { return _dh; }
52 53
53 DH* operator->() { return _dh; } 54 DH* operator->() { return _dh; }
54 const DH* operator->() const { return _dh; } 55 const DH* operator->() const { return _dh; }
55 }; 56 };
56 57
@@ -91,53 +92,60 @@ namespace opkele {
91 time_t w3c_to_time(const string& w); 92 time_t w3c_to_time(const string& w);
92 93
93 /** 94 /**
94 * Encode string to the representation suitable for using in URL. 95 * Encode string to the representation suitable for using in URL.
95 * @param str string to encode 96 * @param str string to encode
96 * @return encoded string 97 * @return encoded string
97 * @throw failed_conversion in case of failure 98 * @throw failed_conversion in case of failure
98 */ 99 */
99 string url_encode(const string& str); 100 string url_encode(const string& str);
100 101
101 /** 102 /**
102 * Convert number to string 103 * Convert number to string
103 * @param l number 104 * @param l number
104 * @return string representation 105 * @return string representation
105 * @throw failed_conversion in case of failure 106 * @throw failed_conversion in case of failure
106 */ 107 */
107 string long_to_string(long l); 108 string long_to_string(long l);
108 /** 109 /**
109 * Convert string to number 110 * Convert string to number
110 * @param s string, containing the number 111 * @param s string, containing the number
111 * @return the number 112 * @return the number
112 * @throw failed_conversion in case of failure 113 * @throw failed_conversion in case of failure
113 */ 114 */
114 long string_to_long(const string& s); 115 long string_to_long(const string& s);
115 116
116 /** 117 /**
117 * Encode binary data using base64. 118 * Encode binary data using base64.
118 * @param data pointer to binary data 119 * @param data pointer to binary data
119 * @param length length of data 120 * @param length length of data
120 * @return encoded data 121 * @return encoded data
121 */ 122 */
122 string encode_base64(const void *data,size_t length); 123 string encode_base64(const void *data,size_t length);
123 /** 124 /**
124 * Decode binary data from base64 representation. 125 * Decode binary data from base64 representation.
125 * @param data base64-encoded data 126 * @param data base64-encoded data
126 * @param rv container for decoded binary 127 * @param rv container for decoded binary
127 */ 128 */
128 void decode_base64(const string& data,vector<unsigned char>& rv); 129 void decode_base64(const string& data,vector<unsigned char>& rv);
129 130
130 /** 131 /**
131 * Normalize http(s) URI according to RFC3986, section 6. URI is 132 * Normalize http(s) URI according to RFC3986, section 6. URI is
132 * expected to have scheme: in front of it. 133 * expected to have scheme: in front of it.
133 * @param uri URI 134 * @param uri URI
134 * @return normalized URI 135 * @return normalized URI
135 * @throw not_implemented in case of non-httpi(s) URI 136 * @throw not_implemented in case of non-httpi(s) URI
136 * @throw bad_input in case of malformed URI 137 * @throw bad_input in case of malformed URI
137 */ 138 */
138 string rfc_3986_normalize_uri(const string& uri); 139 string rfc_3986_normalize_uri(const string& uri);
140
141 string& strip_uri_fragment_part(string& uri);
142
143 string abi_demangle(const char* mn);
144
145 string base64_signature(const assoc_t& assoc,const basic_openid_message& om);
146
139 } 147 }
140 148
141} 149}
142 150
143#endif /* __OPKELE_UTIL_H */ 151#endif /* __OPKELE_UTIL_H */