author | Michael Krelin <hacker@klever.net> | 2008-03-03 14:58:09 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-03-03 14:58:09 (UTC) |
commit | 0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be (patch) (unidiff) | |
tree | 0e435d48a9d2b94ff309c8fea2d416e0e14d8b2a /include/opkele/types.h | |
parent | 5fd5ecad8c2bd1e8846c11fa9b281f0f4ab8a4a7 (diff) | |
download | libopkele-0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be.zip libopkele-0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be.tar.gz libopkele-0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be.tar.bz2 |
added append_to() to basic_openid_message
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | include/opkele/types.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h index af7fb1a..ffb9afb 100644 --- a/include/opkele/types.h +++ b/include/opkele/types.h | |||
@@ -36,192 +36,193 @@ namespace opkele { | |||
36 | mode_checkid_immediate, | 36 | mode_checkid_immediate, |
37 | mode_checkid_setup, | 37 | mode_checkid_setup, |
38 | mode_check_association | 38 | mode_check_association |
39 | } mode_t; | 39 | } mode_t; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * the association secret container | 42 | * the association secret container |
43 | */ | 43 | */ |
44 | class secret_t : public vector<unsigned char> { | 44 | class secret_t : public vector<unsigned char> { |
45 | public: | 45 | public: |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * xor the secret and hmac together and encode, using base64 | 48 | * xor the secret and hmac together and encode, using base64 |
49 | * @param key_d pointer to the message digest | 49 | * @param key_d pointer to the message digest |
50 | * @param rv reference to the return value | 50 | * @param rv reference to the return value |
51 | */ | 51 | */ |
52 | void enxor_to_base64(const unsigned char *key_d,string& rv) const; | 52 | void enxor_to_base64(const unsigned char *key_d,string& rv) const; |
53 | /** | 53 | /** |
54 | * decode base64-encoded secret and xor it with the message digest | 54 | * decode base64-encoded secret and xor it with the message digest |
55 | * @param key_d pointer to the message digest | 55 | * @param key_d pointer to the message digest |
56 | * @param b64 base64-encoded secret value | 56 | * @param b64 base64-encoded secret value |
57 | */ | 57 | */ |
58 | void enxor_from_base64(const unsigned char *key_d,const string& b64); | 58 | void enxor_from_base64(const unsigned char *key_d,const string& b64); |
59 | /** | 59 | /** |
60 | * plainly encode to base64 representation | 60 | * plainly encode to base64 representation |
61 | * @param rv reference to the return value | 61 | * @param rv reference to the return value |
62 | */ | 62 | */ |
63 | void to_base64(string& rv) const; | 63 | void to_base64(string& rv) const; |
64 | /** | 64 | /** |
65 | * decode cleartext secret from base64 | 65 | * decode cleartext secret from base64 |
66 | * @param b64 base64-encoded representation of the secret value | 66 | * @param b64 base64-encoded representation of the secret value |
67 | */ | 67 | */ |
68 | void from_base64(const string& b64); | 68 | void from_base64(const string& b64); |
69 | }; | 69 | }; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * Interface to the association. | 72 | * Interface to the association. |
73 | */ | 73 | */ |
74 | class association_t { | 74 | class association_t { |
75 | public: | 75 | public: |
76 | 76 | ||
77 | virtual ~association_t() { } | 77 | virtual ~association_t() { } |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * retrieve the server with which association was established. | 80 | * retrieve the server with which association was established. |
81 | * @return server name | 81 | * @return server name |
82 | */ | 82 | */ |
83 | virtual string server() const = 0; | 83 | virtual string server() const = 0; |
84 | /** | 84 | /** |
85 | * retrieve the association handle. | 85 | * retrieve the association handle. |
86 | * @return handle | 86 | * @return handle |
87 | */ | 87 | */ |
88 | virtual string handle() const = 0; | 88 | virtual string handle() const = 0; |
89 | /** | 89 | /** |
90 | * retrieve the association type. | 90 | * retrieve the association type. |
91 | * @return association type | 91 | * @return association type |
92 | */ | 92 | */ |
93 | virtual string assoc_type() const = 0; | 93 | virtual string assoc_type() const = 0; |
94 | /** | 94 | /** |
95 | * retrieve the association secret. | 95 | * retrieve the association secret. |
96 | * @return association secret | 96 | * @return association secret |
97 | */ | 97 | */ |
98 | virtual secret_t secret() const = 0; | 98 | virtual secret_t secret() const = 0; |
99 | /** | 99 | /** |
100 | * retrieve the number of seconds the association expires in. | 100 | * retrieve the number of seconds the association expires in. |
101 | * @return seconds till expiration | 101 | * @return seconds till expiration |
102 | */ | 102 | */ |
103 | virtual int expires_in() const = 0; | 103 | virtual int expires_in() const = 0; |
104 | /** | 104 | /** |
105 | * check whether the association is stateless. | 105 | * check whether the association is stateless. |
106 | * @return true if stateless | 106 | * @return true if stateless |
107 | */ | 107 | */ |
108 | virtual bool stateless() const = 0; | 108 | virtual bool stateless() const = 0; |
109 | /** | 109 | /** |
110 | * check whether the association is expired. | 110 | * check whether the association is expired. |
111 | * @return true if expired | 111 | * @return true if expired |
112 | */ | 112 | */ |
113 | virtual bool is_expired() const = 0; | 113 | virtual bool is_expired() const = 0; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * the shared_ptr<> for association_t object type | 117 | * the shared_ptr<> for association_t object type |
118 | */ | 118 | */ |
119 | typedef tr1mem::shared_ptr<association_t> assoc_t; | 119 | typedef tr1mem::shared_ptr<association_t> assoc_t; |
120 | 120 | ||
121 | class basic_openid_message { | 121 | class basic_openid_message { |
122 | public: | 122 | public: |
123 | typedef list<string> fields_t; | 123 | typedef list<string> fields_t; |
124 | typedef util::forward_iterator_proxy< | 124 | typedef util::forward_iterator_proxy< |
125 | string,const string&,const string* | 125 | string,const string&,const string* |
126 | > fields_iterator; | 126 | > fields_iterator; |
127 | 127 | ||
128 | basic_openid_message() { } | 128 | basic_openid_message() { } |
129 | virtual ~basic_openid_message() { } | 129 | virtual ~basic_openid_message() { } |
130 | basic_openid_message(const basic_openid_message& x); | 130 | basic_openid_message(const basic_openid_message& x); |
131 | void copy_to(basic_openid_message& x) const; | 131 | void copy_to(basic_openid_message& x) const; |
132 | void append_to(basic_openid_message& x) const; | ||
132 | 133 | ||
133 | virtual bool has_field(const string& n) const = 0; | 134 | virtual bool has_field(const string& n) const = 0; |
134 | virtual const string& get_field(const string& n) const = 0; | 135 | virtual const string& get_field(const string& n) const = 0; |
135 | 136 | ||
136 | virtual bool has_ns(const string& uri) const; | 137 | virtual bool has_ns(const string& uri) const; |
137 | virtual string get_ns(const string& uri) const; | 138 | virtual string get_ns(const string& uri) const; |
138 | 139 | ||
139 | virtual fields_iterator fields_begin() const = 0; | 140 | virtual fields_iterator fields_begin() const = 0; |
140 | virtual fields_iterator fields_end() const = 0; | 141 | virtual fields_iterator fields_end() const = 0; |
141 | 142 | ||
142 | virtual string append_query(const string& url,const char *pfx="openid.") const; | 143 | virtual string append_query(const string& url,const char *pfx="openid.") const; |
143 | virtual string query_string(const char *pfx="openid.") const; | 144 | virtual string query_string(const char *pfx="openid.") const; |
144 | 145 | ||
145 | 146 | ||
146 | virtual void reset_fields(); | 147 | virtual void reset_fields(); |
147 | virtual void set_field(const string& n,const string& v); | 148 | virtual void set_field(const string& n,const string& v); |
148 | virtual void reset_field(const string& n); | 149 | virtual void reset_field(const string& n); |
149 | 150 | ||
150 | virtual void from_keyvalues(const string& kv); | 151 | virtual void from_keyvalues(const string& kv); |
151 | virtual void to_keyvalues(ostream& o) const; | 152 | virtual void to_keyvalues(ostream& o) const; |
152 | 153 | ||
153 | virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const; | 154 | virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const; |
154 | 155 | ||
155 | void add_to_signed(const string& fields); | 156 | void add_to_signed(const string& fields); |
156 | string find_ns(const string& uri,const char *pfx) const; | 157 | string find_ns(const string& uri,const char *pfx) const; |
157 | string allocate_ns(const string& uri,const char *pfx); | 158 | string allocate_ns(const string& uri,const char *pfx); |
158 | }; | 159 | }; |
159 | 160 | ||
160 | class openid_message_t : public basic_openid_message, public map<string,string> { | 161 | class openid_message_t : public basic_openid_message, public map<string,string> { |
161 | public: | 162 | public: |
162 | openid_message_t() { } | 163 | openid_message_t() { } |
163 | openid_message_t(const basic_openid_message& x) | 164 | openid_message_t(const basic_openid_message& x) |
164 | : basic_openid_message(x) { } | 165 | : basic_openid_message(x) { } |
165 | 166 | ||
166 | void copy_to(basic_openid_message& x) const; | 167 | void copy_to(basic_openid_message& x) const; |
167 | 168 | ||
168 | bool has_field(const string& n) const; | 169 | bool has_field(const string& n) const; |
169 | const string& get_field(const string& n) const; | 170 | const string& get_field(const string& n) const; |
170 | virtual fields_iterator fields_begin() const; | 171 | virtual fields_iterator fields_begin() const; |
171 | virtual fields_iterator fields_end() const; | 172 | virtual fields_iterator fields_end() const; |
172 | 173 | ||
173 | void reset_fields(); | 174 | void reset_fields(); |
174 | void set_field(const string& n,const string& v); | 175 | void set_field(const string& n,const string& v); |
175 | void reset_field(const string& n); | 176 | void reset_field(const string& n); |
176 | }; | 177 | }; |
177 | 178 | ||
178 | /** | 179 | /** |
179 | * request/response parameters map | 180 | * request/response parameters map |
180 | */ | 181 | */ |
181 | class params_t : public openid_message_t { | 182 | class params_t : public openid_message_t { |
182 | public: | 183 | public: |
183 | 184 | ||
184 | /** | 185 | /** |
185 | * check whether the parameter is present. | 186 | * check whether the parameter is present. |
186 | * @param n the parameter name | 187 | * @param n the parameter name |
187 | * @return true if yes | 188 | * @return true if yes |
188 | */ | 189 | */ |
189 | bool has_param(const string& n) const { | 190 | bool has_param(const string& n) const { |
190 | return has_field(n); } | 191 | return has_field(n); } |
191 | /** | 192 | /** |
192 | * retrieve the parameter (const version) | 193 | * retrieve the parameter (const version) |
193 | * @param n the parameter name | 194 | * @param n the parameter name |
194 | * @return the parameter value | 195 | * @return the parameter value |
195 | * @throw failed_lookup if there is no such parameter | 196 | * @throw failed_lookup if there is no such parameter |
196 | */ | 197 | */ |
197 | const string& get_param(const string& n) const { | 198 | const string& get_param(const string& n) const { |
198 | return get_field(n); } | 199 | return get_field(n); } |
199 | 200 | ||
200 | /** | 201 | /** |
201 | * parse the OpenID key/value data. | 202 | * parse the OpenID key/value data. |
202 | * @param kv the OpenID key/value data | 203 | * @param kv the OpenID key/value data |
203 | */ | 204 | */ |
204 | void parse_keyvalues(const string& kv) { | 205 | void parse_keyvalues(const string& kv) { |
205 | from_keyvalues(kv); } | 206 | from_keyvalues(kv); } |
206 | 207 | ||
207 | string append_query(const string& url,const char *prefix="openid.") const; | 208 | string append_query(const string& url,const char *prefix="openid.") const; |
208 | 209 | ||
209 | }; | 210 | }; |
210 | 211 | ||
211 | struct openid_endpoint_t { | 212 | struct openid_endpoint_t { |
212 | string uri; | 213 | string uri; |
213 | string claimed_id; | 214 | string claimed_id; |
214 | string local_id; | 215 | string local_id; |
215 | 216 | ||
216 | openid_endpoint_t() { } | 217 | openid_endpoint_t() { } |
217 | openid_endpoint_t(const string& u,const string& cid,const string& lid) | 218 | openid_endpoint_t(const string& u,const string& cid,const string& lid) |
218 | : uri(u), claimed_id(cid), local_id(lid) { } | 219 | : uri(u), claimed_id(cid), local_id(lid) { } |
219 | 220 | ||
220 | bool operator==(const openid_endpoint_t& x) const { | 221 | bool operator==(const openid_endpoint_t& x) const { |
221 | return uri==x.uri && local_id==x.local_id; } | 222 | return uri==x.uri && local_id==x.local_id; } |
222 | bool operator<(const openid_endpoint_t& x) const { | 223 | bool operator<(const openid_endpoint_t& x) const { |
223 | int c; | 224 | int c; |
224 | return (c=strcmp(uri.c_str(),x.uri.c_str())) | 225 | return (c=strcmp(uri.c_str(),x.uri.c_str())) |
225 | ? (c<0) : (strcmp(local_id.c_str(),x.local_id.c_str())<0); } | 226 | ? (c<0) : (strcmp(local_id.c_str(),x.local_id.c_str())<0); } |
226 | }; | 227 | }; |
227 | 228 | ||