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