author | Michael Krelin <hacker@klever.net> | 2008-02-16 17:49:22 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-02-16 17:49:22 (UTC) |
commit | 21bddce2d98394865cf2ed0b144f92bbb6993bc9 (patch) (unidiff) | |
tree | e30194fab08a704885ae00c711e1707dc73bed83 | |
parent | ccdfc6eacec435a59d773127762ad0b6bce07149 (diff) | |
download | libopkele-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>
-rw-r--r-- | include/Makefile.am | 3 | ||||
-rw-r--r-- | include/opkele/util-internal.h | 92 | ||||
-rw-r--r-- | include/opkele/util.h | 92 | ||||
-rw-r--r-- | lib/basic_op.cc | 1 | ||||
-rw-r--r-- | lib/basic_rp.cc | 1 | ||||
-rw-r--r-- | lib/consumer.cc | 1 | ||||
-rw-r--r-- | lib/server.cc | 1 | ||||
-rw-r--r-- | test/idiscover.cc | 1 |
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 | |||
@@ -19,12 +19,13 @@ nobase_include_HEADERS = \ | |||
19 | opkele/basic_rp.h opkele/prequeue_rp.h \ | 19 | opkele/basic_rp.h opkele/prequeue_rp.h \ |
20 | opkele/iterator.h \ | 20 | opkele/iterator.h \ |
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_} |
23 | 24 | ||
24 | noinst_HEADERS = \ | 25 | noinst_HEADERS = \ |
25 | opkele/data.h \ | 26 | opkele/data.h \ |
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 \ |
29 | opkele/discovery.h | 30 | opkele/discovery.h |
30 | 31 | ||
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 | |||
7 | namespace 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 | |||
@@ -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 | ||
11 | namespace opkele { | 9 | namespace 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 | } |
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 | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <opkele/basic_op.h> | 6 | #include <opkele/basic_op.h> |
7 | #include <opkele/exception.h> | 7 | #include <opkele/exception.h> |
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> |
10 | 11 | ||
11 | namespace opkele { | 12 | namespace opkele { |
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 | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <opkele/uris.h> | 6 | #include <opkele/uris.h> |
7 | #include <opkele/data.h> | 7 | #include <opkele/data.h> |
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> |
10 | 11 | ||
11 | namespace opkele { | 12 | namespace opkele { |
diff --git a/lib/consumer.cc b/lib/consumer.cc index ebda262..801496e 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <cassert> | 2 | #include <cassert> |
3 | #include <cstring> | 3 | #include <cstring> |
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> |
6 | #include <opkele/exception.h> | 7 | #include <opkele/exception.h> |
7 | #include <opkele/data.h> | 8 | #include <opkele/data.h> |
diff --git a/lib/server.cc b/lib/server.cc index 776f1ae..0dea1eb 100644 --- a/lib/server.cc +++ b/lib/server.cc | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <openssl/sha.h> | 3 | #include <openssl/sha.h> |
4 | #include <openssl/hmac.h> | 4 | #include <openssl/hmac.h> |
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> |
7 | #include <opkele/server.h> | 8 | #include <opkele/server.h> |
8 | #include <opkele/data.h> | 9 | #include <opkele/data.h> |
diff --git a/test/idiscover.cc b/test/idiscover.cc index 44df9ce..4b1e90c 100644 --- a/test/idiscover.cc +++ b/test/idiscover.cc | |||
@@ -6,6 +6,7 @@ using namespace std; | |||
6 | #include <opkele/exception.h> | 6 | #include <opkele/exception.h> |
7 | #include <opkele/discovery.h> | 7 | #include <opkele/discovery.h> |
8 | #include <opkele/util.h> | 8 | #include <opkele/util.h> |
9 | #include <opkele/util-internal.h> | ||
9 | 10 | ||
10 | namespace opkele { | 11 | namespace opkele { |
11 | ostream& operator<<(ostream& o,const opkele::openid_endpoint_t& oep) { | 12 | ostream& operator<<(ostream& o,const opkele::openid_endpoint_t& oep) { |