*/
static char* issue_attrs;
+/**
+ * Attribute names for issuer context data
+ */
+static char* credential;
+
+/**
+ * Attribute names for issuer context data
+ */
+static char* prove_predicate;
+
/**
* Attribute names for issuer context data
*/
const struct GNUNET_ZKLAIM_Context *ctx)
{
int ret;
+ size_t len;
+ char* data;
+ char *str;
+
if (NULL == ctx)
{
fprintf (stderr,
(struct GNUNET_CRYPTO_EcdsaPrivateKey*)pkey,
&issue_iter,
NULL);
- fprintf (stdout,
- "Issued (%d)\n", ret);
+ if (0 != ret)
+ {
+ fprintf (stderr,
+ "Failed (%d)\n", ret);
+ }
+ else
+ {
+ len = GNUNET_ZKLAIM_context_serialize (ctx,
+ &data);
+ GNUNET_STRINGS_base64_encode (data,
+ len,
+ &str);
+ fprintf (stdout,
+ "%s\n", str);
+ GNUNET_free (str);
+ }
}
if (NULL == cleanup_task)
cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
}
+enum zklaim_op
+op_str_to_enum (const char* op_str)
+{
+
+ if (0 == strcmp ("<", op_str))
+ return zklaim_less;
+ else if (0 == strcmp ("<=", op_str))
+ return zklaim_less_or_eq;
+ else if (0 == strcmp ("==", op_str))
+ return zklaim_eq;
+ else if (0 == strcmp ("<=", op_str))
+ return zklaim_greater_or_eq;
+ else if (0 == strcmp ("<", op_str))
+ return zklaim_greater;
+ else if (0 == strcmp ("!=", op_str))
+ return zklaim_not_eq;
+ return zklaim_noop;
+}
+
+void
+prove_iter (void *cls,
+ const char* name,
+ enum zklaim_op *zop,
+ uint64_t *ref)
+{
+ char *tmp;
+ char *attr;
+ char *val;
+ char *op;
+ tmp = GNUNET_strdup (prove_predicate);
+ fprintf (stderr,
+ "%s\n",
+ prove_predicate);
+ attr = strtok (tmp, " ");
+ while (NULL != attr)
+ {
+ fprintf (stderr,
+ "Got %s\n", attr);
+ op = strtok (NULL, " ");
+ if (NULL == op)
+ break;
+ val = strtok (NULL, ";");
+ if (NULL == val)
+ break;
+ if (0 != strcmp (name, attr))
+ {
+ attr = strtok (NULL, " ");
+ continue;
+ }
+ *zop = op_str_to_enum (op);
+ if (1 != sscanf (val, "%lu", ref))
+ fprintf (stderr,
+ "Failed parse %s %s %s\n",
+ attr, op, val);
+ fprintf (stdout, "Setting %s %s %lu\n", name, op, *ref);
+ attr = strtok (NULL, " ");
+ }
+ GNUNET_free (tmp);
+
+}
+
static void
handle_arguments ()
{
+ struct GNUNET_ZKLAIM_Context *ctx;
+ size_t len;
+ char *data;
+ int ret;
+
timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
&timeout_task,
NULL);
NULL);
return;
}
- if (issue_attrs)
+ else if (issue_attrs)
{
zklaim_op = GNUNET_ZKLAIM_lookup_context (zklaim_handle,
context_name,
NULL);
return;
}
+ else if (prove_predicate)
+ {
+ len = GNUNET_STRINGS_base64_decode (credential,
+ strlen (credential),
+ (void**)&data);
+
+ ctx = GNUNET_ZKLAIM_context_deserialize (data,
+ len);
+ fprintf (stderr,
+ "%s\n",
+ prove_predicate);
+
+ ret = GNUNET_ZKLAIM_context_prove (ctx,
+ &prove_iter,
+ NULL);
+ fprintf (stdout,
+ "Prove result: %d\n", ret);
+ }
cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
}
NULL,
gettext_noop ("Context name"),
&context_name),
-
GNUNET_GETOPT_option_string ('A',
"attributes",
NULL,
&create),
GNUNET_GETOPT_option_string ('I',
"issue",
- gettext_noop ("Issue a credential with the given attributes and given zklaim context"),
NULL,
+ gettext_noop ("Issue a credential with the given attributes and given zklaim context"),
&issue_attrs),
+ GNUNET_GETOPT_option_string ('P',
+ "predicate",
+ NULL,
+ gettext_noop ("Predicate to prove"),
+ &prove_predicate),
+ GNUNET_GETOPT_option_string ('R',
+ "credential",
+ NULL,
+ gettext_noop ("A credential"),
+ &credential),
GNUNET_GETOPT_OPTION_END
};
if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",
iter_cls);
}
+size_t
+GNUNET_ZKLAIM_context_serialize (const struct GNUNET_ZKLAIM_Context *ctx,
+ char **buf)
+{
+ char *pos;
+ char *tmp;
+ size_t len;
+ size_t len_w;
+ size_t ret_len = 0;
+ len = zklaim_ctx_serialize (ctx->ctx,
+ (unsigned char**) &tmp);
+ ret_len += strlen (ctx->attrs) + 1 + sizeof (size_t) + len;
+ *buf = GNUNET_malloc (ret_len);
+ pos = *buf;
+ memcpy (pos, ctx->attrs, strlen (ctx->attrs) + 1);
+ pos += strlen (ctx->attrs) + 1;
+ len_w = htonl (len);
+ memcpy (pos, &len_w, sizeof (size_t));
+ pos += sizeof (size_t);
+ memcpy (pos, tmp, len);
+ GNUNET_free (tmp);
+ return ret_len;
+}
+
+
+struct GNUNET_ZKLAIM_Context *
+GNUNET_ZKLAIM_context_deserialize (char *data,
+ size_t data_len)
+{
+ struct GNUNET_ZKLAIM_Context *ctx;
+ char *pos;
+ size_t len;
+
+ ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context);
+ ctx->attrs = GNUNET_strdup (data);
+ pos = data + strlen (ctx->attrs) + 1;
+ len = ntohl (*((size_t*)pos));
+ ctx->ctx = zklaim_context_new ();
+ pos += sizeof (size_t);
+ if (0 != zklaim_ctx_deserialize (ctx->ctx,
+ (unsigned char*) pos,
+ len))
+ return NULL;
+ return ctx;
+}
+
+int
+GNUNET_ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
+ GNUNET_ZKLAIM_PredicateIterator iter,
+ void* iter_cls)
+{
+ return ZKLAIM_context_prove (ctx,
+ iter,
+ iter_cls);
+}
+
/* end of zklaim_api.c */
key);
}
-void
+int
ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
GNUNET_ZKLAIM_PredicateIterator iter,
void *iter_cls)
tmp = GNUNET_strdup (ctx->attrs);
attr_name = strtok (tmp, ",");
plw = ctx->ctx->pl_ctx_head;
-
+ fprintf (stderr,
+ "Num payloads: %lu, attrs: %s\n",
+ ctx->ctx->num_of_payloads,
+ ctx->attrs);
for (i = 0; i < ctx->ctx->num_of_payloads; i++)
{
for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
{
- GNUNET_assert (NULL != attr_name);
+ plw->pl.data_op[j] = zklaim_noop;
+ }
+ plw = plw->next;
+ }
+ plw = ctx->ctx->pl_ctx_head;
+ for (i = 0; i < ctx->ctx->num_of_payloads; i++)
+ {
+ fprintf (stderr,
+ "Payload #%d\n",
+ i);
+
+ for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
+ {
+
+ if (NULL == attr_name)
+ break;
iter (iter_cls,
- attr_name,
- &plw->pl.data_op[i],
- &plw->pl.data_ref[i]);
- attr_name = strtok (NULL, ",");
+ attr_name,
+ &plw->pl.data_op[j],
+ &plw->pl.data_ref[j]);
+ attr_name = strtok (attr_name + strlen (attr_name) + 1, ",");
}
+ if (NULL == attr_name)
+ break;
plw = plw->next;
GNUNET_assert (NULL != plw);
}
GNUNET_free (tmp);
-
+ zklaim_print (ctx->ctx);
+ return zklaim_proof_generate (ctx->ctx);
}
int