aboutsummaryrefslogtreecommitdiff
path: root/src/credential/credential_serialization.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/credential_serialization.c')
-rw-r--r--src/credential/credential_serialization.c75
1 files changed, 46 insertions, 29 deletions
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c
index 99138441e..b08920d96 100644
--- a/src/credential/credential_serialization.c
+++ b/src/credential/credential_serialization.c
@@ -184,18 +184,21 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len,
184 * 184 *
185 * @param d_count number of delegation chain entries 185 * @param d_count number of delegation chain entries
186 * @param dd array of #GNUNET_CREDENTIAL_Delegation 186 * @param dd array of #GNUNET_CREDENTIAL_Delegation
187 * @param c_count number of credential entries
187 * @param cd a #GNUNET_CREDENTIAL_Credential 188 * @param cd a #GNUNET_CREDENTIAL_Credential
188 * @return the required size to serialize 189 * @return the required size to serialize
189 */ 190 */
190size_t 191size_t
191GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, 192GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count,
192 const struct GNUNET_CREDENTIAL_Delegation *dd, 193 const struct GNUNET_CREDENTIAL_Delegation *dd,
194 unsigned int c_count,
193 const struct GNUNET_CREDENTIAL_Credential *cd) 195 const struct GNUNET_CREDENTIAL_Credential *cd)
194{ 196{
195 unsigned int i; 197 unsigned int i;
196 size_t ret; 198 size_t ret;
197 199
198 ret = sizeof (struct ChainEntry) * (d_count + 1); 200 ret = sizeof (struct ChainEntry) * (d_count);
201 ret += sizeof (struct ChainEntry) * (c_count);
199 202
200 for (i=0; i<d_count;i++) 203 for (i=0; i<d_count;i++)
201 { 204 {
@@ -204,8 +207,11 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count,
204 dd[i].subject_attribute_len) >= ret); 207 dd[i].subject_attribute_len) >= ret);
205 ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; 208 ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len;
206 } 209 }
207 GNUNET_assert ((ret + cd->issuer_attribute_len) >= ret); 210 for (i=0; i<c_count;i++)
208 ret += cd->issuer_attribute_len; 211 {
212 GNUNET_assert ((ret + cd[i].issuer_attribute_len) >= ret);
213 ret += cd[i].issuer_attribute_len;
214 }
209 return ret; 215 return ret;
210} 216}
211 217
@@ -214,6 +220,7 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count,
214 * 220 *
215 * @param d_count number of delegation chain entries 221 * @param d_count number of delegation chain entries
216 * @param dd array of #GNUNET_CREDENTIAL_Delegation 222 * @param dd array of #GNUNET_CREDENTIAL_Delegation
223 * @param c_count number of credential entries
217 * @param cd a #GNUNET_CREDENTIAL_Credential 224 * @param cd a #GNUNET_CREDENTIAL_Credential
218 * @param dest_size size of the destination 225 * @param dest_size size of the destination
219 * @param dest where to store the result 226 * @param dest where to store the result
@@ -222,6 +229,7 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count,
222ssize_t 229ssize_t
223GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, 230GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count,
224 const struct GNUNET_CREDENTIAL_Delegation *dd, 231 const struct GNUNET_CREDENTIAL_Delegation *dd,
232 unsigned int c_count,
225 const struct GNUNET_CREDENTIAL_Credential *cd, 233 const struct GNUNET_CREDENTIAL_Credential *cd,
226 size_t dest_size, 234 size_t dest_size,
227 char *dest) 235 char *dest)
@@ -258,21 +266,25 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count,
258 dd[i].subject_attribute_len); 266 dd[i].subject_attribute_len);
259 off += dd[i].subject_attribute_len; 267 off += dd[i].subject_attribute_len;
260 } 268 }
261 rec.issuer_attribute_len = htonl ((uint32_t) cd->issuer_attribute_len); 269 for (i=0;i<c_count;i++)
262 rec.subject_attribute_len = htonl (0); 270 {
263 rec.issuer_key = cd->issuer_key; 271 rec.issuer_attribute_len = htonl ((uint32_t) cd[i].issuer_attribute_len);
264 if (off + sizeof (rec) > dest_size) 272 rec.subject_attribute_len = htonl (0);
265 return -1; 273 rec.issuer_key = cd[i].issuer_key;
266 GNUNET_memcpy (&dest[off], 274 rec.subject_key = cd[i].subject_key;
267 &rec, 275 if (off + sizeof (rec) > dest_size)
268 sizeof (rec)); 276 return -1;
269 off += sizeof (rec); 277 GNUNET_memcpy (&dest[off],
270 if (off + cd->issuer_attribute_len > dest_size) 278 &rec,
271 return -1; 279 sizeof (rec));
272 GNUNET_memcpy (&dest[off], 280 off += sizeof (rec);
273 cd->issuer_attribute, 281 if (off + cd[i].issuer_attribute_len > dest_size)
274 cd->issuer_attribute_len); 282 return -1;
275 off += cd->issuer_attribute_len; 283 GNUNET_memcpy (&dest[off],
284 cd[i].issuer_attribute,
285 cd[i].issuer_attribute_len);
286 off += cd[i].issuer_attribute_len;
287 }
276 288
277 return off; 289 return off;
278} 290}
@@ -285,6 +297,7 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count,
285 * @param src the serialized data 297 * @param src the serialized data
286 * @param d_count the number of delegation chain entries 298 * @param d_count the number of delegation chain entries
287 * @param dd where to put the delegation chain entries 299 * @param dd where to put the delegation chain entries
300 * @param c_count the number of credential entries
288 * @param cd where to put the credential data 301 * @param cd where to put the credential data
289 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 302 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
290 */ 303 */
@@ -293,6 +306,7 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len,
293 const char *src, 306 const char *src,
294 unsigned int d_count, 307 unsigned int d_count,
295 struct GNUNET_CREDENTIAL_Delegation *dd, 308 struct GNUNET_CREDENTIAL_Delegation *dd,
309 unsigned int c_count,
296 struct GNUNET_CREDENTIAL_Credential *cd) 310 struct GNUNET_CREDENTIAL_Credential *cd)
297{ 311{
298 struct ChainEntry rec; 312 struct ChainEntry rec;
@@ -319,17 +333,20 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len,
319 dd[i].subject_attribute = &src[off]; 333 dd[i].subject_attribute = &src[off];
320 off += dd[i].subject_attribute_len; 334 off += dd[i].subject_attribute_len;
321 } 335 }
322 if (off + sizeof (rec) > len) 336 for (i=0;i<c_count;i++)
323 return GNUNET_SYSERR; 337 {
324 GNUNET_memcpy (&rec, &src[off], sizeof (rec)); 338 if (off + sizeof (rec) > len)
325 cd->issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); 339 return GNUNET_SYSERR;
326 cd->issuer_key = rec.issuer_key; 340 GNUNET_memcpy (&rec, &src[off], sizeof (rec));
327 cd->subject_key = rec.subject_key; 341 cd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len);
328 off += sizeof (rec); 342 cd[i].issuer_key = rec.issuer_key;
329 if (off + cd->issuer_attribute_len > len) 343 cd[i].subject_key = rec.subject_key;
330 return GNUNET_SYSERR; 344 off += sizeof (rec);
331 cd->issuer_attribute = &src[off]; 345 if (off + cd[i].issuer_attribute_len > len)
332 off += cd->issuer_attribute_len; 346 return GNUNET_SYSERR;
347 cd[i].issuer_attribute = &src[off];
348 off += cd[i].issuer_attribute_len;
349 }
333 return GNUNET_OK; 350 return GNUNET_OK;
334} 351}
335 352