summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/util.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h
index 80d8b03..2a7a859 100644
--- a/include/opkele/util.h
+++ b/include/opkele/util.h
@@ -15,2 +15,6 @@ namespace opkele {
15 15
16 /**
17 * Convenience class encapsulating SSL BIGNUM object for the purpose of
18 * automatical freeing.
19 */
16 class bignum_t { 20 class bignum_t {
@@ -28,2 +32,6 @@ namespace opkele {
28 }; 32 };
33 /**
34 * Convenience clas encapsulating SSL DH object for the purpose of
35 * automatic freeing.
36 */
29 class dh_t { 37 class dh_t {
@@ -45,15 +53,73 @@ namespace opkele {
45 53
54 /**
55 * Convert base64-encoded SSL BIGNUM to internal representation.
56 * @param b64 base64-encoded number
57 * @return SSL BIGNUM
58 * @throw failed_conversion in case of error
59 */
46 BIGNUM *base64_to_bignum(const string& b64); 60 BIGNUM *base64_to_bignum(const string& b64);
61 /**
62 * Convert decimal representation to SSL BIGNUM.
63 * @param dec decimal representation
64 * @return resulting BIGNUM
65 * @throw failed_conversion in case of error
66 */
47 BIGNUM *dec_to_bignum(const string& dec); 67 BIGNUM *dec_to_bignum(const string& dec);
68 /**
69 * Convert SSL BIGNUM data to base64 encoded string.
70 * @param bn BIGNUM
71 * @return base64encoded string
72 */
48 string bignum_to_base64(const BIGNUM *bn); 73 string bignum_to_base64(const BIGNUM *bn);
49 74
75 /**
76 * Convert internal time representation to w3c format
77 * @param t internal representation
78 * @return w3c time
79 * @throw failed_conversion in case of error
80 */
50 string time_to_w3c(time_t t); 81 string time_to_w3c(time_t t);
82 /**
83 * Convert W3C time representation to internal time_t
84 * @param w w3c representation
85 * @return converted time
86 * @throw failed_conversion in case of error
87 */
51 time_t w3c_to_time(const string& w); 88 time_t w3c_to_time(const string& w);
52 89
90 /**
91 * Encode string to the representation suitable for using in URL.
92 * @param str string to encode
93 * @return encoded string
94 * @throw failed_conversion in case of failure
95 */
53 string url_encode(const string& str); 96 string url_encode(const string& str);
54 97
98 /**
99 * Convert number to string
100 * @param l number
101 * @return string representation
102 * @throw failed_conversion in case of failure
103 */
55 string long_to_string(long l); 104 string long_to_string(long l);
105 /**
106 * Convert string to number
107 * @param s string, containing the number
108 * @return the number
109 * @throw failed_conversion in case of failure
110 */
56 long string_to_long(const string& s); 111 long string_to_long(const string& s);
57 112
113 /**
114 * Encode binary data using base64.
115 * @param data pointer to binary data
116 * @param length length of data
117 * @return encoded data
118 */
58 string encode_base64(const void *data,size_t length); 119 string encode_base64(const void *data,size_t length);
120 /**
121 * Decode binary data from base64 representation.
122 * @param data base64-encoded data
123 * @param rv container for decoded binary
124 */
59 void decode_base64(const string& data,vector<unsigned char>& rv); 125 void decode_base64(const string& data,vector<unsigned char>& rv);