diff options
Diffstat (limited to 'src/zklaim/zklaim_api.c')
-rw-r--r-- | src/zklaim/zklaim_api.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/zklaim/zklaim_api.c b/src/zklaim/zklaim_api.c index 6e9da67f3..6ca94fda5 100644 --- a/src/zklaim/zklaim_api.c +++ b/src/zklaim/zklaim_api.c | |||
@@ -536,4 +536,60 @@ GNUNET_ZKLAIM_issue_from_context (struct GNUNET_ZKLAIM_Context *ctx, | |||
536 | iter_cls); | 536 | iter_cls); |
537 | } | 537 | } |
538 | 538 | ||
539 | size_t | ||
540 | GNUNET_ZKLAIM_context_serialize (const struct GNUNET_ZKLAIM_Context *ctx, | ||
541 | char **buf) | ||
542 | { | ||
543 | char *pos; | ||
544 | char *tmp; | ||
545 | size_t len; | ||
546 | size_t len_w; | ||
547 | size_t ret_len = 0; | ||
548 | len = zklaim_ctx_serialize (ctx->ctx, | ||
549 | (unsigned char**) &tmp); | ||
550 | ret_len += strlen (ctx->attrs) + 1 + sizeof (size_t) + len; | ||
551 | *buf = GNUNET_malloc (ret_len); | ||
552 | pos = *buf; | ||
553 | memcpy (pos, ctx->attrs, strlen (ctx->attrs) + 1); | ||
554 | pos += strlen (ctx->attrs) + 1; | ||
555 | len_w = htonl (len); | ||
556 | memcpy (pos, &len_w, sizeof (size_t)); | ||
557 | pos += sizeof (size_t); | ||
558 | memcpy (pos, tmp, len); | ||
559 | GNUNET_free (tmp); | ||
560 | return ret_len; | ||
561 | } | ||
562 | |||
563 | |||
564 | struct GNUNET_ZKLAIM_Context * | ||
565 | GNUNET_ZKLAIM_context_deserialize (char *data, | ||
566 | size_t data_len) | ||
567 | { | ||
568 | struct GNUNET_ZKLAIM_Context *ctx; | ||
569 | char *pos; | ||
570 | size_t len; | ||
571 | |||
572 | ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context); | ||
573 | ctx->attrs = GNUNET_strdup (data); | ||
574 | pos = data + strlen (ctx->attrs) + 1; | ||
575 | len = ntohl (*((size_t*)pos)); | ||
576 | ctx->ctx = zklaim_context_new (); | ||
577 | pos += sizeof (size_t); | ||
578 | if (0 != zklaim_ctx_deserialize (ctx->ctx, | ||
579 | (unsigned char*) pos, | ||
580 | len)) | ||
581 | return NULL; | ||
582 | return ctx; | ||
583 | } | ||
584 | |||
585 | int | ||
586 | GNUNET_ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx, | ||
587 | GNUNET_ZKLAIM_PredicateIterator iter, | ||
588 | void* iter_cls) | ||
589 | { | ||
590 | return ZKLAIM_context_prove (ctx, | ||
591 | iter, | ||
592 | iter_cls); | ||
593 | } | ||
594 | |||
539 | /* end of zklaim_api.c */ | 595 | /* end of zklaim_api.c */ |