diff options
author | Andreas Ebner <pansy007@googlemail.com> | 2019-07-24 16:29:32 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-10-07 12:15:32 +0200 |
commit | 40624873cbd2eaf3a94185995b14899ea6ab36bf (patch) | |
tree | 0bcc45fc8ba74c7b218ed2b32fc8b7482a42a37c /src/credential/credential_serialization.c | |
parent | 5091edcec16455febee99afec20e0ffe6cc59c21 (diff) | |
download | gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.tar.gz gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.zip |
Run clang format over some files, experimental implementation of forward algorithm
Diffstat (limited to 'src/credential/credential_serialization.c')
-rw-r--r-- | src/credential/credential_serialization.c | 310 |
1 files changed, 152 insertions, 158 deletions
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c index 4e461c654..b14ec26f2 100644 --- a/src/credential/credential_serialization.c +++ b/src/credential/credential_serialization.c | |||
@@ -11,17 +11,17 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
23 | * @file credential/credential_serialization.c | 23 | * @file credential/credential_serialization.c |
24 | * @brief API to serialize and deserialize delegation chains | 24 | * @brief API to serialize and deserialize delegation chains |
25 | * and credentials | 25 | * and credentials |
26 | * @author Martin Schanzenbach | 26 | * @author Martin Schanzenbach |
27 | */ | 27 | */ |
@@ -41,14 +41,14 @@ | |||
41 | * @return the required size to serialize | 41 | * @return the required size to serialize |
42 | */ | 42 | */ |
43 | size_t | 43 | size_t |
44 | GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, | 44 | GNUNET_CREDENTIAL_delegation_set_get_size ( |
45 | const struct | 45 | unsigned int ds_count, |
46 | GNUNET_CREDENTIAL_DelegationSet *dsr) | 46 | const struct GNUNET_CREDENTIAL_DelegationSet *dsr) |
47 | { | 47 | { |
48 | unsigned int i; | 48 | unsigned int i; |
49 | size_t ret; | 49 | size_t ret; |
50 | 50 | ||
51 | ret = sizeof(struct DelegationRecordData) * (ds_count); | 51 | ret = sizeof (struct DelegationRecordData) * (ds_count); |
52 | 52 | ||
53 | for (i = 0; i < ds_count; i++) | 53 | for (i = 0; i < ds_count; i++) |
54 | { | 54 | { |
@@ -68,11 +68,11 @@ GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, | |||
68 | * @return the size of the data, -1 on failure | 68 | * @return the size of the data, -1 on failure |
69 | */ | 69 | */ |
70 | ssize_t | 70 | ssize_t |
71 | GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, | 71 | GNUNET_CREDENTIAL_delegation_set_serialize ( |
72 | const struct | 72 | unsigned int d_count, |
73 | GNUNET_CREDENTIAL_DelegationSet *dsr, | 73 | const struct GNUNET_CREDENTIAL_DelegationSet *dsr, |
74 | size_t dest_size, | 74 | size_t dest_size, |
75 | char *dest) | 75 | char *dest) |
76 | { | 76 | { |
77 | struct DelegationRecordData rec; | 77 | struct DelegationRecordData rec; |
78 | unsigned int i; | 78 | unsigned int i; |
@@ -83,12 +83,10 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, | |||
83 | { | 83 | { |
84 | rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len); | 84 | rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len); |
85 | rec.subject_key = dsr[i].subject_key; | 85 | rec.subject_key = dsr[i].subject_key; |
86 | if (off + sizeof(rec) > dest_size) | 86 | if (off + sizeof (rec) > dest_size) |
87 | return -1; | 87 | return -1; |
88 | GNUNET_memcpy (&dest[off], | 88 | GNUNET_memcpy (&dest[off], &rec, sizeof (rec)); |
89 | &rec, | 89 | off += sizeof (rec); |
90 | sizeof(rec)); | ||
91 | off += sizeof(rec); | ||
92 | if (0 == dsr[i].subject_attribute_len) | 90 | if (0 == dsr[i].subject_attribute_len) |
93 | continue; | 91 | continue; |
94 | if (off + dsr[i].subject_attribute_len > dest_size) | 92 | if (off + dsr[i].subject_attribute_len > dest_size) |
@@ -112,12 +110,11 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, | |||
112 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 110 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
113 | */ | 111 | */ |
114 | int | 112 | int |
115 | GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, | 113 | GNUNET_CREDENTIAL_delegation_set_deserialize ( |
116 | const char *src, | 114 | size_t len, |
117 | unsigned int d_count, | 115 | const char *src, |
118 | struct | 116 | unsigned int d_count, |
119 | GNUNET_CREDENTIAL_DelegationSet * | 117 | struct GNUNET_CREDENTIAL_DelegationSet *dsr) |
120 | dsr) | ||
121 | { | 118 | { |
122 | struct DelegationRecordData rec; | 119 | struct DelegationRecordData rec; |
123 | unsigned int i; | 120 | unsigned int i; |
@@ -126,15 +123,15 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, | |||
126 | off = 0; | 123 | off = 0; |
127 | for (i = 0; i < d_count; i++) | 124 | for (i = 0; i < d_count; i++) |
128 | { | 125 | { |
129 | if (off + sizeof(rec) > len) | 126 | if (off + sizeof (rec) > len) |
130 | return GNUNET_SYSERR; | 127 | return GNUNET_SYSERR; |
131 | GNUNET_memcpy (&rec, &src[off], sizeof(rec)); | 128 | GNUNET_memcpy (&rec, &src[off], sizeof (rec)); |
132 | dsr[i].subject_key = rec.subject_key; | 129 | dsr[i].subject_key = rec.subject_key; |
133 | off += sizeof(rec); | 130 | off += sizeof (rec); |
134 | dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); | 131 | dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); |
135 | if (off + dsr[i].subject_attribute_len > len) | 132 | if (off + dsr[i].subject_attribute_len > len) |
136 | return GNUNET_SYSERR; | 133 | return GNUNET_SYSERR; |
137 | dsr[i].subject_attribute = (char*) &src[off]; | 134 | dsr[i].subject_attribute = (char *) &src[off]; |
138 | off += dsr[i].subject_attribute_len; | 135 | off += dsr[i].subject_attribute_len; |
139 | } | 136 | } |
140 | return GNUNET_OK; | 137 | return GNUNET_OK; |
@@ -150,14 +147,14 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, | |||
150 | * @return the required size to serialize | 147 | * @return the required size to serialize |
151 | */ | 148 | */ |
152 | size_t | 149 | size_t |
153 | GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, | 150 | GNUNET_CREDENTIAL_credentials_get_size ( |
154 | const struct | 151 | unsigned int c_count, |
155 | GNUNET_CREDENTIAL_Credential *cd) | 152 | const struct GNUNET_CREDENTIAL_Credential *cd) |
156 | { | 153 | { |
157 | unsigned int i; | 154 | unsigned int i; |
158 | size_t ret; | 155 | size_t ret; |
159 | 156 | ||
160 | ret = sizeof(struct CredentialEntry) * (c_count); | 157 | ret = sizeof (struct CredentialEntry) * (c_count); |
161 | 158 | ||
162 | for (i = 0; i < c_count; i++) | 159 | for (i = 0; i < c_count; i++) |
163 | { | 160 | { |
@@ -176,11 +173,11 @@ GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, | |||
176 | * @return the size of the data, -1 on failure | 173 | * @return the size of the data, -1 on failure |
177 | */ | 174 | */ |
178 | ssize_t | 175 | ssize_t |
179 | GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | 176 | GNUNET_CREDENTIAL_credentials_serialize ( |
180 | const struct | 177 | unsigned int c_count, |
181 | GNUNET_CREDENTIAL_Credential *cd, | 178 | const struct GNUNET_CREDENTIAL_Credential *cd, |
182 | size_t dest_size, | 179 | size_t dest_size, |
183 | char *dest) | 180 | char *dest) |
184 | { | 181 | { |
185 | struct CredentialEntry c_rec; | 182 | struct CredentialEntry c_rec; |
186 | unsigned int i; | 183 | unsigned int i; |
@@ -194,16 +191,14 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | |||
194 | c_rec.subject_key = cd[i].subject_key; | 191 | c_rec.subject_key = cd[i].subject_key; |
195 | c_rec.signature = cd[i].signature; | 192 | c_rec.signature = cd[i].signature; |
196 | c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 193 | c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
197 | c_rec.purpose.size = htonl ((sizeof(struct CredentialEntry) | 194 | c_rec.purpose.size = |
198 | + cd[i].issuer_attribute_len) - sizeof(struct | 195 | htonl ((sizeof (struct CredentialEntry) + cd[i].issuer_attribute_len) - |
199 | GNUNET_CRYPTO_EcdsaSignature)); | 196 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); |
200 | c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); | 197 | c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); |
201 | if (off + sizeof(c_rec) > dest_size) | 198 | if (off + sizeof (c_rec) > dest_size) |
202 | return -1; | 199 | return -1; |
203 | GNUNET_memcpy (&dest[off], | 200 | GNUNET_memcpy (&dest[off], &c_rec, sizeof (c_rec)); |
204 | &c_rec, | 201 | off += sizeof (c_rec); |
205 | sizeof(c_rec)); | ||
206 | off += sizeof(c_rec); | ||
207 | if (off + cd[i].issuer_attribute_len > dest_size) | 202 | if (off + cd[i].issuer_attribute_len > dest_size) |
208 | return -1; | 203 | return -1; |
209 | GNUNET_memcpy (&dest[off], | 204 | GNUNET_memcpy (&dest[off], |
@@ -216,7 +211,6 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | |||
216 | } | 211 | } |
217 | 212 | ||
218 | 213 | ||
219 | |||
220 | /** | 214 | /** |
221 | * Deserialize the given destination | 215 | * Deserialize the given destination |
222 | * | 216 | * |
@@ -227,11 +221,11 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | |||
227 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 221 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
228 | */ | 222 | */ |
229 | int | 223 | int |
230 | GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | 224 | GNUNET_CREDENTIAL_credentials_deserialize ( |
231 | const char *src, | 225 | size_t len, |
232 | unsigned int c_count, | 226 | const char *src, |
233 | struct GNUNET_CREDENTIAL_Credential * | 227 | unsigned int c_count, |
234 | cd) | 228 | struct GNUNET_CREDENTIAL_Credential *cd) |
235 | { | 229 | { |
236 | struct CredentialEntry c_rec; | 230 | struct CredentialEntry c_rec; |
237 | unsigned int i; | 231 | unsigned int i; |
@@ -240,15 +234,15 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | |||
240 | off = 0; | 234 | off = 0; |
241 | for (i = 0; i < c_count; i++) | 235 | for (i = 0; i < c_count; i++) |
242 | { | 236 | { |
243 | if (off + sizeof(c_rec) > len) | 237 | if (off + sizeof (c_rec) > len) |
244 | return GNUNET_SYSERR; | 238 | return GNUNET_SYSERR; |
245 | GNUNET_memcpy (&c_rec, &src[off], sizeof(c_rec)); | 239 | GNUNET_memcpy (&c_rec, &src[off], sizeof (c_rec)); |
246 | cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len); | 240 | cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len); |
247 | cd[i].issuer_key = c_rec.issuer_key; | 241 | cd[i].issuer_key = c_rec.issuer_key; |
248 | cd[i].subject_key = c_rec.subject_key; | 242 | cd[i].subject_key = c_rec.subject_key; |
249 | cd[i].signature = c_rec.signature; | 243 | cd[i].signature = c_rec.signature; |
250 | cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration); | 244 | cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration); |
251 | off += sizeof(c_rec); | 245 | off += sizeof (c_rec); |
252 | if (off + cd[i].issuer_attribute_len > len) | 246 | if (off + cd[i].issuer_attribute_len > len) |
253 | return GNUNET_SYSERR; | 247 | return GNUNET_SYSERR; |
254 | cd[i].issuer_attribute = &src[off]; | 248 | cd[i].issuer_attribute = &src[off]; |
@@ -258,7 +252,6 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | |||
258 | } | 252 | } |
259 | 253 | ||
260 | 254 | ||
261 | |||
262 | /** | 255 | /** |
263 | * Calculate how many bytes we will need to serialize | 256 | * Calculate how many bytes we will need to serialize |
264 | * the given delegation chain and credential | 257 | * the given delegation chain and credential |
@@ -270,23 +263,21 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | |||
270 | * @return the required size to serialize | 263 | * @return the required size to serialize |
271 | */ | 264 | */ |
272 | size_t | 265 | size_t |
273 | GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, | 266 | GNUNET_CREDENTIAL_delegation_chain_get_size ( |
274 | const struct | 267 | unsigned int d_count, |
275 | GNUNET_CREDENTIAL_Delegation *dd, | 268 | const struct GNUNET_CREDENTIAL_Delegation *dd, |
276 | unsigned int c_count, | 269 | unsigned int c_count, |
277 | const struct | 270 | const struct GNUNET_CREDENTIAL_Credential *cd) |
278 | GNUNET_CREDENTIAL_Credential *cd) | ||
279 | { | 271 | { |
280 | unsigned int i; | 272 | unsigned int i; |
281 | size_t ret; | 273 | size_t ret; |
282 | 274 | ||
283 | ret = sizeof(struct ChainEntry) * (d_count); | 275 | ret = sizeof (struct ChainEntry) * (d_count); |
284 | 276 | ||
285 | for (i = 0; i < d_count; i++) | 277 | for (i = 0; i < d_count; i++) |
286 | { | 278 | { |
287 | GNUNET_assert ((ret | 279 | GNUNET_assert ( |
288 | + dd[i].issuer_attribute_len | 280 | (ret + dd[i].issuer_attribute_len + dd[i].subject_attribute_len) >= ret); |
289 | + dd[i].subject_attribute_len) >= ret); | ||
290 | ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; | 281 | ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; |
291 | } | 282 | } |
292 | return ret + GNUNET_CREDENTIAL_credentials_get_size (c_count, cd); | 283 | return ret + GNUNET_CREDENTIAL_credentials_get_size (c_count, cd); |
@@ -304,14 +295,13 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, | |||
304 | * @return the size of the data, -1 on failure | 295 | * @return the size of the data, -1 on failure |
305 | */ | 296 | */ |
306 | ssize_t | 297 | ssize_t |
307 | GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, | 298 | GNUNET_CREDENTIAL_delegation_chain_serialize ( |
308 | const struct | 299 | unsigned int d_count, |
309 | GNUNET_CREDENTIAL_Delegation *dd, | 300 | const struct GNUNET_CREDENTIAL_Delegation *dd, |
310 | unsigned int c_count, | 301 | unsigned int c_count, |
311 | const struct | 302 | const struct GNUNET_CREDENTIAL_Credential *cd, |
312 | GNUNET_CREDENTIAL_Credential *cd, | 303 | size_t dest_size, |
313 | size_t dest_size, | 304 | char *dest) |
314 | char *dest) | ||
315 | { | 305 | { |
316 | struct ChainEntry rec; | 306 | struct ChainEntry rec; |
317 | unsigned int i; | 307 | unsigned int i; |
@@ -324,12 +314,10 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, | |||
324 | rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len); | 314 | rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len); |
325 | rec.issuer_key = dd[i].issuer_key; | 315 | rec.issuer_key = dd[i].issuer_key; |
326 | rec.subject_key = dd[i].subject_key; | 316 | rec.subject_key = dd[i].subject_key; |
327 | if (off + sizeof(rec) > dest_size) | 317 | if (off + sizeof (rec) > dest_size) |
328 | return -1; | 318 | return -1; |
329 | GNUNET_memcpy (&dest[off], | 319 | GNUNET_memcpy (&dest[off], &rec, sizeof (rec)); |
330 | &rec, | 320 | off += sizeof (rec); |
331 | sizeof(rec)); | ||
332 | off += sizeof(rec); | ||
333 | if (off + dd[i].issuer_attribute_len > dest_size) | 321 | if (off + dd[i].issuer_attribute_len > dest_size) |
334 | return -1; | 322 | return -1; |
335 | GNUNET_memcpy (&dest[off], | 323 | GNUNET_memcpy (&dest[off], |
@@ -364,14 +352,13 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, | |||
364 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 352 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
365 | */ | 353 | */ |
366 | int | 354 | int |
367 | GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, | 355 | GNUNET_CREDENTIAL_delegation_chain_deserialize ( |
368 | const char *src, | 356 | size_t len, |
369 | unsigned int d_count, | 357 | const char *src, |
370 | struct | 358 | unsigned int d_count, |
371 | GNUNET_CREDENTIAL_Delegation *dd, | 359 | struct GNUNET_CREDENTIAL_Delegation *dd, |
372 | unsigned int c_count, | 360 | unsigned int c_count, |
373 | struct | 361 | struct GNUNET_CREDENTIAL_Credential *cd) |
374 | GNUNET_CREDENTIAL_Credential *cd) | ||
375 | { | 362 | { |
376 | struct ChainEntry rec; | 363 | struct ChainEntry rec; |
377 | unsigned int i; | 364 | unsigned int i; |
@@ -380,13 +367,13 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, | |||
380 | off = 0; | 367 | off = 0; |
381 | for (i = 0; i < d_count; i++) | 368 | for (i = 0; i < d_count; i++) |
382 | { | 369 | { |
383 | if (off + sizeof(rec) > len) | 370 | if (off + sizeof (rec) > len) |
384 | return GNUNET_SYSERR; | 371 | return GNUNET_SYSERR; |
385 | GNUNET_memcpy (&rec, &src[off], sizeof(rec)); | 372 | GNUNET_memcpy (&rec, &src[off], sizeof (rec)); |
386 | dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); | 373 | dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); |
387 | dd[i].issuer_key = rec.issuer_key; | 374 | dd[i].issuer_key = rec.issuer_key; |
388 | dd[i].subject_key = rec.subject_key; | 375 | dd[i].subject_key = rec.subject_key; |
389 | off += sizeof(rec); | 376 | off += sizeof (rec); |
390 | if (off + dd[i].issuer_attribute_len > len) | 377 | if (off + dd[i].issuer_attribute_len > len) |
391 | return GNUNET_SYSERR; | 378 | return GNUNET_SYSERR; |
392 | dd[i].issuer_attribute = &src[off]; | 379 | dd[i].issuer_attribute = &src[off]; |
@@ -404,66 +391,63 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, | |||
404 | } | 391 | } |
405 | 392 | ||
406 | int | 393 | int |
407 | GNUNET_CREDENTIAL_credential_serialize (struct | 394 | GNUNET_CREDENTIAL_credential_serialize ( |
408 | GNUNET_CREDENTIAL_Credential *cred, | 395 | struct GNUNET_CREDENTIAL_Credential *cred, |
409 | char **data) | 396 | char **data) |
410 | { | 397 | { |
411 | size_t size; | 398 | size_t size; |
412 | struct CredentialEntry *cdata; | 399 | struct CredentialEntry *cdata; |
413 | 400 | ||
414 | size = sizeof(struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; | 401 | size = sizeof (struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; |
415 | *data = GNUNET_malloc (size); | 402 | *data = GNUNET_malloc (size); |
416 | cdata = (struct CredentialEntry*) *data; | 403 | cdata = (struct CredentialEntry *) *data; |
417 | cdata->subject_key = cred->subject_key; | 404 | cdata->subject_key = cred->subject_key; |
418 | cdata->issuer_key = cred->issuer_key; | 405 | cdata->issuer_key = cred->issuer_key; |
419 | cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); | 406 | cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); |
420 | cdata->signature = cred->signature; | 407 | cdata->signature = cred->signature; |
421 | cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); | 408 | cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); |
422 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 409 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
423 | cdata->purpose.size = htonl (size - sizeof(struct | 410 | cdata->purpose.size = |
424 | GNUNET_CRYPTO_EcdsaSignature)); | 411 | htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); |
425 | GNUNET_memcpy (&cdata[1], | 412 | GNUNET_memcpy (&cdata[1], |
426 | cred->issuer_attribute, | 413 | cred->issuer_attribute, |
427 | strlen (cred->issuer_attribute)); | 414 | strlen (cred->issuer_attribute)); |
428 | 415 | ||
429 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( | 416 | if (GNUNET_OK != |
430 | GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | 417 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, |
431 | &cdata->purpose, | 418 | &cdata->purpose, |
432 | &cdata->signature, | 419 | &cdata->signature, |
433 | &cdata->issuer_key)) | 420 | &cdata->issuer_key)) |
434 | { | 421 | { |
435 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 422 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); |
436 | "Invalid credential\n"); | 423 | //return NULL; |
437 | // return NULL; | ||
438 | } | 424 | } |
439 | return size; | 425 | return size; |
440 | } | 426 | } |
441 | 427 | ||
442 | struct GNUNET_CREDENTIAL_Credential* | 428 | struct GNUNET_CREDENTIAL_Credential * |
443 | GNUNET_CREDENTIAL_credential_deserialize (const char*data, | 429 | GNUNET_CREDENTIAL_credential_deserialize (const char *data, size_t data_size) |
444 | size_t data_size) | ||
445 | { | 430 | { |
446 | struct GNUNET_CREDENTIAL_Credential *cred; | 431 | struct GNUNET_CREDENTIAL_Credential *cred; |
447 | struct CredentialEntry *cdata; | 432 | struct CredentialEntry *cdata; |
448 | char *issuer_attribute; | 433 | char *issuer_attribute; |
449 | 434 | ||
450 | if (data_size < sizeof(struct CredentialEntry)) | 435 | if (data_size < sizeof (struct CredentialEntry)) |
451 | return NULL; | 436 | return NULL; |
452 | cdata = (struct CredentialEntry*) data; | 437 | cdata = (struct CredentialEntry *) data; |
453 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( | 438 | if (GNUNET_OK != |
454 | GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | 439 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, |
455 | &cdata->purpose, | 440 | &cdata->purpose, |
456 | &cdata->signature, | 441 | &cdata->signature, |
457 | &cdata->issuer_key)) | 442 | &cdata->issuer_key)) |
458 | { | 443 | { |
459 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 444 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); |
460 | "Invalid credential\n"); | 445 | //return NULL; |
461 | // return NULL; | ||
462 | } | 446 | } |
463 | issuer_attribute = (char*) &cdata[1]; | 447 | issuer_attribute = (char *) &cdata[1]; |
464 | 448 | ||
465 | cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl ( | 449 | cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + |
466 | cdata->issuer_attribute_len)); | 450 | ntohl (cdata->issuer_attribute_len)); |
467 | 451 | ||
468 | cred->issuer_key = cdata->issuer_key; | 452 | cred->issuer_key = cdata->issuer_key; |
469 | cred->subject_key = cdata->subject_key; | 453 | cred->subject_key = cdata->subject_key; |
@@ -471,7 +455,7 @@ GNUNET_CREDENTIAL_credential_deserialize (const char*data, | |||
471 | issuer_attribute, | 455 | issuer_attribute, |
472 | ntohl (cdata->issuer_attribute_len)); | 456 | ntohl (cdata->issuer_attribute_len)); |
473 | cred->signature = cdata->signature; | 457 | cred->signature = cdata->signature; |
474 | cred->issuer_attribute = (char*) &cred[1]; | 458 | cred->issuer_attribute = (char *) &cred[1]; |
475 | cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); | 459 | cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); |
476 | return cred; | 460 | return cred; |
477 | } | 461 | } |
@@ -480,51 +464,60 @@ GNUNET_CREDENTIAL_credential_deserialize (const char*data, | |||
480 | 464 | ||
481 | int | 465 | int |
482 | GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, | 466 | GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, |
483 | char **data) | 467 | char **data) |
484 | { | 468 | { |
485 | size_t size; | 469 | size_t size; |
486 | struct DelegateEntry *cdata; | 470 | struct DelegateEntry *cdata; |
487 | int attr_len; | 471 | int attr_len; |
488 | 472 | ||
489 | // +1 for \0 | 473 | // +1 for \0 |
490 | if (0 == dele->subject_attribute_len){ | 474 | if (0 == dele->subject_attribute_len) |
475 | { | ||
491 | attr_len = dele->issuer_attribute_len + 1; | 476 | attr_len = dele->issuer_attribute_len + 1; |
492 | } else { | 477 | } |
478 | else | ||
479 | { | ||
493 | attr_len = dele->issuer_attribute_len + dele->subject_attribute_len + 2; | 480 | attr_len = dele->issuer_attribute_len + dele->subject_attribute_len + 2; |
494 | } | 481 | } |
495 | size = sizeof (struct DelegateEntry) + attr_len; | 482 | size = sizeof (struct DelegateEntry) + attr_len; |
496 | 483 | ||
497 | char tmp_str[attr_len]; | 484 | char tmp_str[attr_len]; |
498 | GNUNET_memcpy(tmp_str, dele->issuer_attribute, dele->issuer_attribute_len); | 485 | GNUNET_memcpy (tmp_str, dele->issuer_attribute, dele->issuer_attribute_len); |
499 | if (0 != dele->subject_attribute_len){ | 486 | if (0 != dele->subject_attribute_len) |
487 | { | ||
500 | tmp_str[dele->issuer_attribute_len] = '\0'; | 488 | tmp_str[dele->issuer_attribute_len] = '\0'; |
501 | GNUNET_memcpy(tmp_str + dele->issuer_attribute_len + 1, dele->subject_attribute, dele->subject_attribute_len); | 489 | GNUNET_memcpy (tmp_str + dele->issuer_attribute_len + 1, |
490 | dele->subject_attribute, | ||
491 | dele->subject_attribute_len); | ||
502 | } | 492 | } |
503 | tmp_str[attr_len - 1] = '\0'; | 493 | tmp_str[attr_len - 1] = '\0'; |
504 | 494 | ||
505 | *data = GNUNET_malloc (size); | 495 | *data = GNUNET_malloc (size); |
506 | cdata = (struct DelegateEntry*)*data; | 496 | cdata = (struct DelegateEntry *) *data; |
507 | cdata->subject_key = dele->subject_key; | 497 | cdata->subject_key = dele->subject_key; |
508 | cdata->issuer_key = dele->issuer_key; | 498 | cdata->issuer_key = dele->issuer_key; |
509 | cdata->expiration = GNUNET_htonll (dele->expiration.abs_value_us); | 499 | cdata->expiration = GNUNET_htonll (dele->expiration.abs_value_us); |
510 | cdata->signature = dele->signature; | 500 | cdata->signature = dele->signature; |
511 | cdata->issuer_attribute_len = htonl (dele->issuer_attribute_len + 1); | 501 | cdata->issuer_attribute_len = htonl (dele->issuer_attribute_len + 1); |
512 | if (0 == dele->subject_attribute_len){ | 502 | if (0 == dele->subject_attribute_len) |
503 | { | ||
513 | cdata->subject_attribute_len = htonl (0); | 504 | cdata->subject_attribute_len = htonl (0); |
514 | } else { | 505 | } |
506 | else | ||
507 | { | ||
515 | cdata->subject_attribute_len = htonl (dele->subject_attribute_len + 1); | 508 | cdata->subject_attribute_len = htonl (dele->subject_attribute_len + 1); |
516 | } | 509 | } |
517 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); | 510 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); |
518 | cdata->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 511 | cdata->purpose.size = |
512 | htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | ||
519 | 513 | ||
520 | GNUNET_memcpy (&cdata[1], | 514 | GNUNET_memcpy (&cdata[1], tmp_str, attr_len); |
521 | tmp_str, | ||
522 | attr_len); | ||
523 | 515 | ||
524 | if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_DELEGATE, | 516 | if (GNUNET_OK != |
525 | &cdata->purpose, | 517 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_DELEGATE, |
526 | &cdata->signature, | 518 | &cdata->purpose, |
527 | &cdata->issuer_key)) | 519 | &cdata->signature, |
520 | &cdata->issuer_key)) | ||
528 | { | 521 | { |
529 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Serialize: Invalid delegate\n"); | 522 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Serialize: Invalid delegate\n"); |
530 | return 0; | 523 | return 0; |
@@ -532,9 +525,8 @@ GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, | |||
532 | return size; | 525 | return size; |
533 | } | 526 | } |
534 | 527 | ||
535 | struct GNUNET_CREDENTIAL_Delegate* | 528 | struct GNUNET_CREDENTIAL_Delegate * |
536 | GNUNET_CREDENTIAL_delegate_deserialize (const char* data, | 529 | GNUNET_CREDENTIAL_delegate_deserialize (const char *data, size_t data_size) |
537 | size_t data_size) | ||
538 | { | 530 | { |
539 | struct GNUNET_CREDENTIAL_Delegate *dele; | 531 | struct GNUNET_CREDENTIAL_Delegate *dele; |
540 | struct DelegateEntry *cdata; | 532 | struct DelegateEntry *cdata; |
@@ -542,38 +534,40 @@ GNUNET_CREDENTIAL_delegate_deserialize (const char* data, | |||
542 | 534 | ||
543 | if (data_size < sizeof (struct DelegateEntry)) | 535 | if (data_size < sizeof (struct DelegateEntry)) |
544 | return NULL; | 536 | return NULL; |
545 | cdata = (struct DelegateEntry*)data; | 537 | cdata = (struct DelegateEntry *) data; |
546 | if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_DELEGATE, | 538 | if (GNUNET_OK != |
547 | &cdata->purpose, | 539 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_DELEGATE, |
548 | &cdata->signature, | 540 | &cdata->purpose, |
549 | &cdata->issuer_key)) | 541 | &cdata->signature, |
542 | &cdata->issuer_key)) | ||
550 | { | 543 | { |
551 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deserialize: Invalid delegate\n"); | 544 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deserialize: Invalid delegate\n"); |
552 | return NULL; | 545 | return NULL; |
553 | } | 546 | } |
554 | attr_combo_str = (char*)&cdata[1]; | 547 | attr_combo_str = (char *) &cdata[1]; |
555 | int iss_len = ntohl(cdata->issuer_attribute_len); | 548 | int iss_len = ntohl (cdata->issuer_attribute_len); |
556 | int sub_len = ntohl(cdata->subject_attribute_len); | 549 | int sub_len = ntohl (cdata->subject_attribute_len); |
557 | int attr_combo_len = iss_len + sub_len; | 550 | int attr_combo_len = iss_len + sub_len; |
558 | 551 | ||
559 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_combo_len); | 552 | dele = |
553 | GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_combo_len); | ||
560 | 554 | ||
561 | dele->issuer_key = cdata->issuer_key; | 555 | dele->issuer_key = cdata->issuer_key; |
562 | dele->subject_key = cdata->subject_key; | 556 | dele->subject_key = cdata->subject_key; |
563 | GNUNET_memcpy (&dele[1], | 557 | GNUNET_memcpy (&dele[1], attr_combo_str, attr_combo_len); |
564 | attr_combo_str, | ||
565 | attr_combo_len); | ||
566 | dele->signature = cdata->signature; | 558 | dele->signature = cdata->signature; |
567 | 559 | ||
568 | // Set the pointers for the attributes | 560 | // Set the pointers for the attributes |
569 | dele->issuer_attribute = (char*)&dele[1]; | 561 | dele->issuer_attribute = (char *) &dele[1]; |
570 | dele->issuer_attribute_len = iss_len; | 562 | dele->issuer_attribute_len = iss_len; |
571 | dele->subject_attribute_len = sub_len; | 563 | dele->subject_attribute_len = sub_len; |
572 | if(0 == sub_len){ | 564 | if (0 == sub_len) |
565 | { | ||
573 | dele->subject_attribute = NULL; | 566 | dele->subject_attribute = NULL; |
574 | } else { | 567 | } |
575 | dele->subject_attribute = (char*)&dele[1] + iss_len; | 568 | else |
576 | 569 | { | |
570 | dele->subject_attribute = (char *) &dele[1] + iss_len; | ||
577 | } | 571 | } |
578 | 572 | ||
579 | dele->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); | 573 | dele->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); |