summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--include/opkele/types.h18
-rw-r--r--lib/params.cc13
-rw-r--r--lib/secret.cc12
3 files changed, 30 insertions, 13 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h
index 520618d..ca07df5 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -40,16 +40,16 @@ namespace opkele {
40 40
41 /** 41 /**
42 * xor the secret and hmac together and encode, using base64 42 * xor the secret and hmac together and encode, using base64
43 * @param key_sha1 pointer to the sha1 digest 43 * @param key_d pointer to the message digest
44 * @param rv reference to the return value 44 * @param rv reference to the return value
45 */ 45 */
46 void enxor_to_base64(const unsigned char *key_sha1,string& rv) const; 46 void enxor_to_base64(const unsigned char *key_d,string& rv) const;
47 /** 47 /**
48 * decode base64-encoded secret and xor it with the sha1 digest 48 * decode base64-encoded secret and xor it with the message digest
49 * @param key_sha1 pointer to the message digest 49 * @param key_d pointer to the message digest
50 * @param b64 base64-encoded secret value 50 * @param b64 base64-encoded secret value
51 */ 51 */
52 void enxor_from_base64(const unsigned char *key_sha1,const string& b64); 52 void enxor_from_base64(const unsigned char *key_d,const string& b64);
53 /** 53 /**
54 * plainly encode to base64 representation 54 * plainly encode to base64 representation
55 * @param rv reference to the return value 55 * @param rv reference to the return value
@@ -161,6 +161,14 @@ namespace opkele {
161 * @return the ready-to-use location 161 * @return the ready-to-use location
162 */ 162 */
163 string append_query(const string& url,const char *prefix = "openid.") const; 163 string append_query(const string& url,const char *prefix = "openid.") const;
164
165 /**
166 * make up a query string suitable for use in GET and POST
167 * requests.
168 * @param prefix string to prened to parameter names
169 * @return query string
170 */
171 string query_string(const char *prefix = "openid.") const;
164 }; 172 };
165 173
166 /** 174 /**
diff --git a/lib/params.cc b/lib/params.cc
index ea86d3a..7a572c1 100644
--- a/lib/params.cc
+++ b/lib/params.cc
@@ -99,6 +99,19 @@ namespace opkele {
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';
diff --git a/lib/secret.cc b/lib/secret.cc
index 632a2ca..d538890 100644
--- a/lib/secret.cc
+++ b/lib/secret.cc
@@ -14,31 +14,27 @@ namespace opkele {
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