summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore 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
@@ -39,18 +39,18 @@ namespace opkele {
public:
/**
* xor the secret and hmac together and encode, using base64
- * @param key_sha1 pointer to the sha1 digest
+ * @param key_d pointer to the message digest
* @param rv reference to the return value
*/
- void enxor_to_base64(const unsigned char *key_sha1,string& rv) const;
+ void enxor_to_base64(const unsigned char *key_d,string& rv) const;
/**
- * decode base64-encoded secret and xor it with the sha1 digest
- * @param key_sha1 pointer to the message digest
+ * decode base64-encoded secret and xor it with the message digest
+ * @param key_d pointer to the message digest
* @param b64 base64-encoded secret value
*/
- void enxor_from_base64(const unsigned char *key_sha1,const string& b64);
+ void enxor_from_base64(const unsigned char *key_d,const string& b64);
/**
* plainly encode to base64 representation
* @param rv reference to the return value
*/
@@ -160,8 +160,16 @@ namespace opkele {
* @param prefix the string to prepend to parameter names
* @return the ready-to-use location
*/
string append_query(const string& url,const char *prefix = "openid.") const;
+
+ /**
+ * make up a query string suitable for use in GET and POST
+ * requests.
+ * @param prefix string to prened to parameter names
+ * @return query string
+ */
+ string query_string(const char *prefix = "openid.") const;
};
/**
* dump the key/value pairs for the parameters to the stream.
diff --git a/lib/params.cc b/lib/params.cc
index ea86d3a..7a572c1 100644
--- a/lib/params.cc
+++ b/lib/params.cc
@@ -98,8 +98,21 @@ namespace opkele {
}
return rv;
}
+ string params_t::query_string(const char *prefix) const {
+ string rv;
+ for(const_iterator i=begin();i!=end();++i) {
+ if(!rv.empty())
+ rv += '&';
+ rv += prefix;
+ rv += i->first;
+ rv += '=';
+ rv += util::url_encode(i->second);
+ }
+ return rv;
+ }
+
ostream& operator << (ostream& o,const params_t& p) {
for(params_t::const_iterator i=p.begin();i!=p.end();++i)
o << i->first << ':' << i->second << '\n';
return o;
diff --git a/lib/secret.cc b/lib/secret.cc
index 632a2ca..d538890 100644
--- a/lib/secret.cc
+++ b/lib/secret.cc
@@ -13,33 +13,29 @@ namespace opkele {
return a1^a2;
}
};
- void secret_t::enxor_to_base64(const unsigned char *key_sha1,string& rv) const {
- if(size()!=20)
- throw bad_input(OPKELE_CP_ "wrong secret size");
+ void secret_t::enxor_to_base64(const unsigned char *key_d,string& rv) const {
vector<unsigned char> tmp;
transform(
begin(), end(),
- key_sha1,
+ key_d,
back_insert_iterator<vector<unsigned char> >(tmp),
bitwise_xor<unsigned char,unsigned char,unsigned char>() );
rv = util::encode_base64(&(tmp.front()),tmp.size());
}
- void secret_t::enxor_from_base64(const unsigned char *key_sha1,const string& b64) {
+ void secret_t::enxor_from_base64(const unsigned char *key_d,const string& b64) {
clear();
util::decode_base64(b64,*this);
transform(
begin(), end(),
- key_sha1,
+ key_d,
begin(),
bitwise_xor<unsigned char,unsigned char,unsigned char>() );
}
void secret_t::to_base64(string& rv) const {
- if(size()!=20)
- throw bad_input(OPKELE_CP_ "wrong secret size");
rv = util::encode_base64(&(front()),size());
}
void secret_t::from_base64(const string& b64) {