aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/zklaim_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zklaim/zklaim_api.c')
-rw-r--r--src/zklaim/zklaim_api.c87
1 files changed, 67 insertions, 20 deletions
diff --git a/src/zklaim/zklaim_api.c b/src/zklaim/zklaim_api.c
index 6ca94fda5..fb83cccb6 100644
--- a/src/zklaim/zklaim_api.c
+++ b/src/zklaim/zklaim_api.c
@@ -281,8 +281,8 @@ handle_zklaim_result_ctx (void *cls,
281{ 281{
282 struct GNUNET_ZKLAIM_Handle *h = cls; 282 struct GNUNET_ZKLAIM_Handle *h = cls;
283 struct GNUNET_ZKLAIM_Operation *op; 283 struct GNUNET_ZKLAIM_Operation *op;
284 struct GNUNET_ZKLAIM_Context ctx; 284 struct GNUNET_ZKLAIM_Context *ctx;
285 uint16_t ctx_len = ntohl (cm->ctx_len); 285 uint16_t ctx_len = ntohs (cm->ctx_len);
286 286
287 op = h->op_head; 287 op = h->op_head;
288 if (NULL == op) 288 if (NULL == op)
@@ -294,21 +294,22 @@ handle_zklaim_result_ctx (void *cls,
294 GNUNET_CONTAINER_DLL_remove (h->op_head, 294 GNUNET_CONTAINER_DLL_remove (h->op_head,
295 h->op_tail, 295 h->op_tail,
296 op); 296 op);
297 ctx.attrs = (char*)&cm[1];
298 ctx.ctx = zklaim_context_new ();
299 zklaim_ctx_deserialize (ctx.ctx,
300 (unsigned char *) &cm[1] + strlen (ctx.attrs) + 1,
301 ctx_len - strlen (ctx.attrs) - 1);
302 if (NULL != op->ctx_cont) 297 if (NULL != op->ctx_cont)
303 { 298 {
304 if (0 > ctx_len) 299 fprintf (stderr,
300 "ctx_len %d\n", ctx_len);
301 if (0 < ctx_len)
302 {
303 ctx = GNUNET_ZKLAIM_context_deserialize ((char*)&cm[1],
304 ctx_len);
305 op->ctx_cont (op->cls, 305 op->ctx_cont (op->cls,
306 &ctx); 306 ctx);
307 GNUNET_ZKLAIM_context_destroy (ctx);
308 }
307 else 309 else
308 op->ctx_cont (op->cls, 310 op->ctx_cont (op->cls,
309 &ctx); 311 NULL);
310 } 312 }
311 zklaim_ctx_free (ctx.ctx);
312 GNUNET_free (op); 313 GNUNET_free (op);
313} 314}
314 315
@@ -480,6 +481,15 @@ GNUNET_ZKLAIM_disconnect (struct GNUNET_ZKLAIM_Handle *h)
480 GNUNET_free (h); 481 GNUNET_free (h);
481} 482}
482 483
484void
485GNUNET_ZKLAIM_context_destroy (struct GNUNET_ZKLAIM_Context *ctx)
486{
487 GNUNET_free_non_null (ctx->name);
488 GNUNET_free_non_null (ctx->attrs);
489 zklaim_ctx_free (ctx->ctx);
490 GNUNET_free (ctx);
491}
492
483/** 493/**
484 * Lookup context 494 * Lookup context
485 */ 495 */
@@ -543,18 +553,22 @@ GNUNET_ZKLAIM_context_serialize (const struct GNUNET_ZKLAIM_Context *ctx,
543 char *pos; 553 char *pos;
544 char *tmp; 554 char *tmp;
545 size_t len; 555 size_t len;
546 size_t len_w; 556 uint64_t len_w;
547 size_t ret_len = 0; 557 size_t ret_len = 0;
558 size_t alen = strlen (ctx->attrs) + 1;
559 size_t nlen = strlen (ctx->name) + 1;
548 len = zklaim_ctx_serialize (ctx->ctx, 560 len = zklaim_ctx_serialize (ctx->ctx,
549 (unsigned char**) &tmp); 561 (unsigned char**) &tmp);
550 ret_len += strlen (ctx->attrs) + 1 + sizeof (size_t) + len; 562 ret_len += alen + nlen + sizeof (size_t) + len;
551 *buf = GNUNET_malloc (ret_len); 563 *buf = GNUNET_malloc (ret_len);
552 pos = *buf; 564 pos = *buf;
553 memcpy (pos, ctx->attrs, strlen (ctx->attrs) + 1); 565 memcpy (pos, ctx->attrs, alen);
554 pos += strlen (ctx->attrs) + 1; 566 pos += alen;
555 len_w = htonl (len); 567 memcpy (pos, ctx->name, nlen);
556 memcpy (pos, &len_w, sizeof (size_t)); 568 pos += nlen;
557 pos += sizeof (size_t); 569 len_w = htons (len);
570 memcpy (pos, &len_w, sizeof (uint16_t));
571 pos += sizeof (uint16_t);
558 memcpy (pos, tmp, len); 572 memcpy (pos, tmp, len);
559 GNUNET_free (tmp); 573 GNUNET_free (tmp);
560 return ret_len; 574 return ret_len;
@@ -572,9 +586,11 @@ GNUNET_ZKLAIM_context_deserialize (char *data,
572 ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context); 586 ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context);
573 ctx->attrs = GNUNET_strdup (data); 587 ctx->attrs = GNUNET_strdup (data);
574 pos = data + strlen (ctx->attrs) + 1; 588 pos = data + strlen (ctx->attrs) + 1;
575 len = ntohl (*((size_t*)pos)); 589 ctx->name = GNUNET_strdup (pos);
590 pos += strlen (ctx->name) + 1;
591 len = ntohs (*((uint16_t*)pos));
576 ctx->ctx = zklaim_context_new (); 592 ctx->ctx = zklaim_context_new ();
577 pos += sizeof (size_t); 593 pos += sizeof (uint16_t);
578 if (0 != zklaim_ctx_deserialize (ctx->ctx, 594 if (0 != zklaim_ctx_deserialize (ctx->ctx,
579 (unsigned char*) pos, 595 (unsigned char*) pos,
580 len)) 596 len))
@@ -582,6 +598,37 @@ GNUNET_ZKLAIM_context_deserialize (char *data,
582 return ctx; 598 return ctx;
583} 599}
584 600
601
602int
603GNUNET_ZKLAIM_context_prove_with_keyfile (struct GNUNET_ZKLAIM_Context *ctx,
604 const char* pkey_fn,
605 GNUNET_ZKLAIM_PredicateIterator iter,
606 void* iter_cls)
607{
608 if (GNUNET_SYSERR == GNUNET_DISK_file_size (pkey_fn,
609 &ctx->ctx->pk_size,
610 GNUNET_NO,
611 GNUNET_YES))
612 {
613 return GNUNET_SYSERR;
614 }
615 ctx->ctx->pk = GNUNET_malloc (ctx->ctx->pk_size);
616 if (GNUNET_SYSERR == GNUNET_DISK_fn_read (pkey_fn,
617 ctx->ctx->pk,
618 ctx->ctx->pk_size))
619 {
620 GNUNET_free (ctx->ctx->pk);
621 ctx->ctx->pk = NULL;
622 ctx->ctx->pk_size = 0;
623 return GNUNET_SYSERR;
624 }
625
626 return GNUNET_ZKLAIM_context_prove (ctx,
627 iter,
628 iter_cls);
629}
630
631
585int 632int
586GNUNET_ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx, 633GNUNET_ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
587 GNUNET_ZKLAIM_PredicateIterator iter, 634 GNUNET_ZKLAIM_PredicateIterator iter,