summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-02-16 17:49:22 (UTC)
committer Michael Krelin <hacker@klever.net>2008-02-16 17:49:22 (UTC)
commit21bddce2d98394865cf2ed0b144f92bbb6993bc9 (patch) (unidiff)
treee30194fab08a704885ae00c711e1707dc73bed83
parentccdfc6eacec435a59d773127762ad0b6bce07149 (diff)
downloadlibopkele-21bddce2d98394865cf2ed0b144f92bbb6993bc9.zip
libopkele-21bddce2d98394865cf2ed0b144f92bbb6993bc9.tar.gz
libopkele-21bddce2d98394865cf2ed0b144f92bbb6993bc9.tar.bz2
moved some stuff out of the now installed util.h header
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/Makefile.am3
-rw-r--r--include/opkele/util-internal.h92
-rw-r--r--include/opkele/util.h92
-rw-r--r--lib/basic_op.cc1
-rw-r--r--lib/basic_rp.cc1
-rw-r--r--lib/consumer.cc1
-rw-r--r--lib/server.cc1
-rw-r--r--test/idiscover.cc1
8 files changed, 110 insertions, 82 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 9f5982c..f842bb9 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -21,2 +21,3 @@ nobase_include_HEADERS = \
21 opkele/basic_op.h opkele/verify_op.h \ 21 opkele/basic_op.h opkele/verify_op.h \
22 opkele/util.h \
22 ${NODIST_HEADERS_} 23 ${NODIST_HEADERS_}
@@ -26,3 +27,3 @@ noinst_HEADERS = \
26 opkele/curl.h opkele/expat.h opkele/tidy.h \ 27 opkele/curl.h opkele/expat.h opkele/tidy.h \
27 opkele/util.h \ 28 opkele/util-internal.h \
28 opkele/debug.h \ 29 opkele/debug.h \
diff --git a/include/opkele/util-internal.h b/include/opkele/util-internal.h
new file mode 100644
index 0000000..ec091ce
--- a/dev/null
+++ b/include/opkele/util-internal.h
@@ -0,0 +1,92 @@
1#ifndef __OPKELE_UTIL_INTERNAL_H
2#define __OPKELE_UTIL_INTERNAL_H
3
4#include <openssl/bn.h>
5#include <openssl/dh.h>
6
7namespace opkele {
8 namespace util {
9
10 /**
11 * Convenience class encapsulating SSL BIGNUM object for the purpose of
12 * automatical freeing.
13 */
14 class bignum_t {
15 public:
16 BIGNUM *_bn;
17
18 bignum_t() : _bn(0) { }
19 bignum_t(BIGNUM *bn) : _bn(bn) { }
20 ~bignum_t() throw() { if(_bn) BN_free(_bn); }
21
22 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; }
23
24 operator const BIGNUM*(void) const { return _bn; }
25 operator BIGNUM*(void) { return _bn; }
26 };
27 /**
28 * Convenience clas encapsulating SSL DH object for the purpose of
29 * automatic freeing.
30 */
31 class dh_t {
32 public:
33 DH *_dh;
34
35 dh_t() : _dh(0) { }
36 dh_t(DH *dh) : _dh(dh) { }
37 ~dh_t() throw() { if(_dh) DH_free(_dh); }
38
39 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; }
40
41 operator const DH*(void) const { return _dh; }
42 operator DH*(void) { return _dh; }
43
44 DH* operator->() { return _dh; }
45 const DH* operator->() const { return _dh; }
46 };
47
48 /**
49 * Convert base64-encoded SSL BIGNUM to internal representation.
50 * @param b64 base64-encoded number
51 * @return SSL BIGNUM
52 * @throw failed_conversion in case of error
53 */
54 BIGNUM *base64_to_bignum(const string& b64);
55 /**
56 * Convert decimal representation to SSL BIGNUM.
57 * @param dec decimal representation
58 * @return resulting BIGNUM
59 * @throw failed_conversion in case of error
60 */
61 BIGNUM *dec_to_bignum(const string& dec);
62 /**
63 * Convert SSL BIGNUM data to base64 encoded string.
64 * @param bn BIGNUM
65 * @return base64encoded string
66 */
67 string bignum_to_base64(const BIGNUM *bn);
68
69 string abi_demangle(const char* mn);
70
71 class change_mode_message_proxy : public basic_openid_message {
72 public:
73 const basic_openid_message& x;
74 const string& mode;
75
76 change_mode_message_proxy(const basic_openid_message& xx,const string& m) : x(xx), mode(m) { }
77
78 bool has_field(const string& n) const { return x.has_field(n); }
79 const string& get_field(const string& n) const {
80 return (n=="mode")?mode:x.get_field(n); }
81 bool has_ns(const string& uri) const {return x.has_ns(uri); }
82 string get_ns(const string& uri) const { return x.get_ns(uri); }
83 fields_iterator fields_begin() const {
84 return x.fields_begin(); }
85 fields_iterator fields_end() const {
86 return x.fields_end(); }
87 };
88
89 }
90}
91
92#endif /* __OPKELE_UTIL_INTERNAL_H */
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
@@ -6,4 +6,2 @@
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>
@@ -20,61 +18,2 @@ namespace opkele {
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
@@ -155,26 +94,17 @@ namespace opkele {
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 }
diff --git a/lib/basic_op.cc b/lib/basic_op.cc
index c247493..fa659ac 100644
--- a/lib/basic_op.cc
+++ b/lib/basic_op.cc
@@ -8,2 +8,3 @@
8#include <opkele/util.h> 8#include <opkele/util.h>
9#include <opkele/util-internal.h>
9#include <opkele/uris.h> 10#include <opkele/uris.h>
diff --git a/lib/basic_rp.cc b/lib/basic_rp.cc
index a0ad130..e65d9fb 100644
--- a/lib/basic_rp.cc
+++ b/lib/basic_rp.cc
@@ -8,2 +8,3 @@
8#include <opkele/util.h> 8#include <opkele/util.h>
9#include <opkele/util-internal.h>
9#include <opkele/curl.h> 10#include <opkele/curl.h>
diff --git a/lib/consumer.cc b/lib/consumer.cc
index ebda262..801496e 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -4,2 +4,3 @@
4#include <opkele/util.h> 4#include <opkele/util.h>
5#include <opkele/util-internal.h>
5#include <opkele/curl.h> 6#include <opkele/curl.h>
diff --git a/lib/server.cc b/lib/server.cc
index 776f1ae..0dea1eb 100644
--- a/lib/server.cc
+++ b/lib/server.cc
@@ -5,2 +5,3 @@
5#include <opkele/util.h> 5#include <opkele/util.h>
6#include <opkele/util-internal.h>
6#include <opkele/exception.h> 7#include <opkele/exception.h>
diff --git a/test/idiscover.cc b/test/idiscover.cc
index 44df9ce..4b1e90c 100644
--- a/test/idiscover.cc
+++ b/test/idiscover.cc
@@ -8,2 +8,3 @@ using namespace std;
8#include <opkele/util.h> 8#include <opkele/util.h>
9#include <opkele/util-internal.h>
9 10