author | Michael Krelin <hacker@klever.net> | 2007-01-12 12:58:25 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-01-12 12:58:25 (UTC) |
commit | e79687a3d9a1631613de02d8e12bae36302b46ab (patch) (unidiff) | |
tree | 4238c0d8d61f5e70ed1e98debb01315babb21686 /include/opkele | |
parent | 4cc2e58186e8cd9b96a3573c92f6664064cf11fe (diff) | |
download | libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.zip libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.tar.gz libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.tar.bz2 |
eliminated mimetic dependency and made use of openssl base64 encoder instead
-rw-r--r-- | include/opkele/util.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h index 5372498..80d8b03 100644 --- a/include/opkele/util.h +++ b/include/opkele/util.h | |||
@@ -1,59 +1,64 @@ | |||
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 <openssl/bn.h> | 7 | #include <openssl/bn.h> |
7 | #include <openssl/dh.h> | 8 | #include <openssl/dh.h> |
8 | 9 | ||
9 | namespace opkele { | 10 | namespace opkele { |
10 | using std::string; | 11 | using std::string; |
12 | using std::vector; | ||
11 | 13 | ||
12 | namespace util { | 14 | namespace util { |
13 | 15 | ||
14 | class bignum_t { | 16 | class bignum_t { |
15 | public: | 17 | public: |
16 | BIGNUM *_bn; | 18 | BIGNUM *_bn; |
17 | 19 | ||
18 | bignum_t() : _bn(0) { } | 20 | bignum_t() : _bn(0) { } |
19 | bignum_t(BIGNUM *bn) : _bn(bn) { } | 21 | bignum_t(BIGNUM *bn) : _bn(bn) { } |
20 | ~bignum_t() throw() { if(_bn) BN_free(_bn); } | 22 | ~bignum_t() throw() { if(_bn) BN_free(_bn); } |
21 | 23 | ||
22 | bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; } | 24 | bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; } |
23 | 25 | ||
24 | operator const BIGNUM*(void) const { return _bn; } | 26 | operator const BIGNUM*(void) const { return _bn; } |
25 | operator BIGNUM*(void) { return _bn; } | 27 | operator BIGNUM*(void) { return _bn; } |
26 | }; | 28 | }; |
27 | class dh_t { | 29 | class dh_t { |
28 | public: | 30 | public: |
29 | DH *_dh; | 31 | DH *_dh; |
30 | 32 | ||
31 | dh_t() : _dh(0) { } | 33 | dh_t() : _dh(0) { } |
32 | dh_t(DH *dh) : _dh(dh) { } | 34 | dh_t(DH *dh) : _dh(dh) { } |
33 | ~dh_t() throw() { if(_dh) DH_free(_dh); } | 35 | ~dh_t() throw() { if(_dh) DH_free(_dh); } |
34 | 36 | ||
35 | dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; } | 37 | dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; } |
36 | 38 | ||
37 | operator const DH*(void) const { return _dh; } | 39 | operator const DH*(void) const { return _dh; } |
38 | operator DH*(void) { return _dh; } | 40 | operator DH*(void) { return _dh; } |
39 | 41 | ||
40 | DH* operator->() { return _dh; } | 42 | DH* operator->() { return _dh; } |
41 | const DH* operator->() const { return _dh; } | 43 | const DH* operator->() const { return _dh; } |
42 | }; | 44 | }; |
43 | 45 | ||
44 | BIGNUM *base64_to_bignum(const string& b64); | 46 | BIGNUM *base64_to_bignum(const string& b64); |
45 | BIGNUM *dec_to_bignum(const string& dec); | 47 | BIGNUM *dec_to_bignum(const string& dec); |
46 | string bignum_to_base64(const BIGNUM *bn); | 48 | string bignum_to_base64(const BIGNUM *bn); |
47 | 49 | ||
48 | string time_to_w3c(time_t t); | 50 | string time_to_w3c(time_t t); |
49 | time_t w3c_to_time(const string& w); | 51 | time_t w3c_to_time(const string& w); |
50 | 52 | ||
51 | string url_encode(const string& str); | 53 | string url_encode(const string& str); |
52 | 54 | ||
53 | string long_to_string(long l); | 55 | string long_to_string(long l); |
54 | long string_to_long(const string& s); | 56 | long string_to_long(const string& s); |
57 | |||
58 | string encode_base64(const void *data,size_t length); | ||
59 | void decode_base64(const string& data,vector<unsigned char>& rv); | ||
55 | } | 60 | } |
56 | 61 | ||
57 | } | 62 | } |
58 | 63 | ||
59 | #endif /* __OPKELE_UTIL_H */ | 64 | #endif /* __OPKELE_UTIL_H */ |