-rw-r--r-- | include/opkele/util.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h new file mode 100644 index 0000000..fbbef93 --- a/dev/null +++ b/include/opkele/util.h | |||
@@ -0,0 +1,60 @@ | |||
1 | #ifndef __OPKELE_UTIL_H | ||
2 | #define __OPKELE_UTIL_H | ||
3 | |||
4 | #include <time.h> | ||
5 | #include <string> | ||
6 | #include <openssl/bn.h> | ||
7 | #include <openssl/dh.h> | ||
8 | |||
9 | namespace opkele { | ||
10 | using std::string; | ||
11 | |||
12 | namespace util { | ||
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 | class dh_t { | ||
28 | public: | ||
29 | DH *_dh; | ||
30 | |||
31 | dh_t() : _dh(0) { } | ||
32 | dh_t(DH *dh) : _dh(dh) { } | ||
33 | ~dh_t() throw() { if(_dh) DH_free(_dh); } | ||
34 | |||
35 | dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; } | ||
36 | |||
37 | operator const DH*(void) const { return _dh; } | ||
38 | operator DH*(void) { return _dh; } | ||
39 | |||
40 | DH* operator->() { return _dh; } | ||
41 | const DH* operator->() const { return _dh; } | ||
42 | }; | ||
43 | |||
44 | BIGNUM *base64_to_bignum(const string& b64); | ||
45 | BIGNUM *dec_to_bignum(const string& dec); | ||
46 | string bignum_to_base64(const BIGNUM *bn); | ||
47 | |||
48 | string time_to_w3c(time_t t); | ||
49 | time_t w3c_to_time(const string& w); | ||
50 | |||
51 | string canonicalize_url(const string& url); | ||
52 | string url_encode(const string& str); | ||
53 | |||
54 | string long_to_string(long l); | ||
55 | long string_to_long(const string& s); | ||
56 | } | ||
57 | |||
58 | } | ||
59 | |||
60 | #endif /* __OPKELE_UTIL_H */ | ||