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.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h
index 2a7a859..edc1859 100644
--- a/include/opkele/util.h
+++ b/include/opkele/util.h
@@ -1,77 +1,80 @@
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 <vector>
7#include <openssl/bn.h> 7#include <openssl/bn.h>
8#include <openssl/dh.h> 8#include <openssl/dh.h>
9 9
10namespace opkele { 10namespace opkele {
11 using std::string; 11 using std::string;
12 using std::vector; 12 using std::vector;
13 13
14 /**
15 * @brief opkele utils namespace
16 */
14 namespace util { 17 namespace util {
15 18
16 /** 19 /**
17 * Convenience class encapsulating SSL BIGNUM object for the purpose of 20 * Convenience class encapsulating SSL BIGNUM object for the purpose of
18 * automatical freeing. 21 * automatical freeing.
19 */ 22 */
20 class bignum_t { 23 class bignum_t {
21 public: 24 public:
22 BIGNUM *_bn; 25 BIGNUM *_bn;
23 26
24 bignum_t() : _bn(0) { } 27 bignum_t() : _bn(0) { }
25 bignum_t(BIGNUM *bn) : _bn(bn) { } 28 bignum_t(BIGNUM *bn) : _bn(bn) { }
26 ~bignum_t() throw() { if(_bn) BN_free(_bn); } 29 ~bignum_t() throw() { if(_bn) BN_free(_bn); }
27 30
28 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; } 31 bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; }
29 32
30 operator const BIGNUM*(void) const { return _bn; } 33 operator const BIGNUM*(void) const { return _bn; }
31 operator BIGNUM*(void) { return _bn; } 34 operator BIGNUM*(void) { return _bn; }
32 }; 35 };
33 /** 36 /**
34 * Convenience clas encapsulating SSL DH object for the purpose of 37 * Convenience clas encapsulating SSL DH object for the purpose of
35 * automatic freeing. 38 * automatic freeing.
36 */ 39 */
37 class dh_t { 40 class dh_t {
38 public: 41 public:
39 DH *_dh; 42 DH *_dh;
40 43
41 dh_t() : _dh(0) { } 44 dh_t() : _dh(0) { }
42 dh_t(DH *dh) : _dh(dh) { } 45 dh_t(DH *dh) : _dh(dh) { }
43 ~dh_t() throw() { if(_dh) DH_free(_dh); } 46 ~dh_t() throw() { if(_dh) DH_free(_dh); }
44 47
45 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; } 48 dh_t& operator=(DH *dh) { if(_dh) DH_free(_dh); _dh = dh; return *this; }
46 49
47 operator const DH*(void) const { return _dh; } 50 operator const DH*(void) const { return _dh; }
48 operator DH*(void) { return _dh; } 51 operator DH*(void) { return _dh; }
49 52
50 DH* operator->() { return _dh; } 53 DH* operator->() { return _dh; }
51 const DH* operator->() const { return _dh; } 54 const DH* operator->() const { return _dh; }
52 }; 55 };
53 56
54 /** 57 /**
55 * Convert base64-encoded SSL BIGNUM to internal representation. 58 * Convert base64-encoded SSL BIGNUM to internal representation.
56 * @param b64 base64-encoded number 59 * @param b64 base64-encoded number
57 * @return SSL BIGNUM 60 * @return SSL BIGNUM
58 * @throw failed_conversion in case of error 61 * @throw failed_conversion in case of error
59 */ 62 */
60 BIGNUM *base64_to_bignum(const string& b64); 63 BIGNUM *base64_to_bignum(const string& b64);
61 /** 64 /**
62 * Convert decimal representation to SSL BIGNUM. 65 * Convert decimal representation to SSL BIGNUM.
63 * @param dec decimal representation 66 * @param dec decimal representation
64 * @return resulting BIGNUM 67 * @return resulting BIGNUM
65 * @throw failed_conversion in case of error 68 * @throw failed_conversion in case of error
66 */ 69 */
67 BIGNUM *dec_to_bignum(const string& dec); 70 BIGNUM *dec_to_bignum(const string& dec);
68 /** 71 /**
69 * Convert SSL BIGNUM data to base64 encoded string. 72 * Convert SSL BIGNUM data to base64 encoded string.
70 * @param bn BIGNUM 73 * @param bn BIGNUM
71 * @return base64encoded string 74 * @return base64encoded string
72 */ 75 */
73 string bignum_to_base64(const BIGNUM *bn); 76 string bignum_to_base64(const BIGNUM *bn);
74 77
75 /** 78 /**
76 * Convert internal time representation to w3c format 79 * Convert internal time representation to w3c format
77 * @param t internal representation 80 * @param t internal representation