-rw-r--r-- | lib/params.cc | 13 | ||||
-rw-r--r-- | lib/secret.cc | 12 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/params.cc b/lib/params.cc index ea86d3a..7a572c1 100644 --- a/lib/params.cc +++ b/lib/params.cc | |||
@@ -90,19 +90,32 @@ namespace opkele { | |||
90 | if(p) | 90 | if(p) |
91 | rv += '&'; | 91 | rv += '&'; |
92 | else | 92 | else |
93 | p = true; | 93 | p = true; |
94 | rv += prefix; | 94 | rv += prefix; |
95 | rv += i->first; | 95 | rv += i->first; |
96 | rv += '='; | 96 | rv += '='; |
97 | rv += util::url_encode(i->second); | 97 | rv += util::url_encode(i->second); |
98 | } | 98 | } |
99 | return rv; | 99 | return rv; |
100 | } | 100 | } |
101 | 101 | ||
102 | string params_t::query_string(const char *prefix) const { | ||
103 | string rv; | ||
104 | for(const_iterator i=begin();i!=end();++i) { | ||
105 | if(!rv.empty()) | ||
106 | rv += '&'; | ||
107 | rv += prefix; | ||
108 | rv += i->first; | ||
109 | rv += '='; | ||
110 | rv += util::url_encode(i->second); | ||
111 | } | ||
112 | return rv; | ||
113 | } | ||
114 | |||
102 | ostream& operator << (ostream& o,const params_t& p) { | 115 | ostream& operator << (ostream& o,const params_t& p) { |
103 | for(params_t::const_iterator i=p.begin();i!=p.end();++i) | 116 | for(params_t::const_iterator i=p.begin();i!=p.end();++i) |
104 | o << i->first << ':' << i->second << '\n'; | 117 | o << i->first << ':' << i->second << '\n'; |
105 | return o; | 118 | return o; |
106 | } | 119 | } |
107 | 120 | ||
108 | } | 121 | } |
diff --git a/lib/secret.cc b/lib/secret.cc index 632a2ca..d538890 100644 --- a/lib/secret.cc +++ b/lib/secret.cc | |||
@@ -5,45 +5,41 @@ | |||
5 | #include <opkele/util.h> | 5 | #include <opkele/util.h> |
6 | 6 | ||
7 | namespace opkele { | 7 | namespace opkele { |
8 | using namespace std; | 8 | using namespace std; |
9 | 9 | ||
10 | template<class __a1,class __a2,class __r> | 10 | template<class __a1,class __a2,class __r> |
11 | struct bitwise_xor : public binary_function<__a1,__a2,__r> { | 11 | struct bitwise_xor : public binary_function<__a1,__a2,__r> { |
12 | __r operator() (const __a1& a1,const __a2& a2) const { | 12 | __r operator() (const __a1& a1,const __a2& a2) const { |
13 | return a1^a2; | 13 | return a1^a2; |
14 | } | 14 | } |
15 | }; | 15 | }; |
16 | 16 | ||
17 | void secret_t::enxor_to_base64(const unsigned char *key_sha1,string& rv) const { | 17 | void secret_t::enxor_to_base64(const unsigned char *key_d,string& rv) const { |
18 | if(size()!=20) | ||
19 | throw bad_input(OPKELE_CP_ "wrong secret size"); | ||
20 | vector<unsigned char> tmp; | 18 | vector<unsigned char> tmp; |
21 | transform( | 19 | transform( |
22 | begin(), end(), | 20 | begin(), end(), |
23 | key_sha1, | 21 | key_d, |
24 | back_insert_iterator<vector<unsigned char> >(tmp), | 22 | back_insert_iterator<vector<unsigned char> >(tmp), |
25 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); | 23 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); |
26 | rv = util::encode_base64(&(tmp.front()),tmp.size()); | 24 | rv = util::encode_base64(&(tmp.front()),tmp.size()); |
27 | } | 25 | } |
28 | 26 | ||
29 | void secret_t::enxor_from_base64(const unsigned char *key_sha1,const string& b64) { | 27 | void secret_t::enxor_from_base64(const unsigned char *key_d,const string& b64) { |
30 | clear(); | 28 | clear(); |
31 | util::decode_base64(b64,*this); | 29 | util::decode_base64(b64,*this); |
32 | transform( | 30 | transform( |
33 | begin(), end(), | 31 | begin(), end(), |
34 | key_sha1, | 32 | key_d, |
35 | begin(), | 33 | begin(), |
36 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); | 34 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); |
37 | } | 35 | } |
38 | 36 | ||
39 | void secret_t::to_base64(string& rv) const { | 37 | void secret_t::to_base64(string& rv) const { |
40 | if(size()!=20) | ||
41 | throw bad_input(OPKELE_CP_ "wrong secret size"); | ||
42 | rv = util::encode_base64(&(front()),size()); | 38 | rv = util::encode_base64(&(front()),size()); |
43 | } | 39 | } |
44 | 40 | ||
45 | void secret_t::from_base64(const string& b64) { | 41 | void secret_t::from_base64(const string& b64) { |
46 | util::decode_base64(b64,*this); | 42 | util::decode_base64(b64,*this); |
47 | } | 43 | } |
48 | 44 | ||
49 | } | 45 | } |