diff options
Diffstat (limited to 'src/credential/credential_serialization.c')
-rw-r--r-- | src/credential/credential_serialization.c | 442 |
1 files changed, 231 insertions, 211 deletions
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c index eac310272..40fa112dd 100644 --- a/src/credential/credential_serialization.c +++ b/src/credential/credential_serialization.c | |||
@@ -41,8 +41,9 @@ | |||
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 (unsigned int ds_count, |
45 | const struct GNUNET_CREDENTIAL_DelegationSet *dsr) | 45 | const struct |
46 | GNUNET_CREDENTIAL_DelegationSet *dsr) | ||
46 | { | 47 | { |
47 | unsigned int i; | 48 | unsigned int i; |
48 | size_t ret; | 49 | size_t ret; |
@@ -50,10 +51,10 @@ GNUNET_CREDENTIAL_delegation_set_get_size(unsigned int ds_count, | |||
50 | ret = sizeof(struct DelegationRecordData) * (ds_count); | 51 | ret = sizeof(struct DelegationRecordData) * (ds_count); |
51 | 52 | ||
52 | for (i = 0; i < ds_count; i++) | 53 | for (i = 0; i < ds_count; i++) |
53 | { | 54 | { |
54 | GNUNET_assert((ret + dsr[i].subject_attribute_len) >= ret); | 55 | GNUNET_assert ((ret + dsr[i].subject_attribute_len) >= ret); |
55 | ret += dsr[i].subject_attribute_len; | 56 | ret += dsr[i].subject_attribute_len; |
56 | } | 57 | } |
57 | return ret; | 58 | return ret; |
58 | } | 59 | } |
59 | 60 | ||
@@ -67,10 +68,11 @@ GNUNET_CREDENTIAL_delegation_set_get_size(unsigned int ds_count, | |||
67 | * @return the size of the data, -1 on failure | 68 | * @return the size of the data, -1 on failure |
68 | */ | 69 | */ |
69 | ssize_t | 70 | ssize_t |
70 | GNUNET_CREDENTIAL_delegation_set_serialize(unsigned int d_count, | 71 | GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, |
71 | const struct GNUNET_CREDENTIAL_DelegationSet *dsr, | 72 | const struct |
72 | size_t dest_size, | 73 | GNUNET_CREDENTIAL_DelegationSet *dsr, |
73 | char *dest) | 74 | size_t dest_size, |
75 | char *dest) | ||
74 | { | 76 | { |
75 | struct DelegationRecordData rec; | 77 | struct DelegationRecordData rec; |
76 | unsigned int i; | 78 | unsigned int i; |
@@ -78,24 +80,24 @@ GNUNET_CREDENTIAL_delegation_set_serialize(unsigned int d_count, | |||
78 | 80 | ||
79 | off = 0; | 81 | off = 0; |
80 | for (i = 0; i < d_count; i++) | 82 | for (i = 0; i < d_count; i++) |
81 | { | 83 | { |
82 | 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); |
83 | rec.subject_key = dsr[i].subject_key; | 85 | rec.subject_key = dsr[i].subject_key; |
84 | if (off + sizeof(rec) > dest_size) | 86 | if (off + sizeof(rec) > dest_size) |
85 | return -1; | 87 | return -1; |
86 | GNUNET_memcpy(&dest[off], | 88 | GNUNET_memcpy (&dest[off], |
87 | &rec, | 89 | &rec, |
88 | sizeof(rec)); | 90 | sizeof(rec)); |
89 | off += sizeof(rec); | 91 | off += sizeof(rec); |
90 | if (0 == dsr[i].subject_attribute_len) | 92 | if (0 == dsr[i].subject_attribute_len) |
91 | continue; | 93 | continue; |
92 | if (off + dsr[i].subject_attribute_len > dest_size) | 94 | if (off + dsr[i].subject_attribute_len > dest_size) |
93 | return -1; | 95 | return -1; |
94 | GNUNET_memcpy(&dest[off], | 96 | GNUNET_memcpy (&dest[off], |
95 | dsr[i].subject_attribute, | 97 | dsr[i].subject_attribute, |
96 | dsr[i].subject_attribute_len); | 98 | dsr[i].subject_attribute_len); |
97 | off += dsr[i].subject_attribute_len; | 99 | off += dsr[i].subject_attribute_len; |
98 | } | 100 | } |
99 | return off; | 101 | return off; |
100 | } | 102 | } |
101 | 103 | ||
@@ -110,10 +112,12 @@ GNUNET_CREDENTIAL_delegation_set_serialize(unsigned int d_count, | |||
110 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 112 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
111 | */ | 113 | */ |
112 | int | 114 | int |
113 | GNUNET_CREDENTIAL_delegation_set_deserialize(size_t len, | 115 | GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, |
114 | const char *src, | 116 | const char *src, |
115 | unsigned int d_count, | 117 | unsigned int d_count, |
116 | struct GNUNET_CREDENTIAL_DelegationSet *dsr) | 118 | struct |
119 | GNUNET_CREDENTIAL_DelegationSet * | ||
120 | dsr) | ||
117 | { | 121 | { |
118 | struct DelegationRecordData rec; | 122 | struct DelegationRecordData rec; |
119 | unsigned int i; | 123 | unsigned int i; |
@@ -121,18 +125,18 @@ GNUNET_CREDENTIAL_delegation_set_deserialize(size_t len, | |||
121 | 125 | ||
122 | off = 0; | 126 | off = 0; |
123 | for (i = 0; i < d_count; i++) | 127 | for (i = 0; i < d_count; i++) |
124 | { | 128 | { |
125 | if (off + sizeof(rec) > len) | 129 | if (off + sizeof(rec) > len) |
126 | return GNUNET_SYSERR; | 130 | return GNUNET_SYSERR; |
127 | GNUNET_memcpy(&rec, &src[off], sizeof(rec)); | 131 | GNUNET_memcpy (&rec, &src[off], sizeof(rec)); |
128 | dsr[i].subject_key = rec.subject_key; | 132 | dsr[i].subject_key = rec.subject_key; |
129 | off += sizeof(rec); | 133 | off += sizeof(rec); |
130 | dsr[i].subject_attribute_len = ntohl((uint32_t)rec.subject_attribute_len); | 134 | dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); |
131 | if (off + dsr[i].subject_attribute_len > len) | 135 | if (off + dsr[i].subject_attribute_len > len) |
132 | return GNUNET_SYSERR; | 136 | return GNUNET_SYSERR; |
133 | dsr[i].subject_attribute = (char*)&src[off]; | 137 | dsr[i].subject_attribute = (char*) &src[off]; |
134 | off += dsr[i].subject_attribute_len; | 138 | off += dsr[i].subject_attribute_len; |
135 | } | 139 | } |
136 | return GNUNET_OK; | 140 | return GNUNET_OK; |
137 | } | 141 | } |
138 | 142 | ||
@@ -146,8 +150,9 @@ GNUNET_CREDENTIAL_delegation_set_deserialize(size_t len, | |||
146 | * @return the required size to serialize | 150 | * @return the required size to serialize |
147 | */ | 151 | */ |
148 | size_t | 152 | size_t |
149 | GNUNET_CREDENTIAL_credentials_get_size(unsigned int c_count, | 153 | GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, |
150 | const struct GNUNET_CREDENTIAL_Credential *cd) | 154 | const struct |
155 | GNUNET_CREDENTIAL_Credential *cd) | ||
151 | { | 156 | { |
152 | unsigned int i; | 157 | unsigned int i; |
153 | size_t ret; | 158 | size_t ret; |
@@ -155,10 +160,10 @@ GNUNET_CREDENTIAL_credentials_get_size(unsigned int c_count, | |||
155 | ret = sizeof(struct CredentialEntry) * (c_count); | 160 | ret = sizeof(struct CredentialEntry) * (c_count); |
156 | 161 | ||
157 | for (i = 0; i < c_count; i++) | 162 | for (i = 0; i < c_count; i++) |
158 | { | 163 | { |
159 | GNUNET_assert((ret + cd[i].issuer_attribute_len) >= ret); | 164 | GNUNET_assert ((ret + cd[i].issuer_attribute_len) >= ret); |
160 | ret += cd[i].issuer_attribute_len; | 165 | ret += cd[i].issuer_attribute_len; |
161 | } | 166 | } |
162 | return ret; | 167 | return ret; |
163 | } | 168 | } |
164 | /** | 169 | /** |
@@ -171,10 +176,11 @@ GNUNET_CREDENTIAL_credentials_get_size(unsigned int c_count, | |||
171 | * @return the size of the data, -1 on failure | 176 | * @return the size of the data, -1 on failure |
172 | */ | 177 | */ |
173 | ssize_t | 178 | ssize_t |
174 | GNUNET_CREDENTIAL_credentials_serialize(unsigned int c_count, | 179 | GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, |
175 | const struct GNUNET_CREDENTIAL_Credential *cd, | 180 | const struct |
176 | size_t dest_size, | 181 | GNUNET_CREDENTIAL_Credential *cd, |
177 | char *dest) | 182 | size_t dest_size, |
183 | char *dest) | ||
178 | { | 184 | { |
179 | struct CredentialEntry c_rec; | 185 | struct CredentialEntry c_rec; |
180 | unsigned int i; | 186 | unsigned int i; |
@@ -182,27 +188,29 @@ GNUNET_CREDENTIAL_credentials_serialize(unsigned int c_count, | |||
182 | 188 | ||
183 | off = 0; | 189 | off = 0; |
184 | for (i = 0; i < c_count; i++) | 190 | for (i = 0; i < c_count; i++) |
185 | { | 191 | { |
186 | c_rec.issuer_attribute_len = htonl((uint32_t)cd[i].issuer_attribute_len); | 192 | c_rec.issuer_attribute_len = htonl ((uint32_t) cd[i].issuer_attribute_len); |
187 | c_rec.issuer_key = cd[i].issuer_key; | 193 | c_rec.issuer_key = cd[i].issuer_key; |
188 | c_rec.subject_key = cd[i].subject_key; | 194 | c_rec.subject_key = cd[i].subject_key; |
189 | c_rec.signature = cd[i].signature; | 195 | c_rec.signature = cd[i].signature; |
190 | c_rec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 196 | c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
191 | c_rec.purpose.size = htonl((sizeof(struct CredentialEntry) + cd[i].issuer_attribute_len) - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); | 197 | c_rec.purpose.size = htonl ((sizeof(struct CredentialEntry) |
192 | c_rec.expiration = GNUNET_htonll(cd[i].expiration.abs_value_us); | 198 | + cd[i].issuer_attribute_len) - sizeof(struct |
193 | if (off + sizeof(c_rec) > dest_size) | 199 | GNUNET_CRYPTO_EcdsaSignature)); |
194 | return -1; | 200 | c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); |
195 | GNUNET_memcpy(&dest[off], | 201 | if (off + sizeof(c_rec) > dest_size) |
196 | &c_rec, | 202 | return -1; |
197 | sizeof(c_rec)); | 203 | GNUNET_memcpy (&dest[off], |
198 | off += sizeof(c_rec); | 204 | &c_rec, |
199 | if (off + cd[i].issuer_attribute_len > dest_size) | 205 | sizeof(c_rec)); |
200 | return -1; | 206 | off += sizeof(c_rec); |
201 | GNUNET_memcpy(&dest[off], | 207 | if (off + cd[i].issuer_attribute_len > dest_size) |
202 | cd[i].issuer_attribute, | 208 | return -1; |
203 | cd[i].issuer_attribute_len); | 209 | GNUNET_memcpy (&dest[off], |
204 | off += cd[i].issuer_attribute_len; | 210 | cd[i].issuer_attribute, |
205 | } | 211 | cd[i].issuer_attribute_len); |
212 | off += cd[i].issuer_attribute_len; | ||
213 | } | ||
206 | 214 | ||
207 | return off; | 215 | return off; |
208 | } | 216 | } |
@@ -219,10 +227,11 @@ GNUNET_CREDENTIAL_credentials_serialize(unsigned int c_count, | |||
219 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 227 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
220 | */ | 228 | */ |
221 | int | 229 | int |
222 | GNUNET_CREDENTIAL_credentials_deserialize(size_t len, | 230 | GNUNET_CREDENTIAL_credentials_deserialize (size_t len, |
223 | const char *src, | 231 | const char *src, |
224 | unsigned int c_count, | 232 | unsigned int c_count, |
225 | struct GNUNET_CREDENTIAL_Credential *cd) | 233 | struct GNUNET_CREDENTIAL_Credential * |
234 | cd) | ||
226 | { | 235 | { |
227 | struct CredentialEntry c_rec; | 236 | struct CredentialEntry c_rec; |
228 | unsigned int i; | 237 | unsigned int i; |
@@ -230,21 +239,21 @@ GNUNET_CREDENTIAL_credentials_deserialize(size_t len, | |||
230 | 239 | ||
231 | off = 0; | 240 | off = 0; |
232 | for (i = 0; i < c_count; i++) | 241 | for (i = 0; i < c_count; i++) |
233 | { | 242 | { |
234 | if (off + sizeof(c_rec) > len) | 243 | if (off + sizeof(c_rec) > len) |
235 | return GNUNET_SYSERR; | 244 | return GNUNET_SYSERR; |
236 | GNUNET_memcpy(&c_rec, &src[off], sizeof(c_rec)); | 245 | GNUNET_memcpy (&c_rec, &src[off], sizeof(c_rec)); |
237 | cd[i].issuer_attribute_len = ntohl((uint32_t)c_rec.issuer_attribute_len); | 246 | cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len); |
238 | cd[i].issuer_key = c_rec.issuer_key; | 247 | cd[i].issuer_key = c_rec.issuer_key; |
239 | cd[i].subject_key = c_rec.subject_key; | 248 | cd[i].subject_key = c_rec.subject_key; |
240 | cd[i].signature = c_rec.signature; | 249 | cd[i].signature = c_rec.signature; |
241 | cd[i].expiration.abs_value_us = GNUNET_ntohll(c_rec.expiration); | 250 | cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration); |
242 | off += sizeof(c_rec); | 251 | off += sizeof(c_rec); |
243 | if (off + cd[i].issuer_attribute_len > len) | 252 | if (off + cd[i].issuer_attribute_len > len) |
244 | return GNUNET_SYSERR; | 253 | return GNUNET_SYSERR; |
245 | cd[i].issuer_attribute = &src[off]; | 254 | cd[i].issuer_attribute = &src[off]; |
246 | off += cd[i].issuer_attribute_len; | 255 | off += cd[i].issuer_attribute_len; |
247 | } | 256 | } |
248 | return GNUNET_OK; | 257 | return GNUNET_OK; |
249 | } | 258 | } |
250 | 259 | ||
@@ -261,10 +270,12 @@ GNUNET_CREDENTIAL_credentials_deserialize(size_t len, | |||
261 | * @return the required size to serialize | 270 | * @return the required size to serialize |
262 | */ | 271 | */ |
263 | size_t | 272 | size_t |
264 | GNUNET_CREDENTIAL_delegation_chain_get_size(unsigned int d_count, | 273 | GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, |
265 | const struct GNUNET_CREDENTIAL_Delegation *dd, | 274 | const struct |
266 | unsigned int c_count, | 275 | GNUNET_CREDENTIAL_Delegation *dd, |
267 | const struct GNUNET_CREDENTIAL_Credential *cd) | 276 | unsigned int c_count, |
277 | const struct | ||
278 | GNUNET_CREDENTIAL_Credential *cd) | ||
268 | { | 279 | { |
269 | unsigned int i; | 280 | unsigned int i; |
270 | size_t ret; | 281 | size_t ret; |
@@ -272,13 +283,13 @@ GNUNET_CREDENTIAL_delegation_chain_get_size(unsigned int d_count, | |||
272 | ret = sizeof(struct ChainEntry) * (d_count); | 283 | ret = sizeof(struct ChainEntry) * (d_count); |
273 | 284 | ||
274 | for (i = 0; i < d_count; i++) | 285 | for (i = 0; i < d_count; i++) |
275 | { | 286 | { |
276 | GNUNET_assert((ret + | 287 | GNUNET_assert ((ret |
277 | dd[i].issuer_attribute_len + | 288 | + dd[i].issuer_attribute_len |
278 | dd[i].subject_attribute_len) >= ret); | 289 | + dd[i].subject_attribute_len) >= ret); |
279 | ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; | 290 | ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; |
280 | } | 291 | } |
281 | return ret + GNUNET_CREDENTIAL_credentials_get_size(c_count, cd); | 292 | return ret + GNUNET_CREDENTIAL_credentials_get_size (c_count, cd); |
282 | } | 293 | } |
283 | 294 | ||
284 | /** | 295 | /** |
@@ -293,12 +304,14 @@ GNUNET_CREDENTIAL_delegation_chain_get_size(unsigned int d_count, | |||
293 | * @return the size of the data, -1 on failure | 304 | * @return the size of the data, -1 on failure |
294 | */ | 305 | */ |
295 | ssize_t | 306 | ssize_t |
296 | GNUNET_CREDENTIAL_delegation_chain_serialize(unsigned int d_count, | 307 | GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, |
297 | const struct GNUNET_CREDENTIAL_Delegation *dd, | 308 | const struct |
298 | unsigned int c_count, | 309 | GNUNET_CREDENTIAL_Delegation *dd, |
299 | const struct GNUNET_CREDENTIAL_Credential *cd, | 310 | unsigned int c_count, |
300 | size_t dest_size, | 311 | const struct |
301 | char *dest) | 312 | GNUNET_CREDENTIAL_Credential *cd, |
313 | size_t dest_size, | ||
314 | char *dest) | ||
302 | { | 315 | { |
303 | struct ChainEntry rec; | 316 | struct ChainEntry rec; |
304 | unsigned int i; | 317 | unsigned int i; |
@@ -306,36 +319,36 @@ GNUNET_CREDENTIAL_delegation_chain_serialize(unsigned int d_count, | |||
306 | 319 | ||
307 | off = 0; | 320 | off = 0; |
308 | for (i = 0; i < d_count; i++) | 321 | for (i = 0; i < d_count; i++) |
309 | { | 322 | { |
310 | rec.issuer_attribute_len = htonl((uint32_t)dd[i].issuer_attribute_len); | 323 | rec.issuer_attribute_len = htonl ((uint32_t) dd[i].issuer_attribute_len); |
311 | rec.subject_attribute_len = htonl((uint32_t)dd[i].subject_attribute_len); | 324 | rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len); |
312 | rec.issuer_key = dd[i].issuer_key; | 325 | rec.issuer_key = dd[i].issuer_key; |
313 | rec.subject_key = dd[i].subject_key; | 326 | rec.subject_key = dd[i].subject_key; |
314 | if (off + sizeof(rec) > dest_size) | 327 | if (off + sizeof(rec) > dest_size) |
315 | return -1; | 328 | return -1; |
316 | GNUNET_memcpy(&dest[off], | 329 | GNUNET_memcpy (&dest[off], |
317 | &rec, | 330 | &rec, |
318 | sizeof(rec)); | 331 | sizeof(rec)); |
319 | off += sizeof(rec); | 332 | off += sizeof(rec); |
320 | if (off + dd[i].issuer_attribute_len > dest_size) | 333 | if (off + dd[i].issuer_attribute_len > dest_size) |
321 | return -1; | 334 | return -1; |
322 | GNUNET_memcpy(&dest[off], | 335 | GNUNET_memcpy (&dest[off], |
323 | dd[i].issuer_attribute, | 336 | dd[i].issuer_attribute, |
324 | dd[i].issuer_attribute_len); | 337 | dd[i].issuer_attribute_len); |
325 | off += dd[i].issuer_attribute_len; | 338 | off += dd[i].issuer_attribute_len; |
326 | if (0 == dd[i].subject_attribute_len) | 339 | if (0 == dd[i].subject_attribute_len) |
327 | continue; | 340 | continue; |
328 | if (off + dd[i].subject_attribute_len > dest_size) | 341 | if (off + dd[i].subject_attribute_len > dest_size) |
329 | return -1; | 342 | return -1; |
330 | GNUNET_memcpy(&dest[off], | 343 | GNUNET_memcpy (&dest[off], |
331 | dd[i].subject_attribute, | 344 | dd[i].subject_attribute, |
332 | dd[i].subject_attribute_len); | 345 | dd[i].subject_attribute_len); |
333 | off += dd[i].subject_attribute_len; | 346 | off += dd[i].subject_attribute_len; |
334 | } | 347 | } |
335 | return off + GNUNET_CREDENTIAL_credentials_serialize(c_count, | 348 | return off + GNUNET_CREDENTIAL_credentials_serialize (c_count, |
336 | cd, | 349 | cd, |
337 | dest_size - off, | 350 | dest_size - off, |
338 | &dest[off]); | 351 | &dest[off]); |
339 | } | 352 | } |
340 | 353 | ||
341 | 354 | ||
@@ -351,12 +364,14 @@ GNUNET_CREDENTIAL_delegation_chain_serialize(unsigned int d_count, | |||
351 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 364 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
352 | */ | 365 | */ |
353 | int | 366 | int |
354 | GNUNET_CREDENTIAL_delegation_chain_deserialize(size_t len, | 367 | GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, |
355 | const char *src, | 368 | const char *src, |
356 | unsigned int d_count, | 369 | unsigned int d_count, |
357 | struct GNUNET_CREDENTIAL_Delegation *dd, | 370 | struct |
358 | unsigned int c_count, | 371 | GNUNET_CREDENTIAL_Delegation *dd, |
359 | struct GNUNET_CREDENTIAL_Credential *cd) | 372 | unsigned int c_count, |
373 | struct | ||
374 | GNUNET_CREDENTIAL_Credential *cd) | ||
360 | { | 375 | { |
361 | struct ChainEntry rec; | 376 | struct ChainEntry rec; |
362 | unsigned int i; | 377 | unsigned int i; |
@@ -364,65 +379,68 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize(size_t len, | |||
364 | 379 | ||
365 | off = 0; | 380 | off = 0; |
366 | for (i = 0; i < d_count; i++) | 381 | for (i = 0; i < d_count; i++) |
367 | { | 382 | { |
368 | if (off + sizeof(rec) > len) | 383 | if (off + sizeof(rec) > len) |
369 | return GNUNET_SYSERR; | 384 | return GNUNET_SYSERR; |
370 | GNUNET_memcpy(&rec, &src[off], sizeof(rec)); | 385 | GNUNET_memcpy (&rec, &src[off], sizeof(rec)); |
371 | dd[i].issuer_attribute_len = ntohl((uint32_t)rec.issuer_attribute_len); | 386 | dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); |
372 | dd[i].issuer_key = rec.issuer_key; | 387 | dd[i].issuer_key = rec.issuer_key; |
373 | dd[i].subject_key = rec.subject_key; | 388 | dd[i].subject_key = rec.subject_key; |
374 | off += sizeof(rec); | 389 | off += sizeof(rec); |
375 | if (off + dd[i].issuer_attribute_len > len) | 390 | if (off + dd[i].issuer_attribute_len > len) |
376 | return GNUNET_SYSERR; | 391 | return GNUNET_SYSERR; |
377 | dd[i].issuer_attribute = &src[off]; | 392 | dd[i].issuer_attribute = &src[off]; |
378 | off += dd[i].issuer_attribute_len; | 393 | off += dd[i].issuer_attribute_len; |
379 | dd[i].subject_attribute_len = ntohl((uint32_t)rec.subject_attribute_len); | 394 | dd[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); |
380 | if (off + dd[i].subject_attribute_len > len) | 395 | if (off + dd[i].subject_attribute_len > len) |
381 | return GNUNET_SYSERR; | 396 | return GNUNET_SYSERR; |
382 | dd[i].subject_attribute = &src[off]; | 397 | dd[i].subject_attribute = &src[off]; |
383 | off += dd[i].subject_attribute_len; | 398 | off += dd[i].subject_attribute_len; |
384 | } | 399 | } |
385 | return GNUNET_CREDENTIAL_credentials_deserialize(len - off, | 400 | return GNUNET_CREDENTIAL_credentials_deserialize (len - off, |
386 | &src[off], | 401 | &src[off], |
387 | c_count, | 402 | c_count, |
388 | cd); | 403 | cd); |
389 | } | 404 | } |
390 | int | 405 | int |
391 | GNUNET_CREDENTIAL_credential_serialize(struct GNUNET_CREDENTIAL_Credential *cred, | 406 | GNUNET_CREDENTIAL_credential_serialize (struct |
392 | char **data) | 407 | GNUNET_CREDENTIAL_Credential *cred, |
408 | char **data) | ||
393 | { | 409 | { |
394 | size_t size; | 410 | size_t size; |
395 | struct CredentialEntry *cdata; | 411 | struct CredentialEntry *cdata; |
396 | 412 | ||
397 | size = sizeof(struct CredentialEntry) + strlen(cred->issuer_attribute) + 1; | 413 | size = sizeof(struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; |
398 | *data = GNUNET_malloc(size); | 414 | *data = GNUNET_malloc (size); |
399 | cdata = (struct CredentialEntry*)*data; | 415 | cdata = (struct CredentialEntry*) *data; |
400 | cdata->subject_key = cred->subject_key; | 416 | cdata->subject_key = cred->subject_key; |
401 | cdata->issuer_key = cred->issuer_key; | 417 | cdata->issuer_key = cred->issuer_key; |
402 | cdata->expiration = GNUNET_htonll(cred->expiration.abs_value_us); | 418 | cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); |
403 | cdata->signature = cred->signature; | 419 | cdata->signature = cred->signature; |
404 | cdata->issuer_attribute_len = htonl(strlen(cred->issuer_attribute) + 1); | 420 | cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); |
405 | cdata->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 421 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
406 | cdata->purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); | 422 | cdata->purpose.size = htonl (size - sizeof(struct |
407 | GNUNET_memcpy(&cdata[1], | 423 | GNUNET_CRYPTO_EcdsaSignature)); |
408 | cred->issuer_attribute, | 424 | GNUNET_memcpy (&cdata[1], |
409 | strlen(cred->issuer_attribute)); | 425 | cred->issuer_attribute, |
410 | 426 | strlen (cred->issuer_attribute)); | |
411 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | 427 | |
412 | &cdata->purpose, | 428 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( |
413 | &cdata->signature, | 429 | GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, |
414 | &cdata->issuer_key)) | 430 | &cdata->purpose, |
415 | { | 431 | &cdata->signature, |
416 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 432 | &cdata->issuer_key)) |
417 | "Invalid credential\n"); | 433 | { |
418 | //return NULL; | 434 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
419 | } | 435 | "Invalid credential\n"); |
436 | // return NULL; | ||
437 | } | ||
420 | return size; | 438 | return size; |
421 | } | 439 | } |
422 | 440 | ||
423 | struct GNUNET_CREDENTIAL_Credential* | 441 | struct GNUNET_CREDENTIAL_Credential* |
424 | GNUNET_CREDENTIAL_credential_deserialize(const char* data, | 442 | GNUNET_CREDENTIAL_credential_deserialize (const char*data, |
425 | size_t data_size) | 443 | size_t data_size) |
426 | { | 444 | { |
427 | struct GNUNET_CREDENTIAL_Credential *cred; | 445 | struct GNUNET_CREDENTIAL_Credential *cred; |
428 | struct CredentialEntry *cdata; | 446 | struct CredentialEntry *cdata; |
@@ -430,28 +448,30 @@ GNUNET_CREDENTIAL_credential_deserialize(const char* data, | |||
430 | 448 | ||
431 | if (data_size < sizeof(struct CredentialEntry)) | 449 | if (data_size < sizeof(struct CredentialEntry)) |
432 | return NULL; | 450 | return NULL; |
433 | cdata = (struct CredentialEntry*)data; | 451 | cdata = (struct CredentialEntry*) data; |
434 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | 452 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( |
435 | &cdata->purpose, | 453 | GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, |
436 | &cdata->signature, | 454 | &cdata->purpose, |
437 | &cdata->issuer_key)) | 455 | &cdata->signature, |
438 | { | 456 | &cdata->issuer_key)) |
439 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 457 | { |
440 | "Invalid credential\n"); | 458 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
441 | //return NULL; | 459 | "Invalid credential\n"); |
442 | } | 460 | // return NULL; |
443 | issuer_attribute = (char*)&cdata[1]; | 461 | } |
444 | 462 | issuer_attribute = (char*) &cdata[1]; | |
445 | cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl(cdata->issuer_attribute_len)); | 463 | |
464 | cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl ( | ||
465 | cdata->issuer_attribute_len)); | ||
446 | 466 | ||
447 | cred->issuer_key = cdata->issuer_key; | 467 | cred->issuer_key = cdata->issuer_key; |
448 | cred->subject_key = cdata->subject_key; | 468 | cred->subject_key = cdata->subject_key; |
449 | GNUNET_memcpy(&cred[1], | 469 | GNUNET_memcpy (&cred[1], |
450 | issuer_attribute, | 470 | issuer_attribute, |
451 | ntohl(cdata->issuer_attribute_len)); | 471 | ntohl (cdata->issuer_attribute_len)); |
452 | cred->signature = cdata->signature; | 472 | cred->signature = cdata->signature; |
453 | cred->issuer_attribute = (char*)&cred[1]; | 473 | cred->issuer_attribute = (char*) &cred[1]; |
454 | cred->expiration.abs_value_us = GNUNET_ntohll(cdata->expiration); | 474 | cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); |
455 | return cred; | 475 | return cred; |
456 | } | 476 | } |
457 | 477 | ||