aboutsummaryrefslogtreecommitdiff
path: root/src/lib/json/json_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/json/json_helper.c')
-rw-r--r--src/lib/json/json_helper.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/lib/json/json_helper.c b/src/lib/json/json_helper.c
index ce73fb316..dfe4ad025 100644
--- a/src/lib/json/json_helper.c
+++ b/src/lib/json/json_helper.c
@@ -1344,4 +1344,137 @@ GNUNET_JSON_spec_blinded_message (const char *name,
1344} 1344}
1345 1345
1346 1346
1347/**
1348 * Parse given JSON object to unblinded signature.
1349 *
1350 * @param cls closure, NULL
1351 * @param root the json object representing data
1352 * @param[out] spec where to write the data
1353 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
1354 */
1355static enum GNUNET_GenericReturnValue
1356parse_unblinded_sig (void *cls,
1357 json_t *root,
1358 struct GNUNET_JSON_Specification *spec)
1359{
1360 struct GNUNET_CRYPTO_UnblindedSignature **target = spec->ptr;
1361 struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
1362 const char *cipher;
1363 struct GNUNET_JSON_Specification dspec[] = {
1364 GNUNET_JSON_spec_string ("cipher",
1365 &cipher),
1366 GNUNET_JSON_spec_end ()
1367 };
1368 const char *emsg;
1369 unsigned int eline;
1370
1371 (void) cls;
1372 if (GNUNET_OK !=
1373 GNUNET_JSON_parse (root,
1374 dspec,
1375 &emsg,
1376 &eline))
1377 {
1378 GNUNET_break_op (0);
1379 return GNUNET_SYSERR;
1380 }
1381 unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
1382 unblinded_sig->cipher = string_to_cipher (cipher);
1383 unblinded_sig->rc = 1;
1384 switch (unblinded_sig->cipher)
1385 {
1386 case GNUNET_CRYPTO_BSA_INVALID:
1387 break;
1388 case GNUNET_CRYPTO_BSA_RSA:
1389 {
1390 struct GNUNET_JSON_Specification ispec[] = {
1391 GNUNET_JSON_spec_rsa_signature (
1392 "rsa_signature",
1393 &unblinded_sig->details.rsa_signature),
1394 GNUNET_JSON_spec_end ()
1395 };
1396
1397 if (GNUNET_OK !=
1398 GNUNET_JSON_parse (root,
1399 ispec,
1400 &emsg,
1401 &eline))
1402 {
1403 GNUNET_break_op (0);
1404 GNUNET_free (unblinded_sig);
1405 return GNUNET_SYSERR;
1406 }
1407 *target = unblinded_sig;
1408 return GNUNET_OK;
1409 }
1410 case GNUNET_CRYPTO_BSA_CS:
1411 {
1412 struct GNUNET_JSON_Specification ispec[] = {
1413 GNUNET_JSON_spec_fixed_auto ("cs_signature_r",
1414 &unblinded_sig->details.cs_signature.
1415 r_point),
1416 GNUNET_JSON_spec_fixed_auto ("cs_signature_s",
1417 &unblinded_sig->details.cs_signature.
1418 s_scalar),
1419 GNUNET_JSON_spec_end ()
1420 };
1421
1422 if (GNUNET_OK !=
1423 GNUNET_JSON_parse (root,
1424 ispec,
1425 &emsg,
1426 &eline))
1427 {
1428 GNUNET_break_op (0);
1429 GNUNET_free (unblinded_sig);
1430 return GNUNET_SYSERR;
1431 }
1432 *target = unblinded_sig;
1433 return GNUNET_OK;
1434 }
1435 }
1436 GNUNET_break_op (0);
1437 GNUNET_free (unblinded_sig);
1438 return GNUNET_SYSERR;
1439}
1440
1441
1442/**
1443 * Cleanup data left from parsing unblinded signature.
1444 *
1445 * @param cls closure, NULL
1446 * @param[out] spec where to free the data
1447 */
1448static void
1449clean_unblinded_sig (void *cls,
1450 struct GNUNET_JSON_Specification *spec)
1451{
1452 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = spec->ptr;
1453
1454 (void) cls;
1455 if (NULL != *ub_sig)
1456 {
1457 GNUNET_CRYPTO_unblinded_sig_decref (*ub_sig);
1458 *ub_sig = NULL;
1459 }
1460}
1461
1462
1463struct GNUNET_JSON_Specification
1464GNUNET_JSON_spec_unblinded_signature (const char *field,
1465 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
1466{
1467 struct GNUNET_JSON_Specification ret = {
1468 .parser = &parse_unblinded_sig,
1469 .cleaner = &clean_unblinded_sig,
1470 .field = field,
1471 .ptr = ub_sig
1472 };
1473
1474 *ub_sig = NULL;
1475 return ret;
1476}
1477
1478
1479
1347/* end of json_helper.c */ 1480/* end of json_helper.c */