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.h92
1 files changed, 11 insertions, 81 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h
index bc1a0ea..60955e1 100644
--- a/include/opkele/util.h
+++ b/include/opkele/util.h
@@ -4,8 +4,6 @@
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>
8#include <openssl/dh.h>
9#include <opkele/types.h> 7#include <opkele/types.h>
10 8
11namespace opkele { 9namespace opkele {
@@ -18,65 +16,6 @@ namespace opkele {
18 namespace util { 16 namespace util {
19 17
20 /** 18 /**
21 * Convenience class encapsulating SSL BIGNUM object for the purpose of
22 * automatical freeing.
23 */
24 class bignum_t {
25 public:
26 BIGNUM *_bn;
27
28 bignum_t() : _bn(0) { }
29 bignum_t(BIGNUM *bn) : _bn(bn) { }
30 ~bignum_t() throw() { if(_bn) BN_free(_bn); }
31
32 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; }
33
34 operator const BIGNUM*(void) const { return _bn; }
35 operator BIGNUM*(void) { return _bn; }
36 };
37 /**
38 * Convenience clas encapsulating SSL DH object for the purpose of
39 * automatic freeing.
40 */
41 class dh_t {
42 public:
43 DH *_dh;
44
45 dh_t() : _dh(0) { }
46 dh_t(DH *dh) : _dh(dh) { }
47 ~dh_t() throw() { if(_dh) DH_free(_dh); }
48
49 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; }
50
51 operator const DH*(void) const { return _dh; }
52 operator DH*(void) { return _dh; }
53
54 DH* operator->() { return _dh; }
55 const DH* operator->() const { return _dh; }
56 };
57
58 /**
59 * Convert base64-encoded SSL BIGNUM to internal representation.
60 * @param b64 base64-encoded number
61 * @return SSL BIGNUM
62 * @throw failed_conversion in case of error
63 */
64 BIGNUM *base64_to_bignum(const string& b64);
65 /**
66 * Convert decimal representation to SSL BIGNUM.
67 * @param dec decimal representation
68 * @return resulting BIGNUM
69 * @throw failed_conversion in case of error
70 */
71 BIGNUM *dec_to_bignum(const string& dec);
72 /**
73 * Convert SSL BIGNUM data to base64 encoded string.
74 * @param bn BIGNUM
75 * @return base64encoded string
76 */
77 string bignum_to_base64(const BIGNUM *bn);
78
79 /**
80 * Convert internal time representation to w3c format 19 * Convert internal time representation to w3c format
81 * @param t internal representation 20 * @param t internal representation
82 * @return w3c time 21 * @return w3c time
@@ -153,30 +92,21 @@ namespace opkele {
153 */ 92 */
154 bool uri_matches_realm(const string& uri,const string& realm); 93 bool uri_matches_realm(const string& uri,const string& realm);
155 94
95 /**
96 * Strip fragment part from URI
97 * @param uri input/output parameter containing the URI
98 * @return reference to uri
99 */
156 string& strip_uri_fragment_part(string& uri); 100 string& strip_uri_fragment_part(string& uri);
157 101
158 string abi_demangle(const char* mn); 102 /**
159 103 * Calculate signature and encode it using base64
104 * @param assoc association being used for signing
105 * @param om openid message
106 * @return base64 representation of the signature
107 */
160 string base64_signature(const assoc_t& assoc,const basic_openid_message& om); 108 string base64_signature(const assoc_t& assoc,const basic_openid_message& om);
161 109
162 class change_mode_message_proxy : public basic_openid_message {
163 public:
164 const basic_openid_message& x;
165 const string& mode;
166
167 change_mode_message_proxy(const basic_openid_message& xx,const string& m) : x(xx), mode(m) { }
168
169 bool has_field(const string& n) const { return x.has_field(n); }
170 const string& get_field(const string& n) const {
171 return (n=="mode")?mode:x.get_field(n); }
172 bool has_ns(const string& uri) const {return x.has_ns(uri); }
173 string get_ns(const string& uri) const { return x.get_ns(uri); }
174 fields_iterator fields_begin() const {
175 return x.fields_begin(); }
176 fields_iterator fields_end() const {
177 return x.fields_end(); }
178 };
179
180 } 110 }
181 111
182} 112}