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.c162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/lib/json/json_helper.c b/src/lib/json/json_helper.c
index b6965e080..cae26aef4 100644
--- a/src/lib/json/json_helper.c
+++ b/src/lib/json/json_helper.c
@@ -26,6 +26,7 @@
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_json_lib.h" 28#include "gnunet_json_lib.h"
29#include <gnunet/gnunet_common.h>
29 30
30 31
31struct GNUNET_JSON_Specification 32struct GNUNET_JSON_Specification
@@ -42,6 +43,29 @@ GNUNET_JSON_spec_end ()
42 43
43 44
44/** 45/**
46 * Convert string value to numeric cipher value.
47 *
48 * @param cipher_s input string
49 * @return numeric cipher value
50 */
51static enum GNUNET_CRYPTO_BlindSignatureAlgorithm
52string_to_cipher (const char *cipher_s)
53{
54 if ((0 == strcasecmp (cipher_s,
55 "RSA")) ||
56 (0 == strcasecmp (cipher_s,
57 "RSA+age_restricted")))
58 return GNUNET_CRYPTO_BSA_RSA;
59 if ((0 == strcasecmp (cipher_s,
60 "CS")) ||
61 (0 == strcasecmp (cipher_s,
62 "CS+age_restricted")))
63 return GNUNET_CRYPTO_BSA_CS;
64 return GNUNET_CRYPTO_BSA_INVALID;
65}
66
67
68/**
45 * Parse given JSON object to fixed size data 69 * Parse given JSON object to fixed size data
46 * 70 *
47 * @param cls closure, NULL 71 * @param cls closure, NULL
@@ -1180,4 +1204,142 @@ GNUNET_JSON_spec_boolean (const char *name,
1180} 1204}
1181 1205
1182 1206
1207/**
1208 * Parse given JSON object to a blinded message.
1209 *
1210 * @param cls closure, NULL
1211 * @param root the json object representing data
1212 * @param[out] spec where to write the data
1213 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
1214 */
1215static enum GNUNET_GenericReturnValue
1216parse_blinded_message (void *cls,
1217 json_t *root,
1218 struct GNUNET_JSON_Specification *spec)
1219{
1220 struct GNUNET_CRYPTO_BlindedMessage **target = spec->ptr;
1221 struct GNUNET_CRYPTO_BlindedMessage *blinded_message;
1222 const char *cipher;
1223 struct GNUNET_JSON_Specification dspec[] = {
1224 GNUNET_JSON_spec_string ("cipher",
1225 &cipher),
1226 GNUNET_JSON_spec_end ()
1227 };
1228 const char *emsg;
1229 unsigned int eline;
1230
1231 (void) cls;
1232 if (GNUNET_OK !=
1233 GNUNET_JSON_parse (root,
1234 dspec,
1235 &emsg,
1236 &eline))
1237 {
1238 GNUNET_break_op (0);
1239 return GNUNET_SYSERR;
1240 }
1241 blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
1242 blinded_message->rc = 1;
1243 blinded_message->cipher = string_to_cipher (cipher);
1244 switch (blinded_message->cipher)
1245 {
1246 case GNUNET_CRYPTO_BSA_INVALID:
1247 break;
1248 case GNUNET_CRYPTO_BSA_RSA:
1249 {
1250 struct GNUNET_JSON_Specification ispec[] = {
1251 GNUNET_JSON_spec_varsize (
1252 "rsa_blinded_planchet",
1253 &blinded_message->details.rsa_blinded_message.blinded_msg,
1254 &blinded_message->details.rsa_blinded_message.blinded_msg_size),
1255 GNUNET_JSON_spec_end ()
1256 };
1257
1258 if (GNUNET_OK !=
1259 GNUNET_JSON_parse (root,
1260 ispec,
1261 &emsg,
1262 &eline))
1263 {
1264 GNUNET_break_op (0);
1265 GNUNET_free (blinded_message);
1266 return GNUNET_SYSERR;
1267 }
1268 *target = blinded_message;
1269 return GNUNET_OK;
1270 }
1271 case GNUNET_CRYPTO_BSA_CS:
1272 {
1273 struct GNUNET_JSON_Specification ispec[] = {
1274 GNUNET_JSON_spec_fixed_auto (
1275 "cs_nonce",
1276 &blinded_message->details.cs_blinded_message.nonce),
1277 GNUNET_JSON_spec_fixed_auto (
1278 "cs_blinded_c0",
1279 &blinded_message->details.cs_blinded_message.c[0]),
1280 GNUNET_JSON_spec_fixed_auto (
1281 "cs_blinded_c1",
1282 &blinded_message->details.cs_blinded_message.c[1]),
1283 GNUNET_JSON_spec_end ()
1284 };
1285
1286 if (GNUNET_OK !=
1287 GNUNET_JSON_parse (root,
1288 ispec,
1289 &emsg,
1290 &eline))
1291 {
1292 GNUNET_break_op (0);
1293 GNUNET_free (blinded_message);
1294 return GNUNET_SYSERR;
1295 }
1296 *target = blinded_message;
1297 return GNUNET_OK;
1298 }
1299 }
1300 GNUNET_break_op (0);
1301 GNUNET_free (blinded_message);
1302 return GNUNET_SYSERR;
1303}
1304
1305/**
1306 * Cleanup data left from parsing blinded message.
1307 *
1308 * @param cls closure, NULL
1309 * @param[out] spec where to free the data
1310 */
1311static void
1312clean_blinded_message (void *cls,
1313 struct GNUNET_JSON_Specification *spec)
1314{
1315 struct GNUNET_CRYPTO_BlindedMessage **blinded_message = spec->ptr;
1316
1317 (void) cls;
1318 if (NULL != blinded_message)
1319 {
1320 GNUNET_CRYPTO_blinded_message_decref (*blinded_message);
1321 *blinded_message = NULL;
1322 }
1323}
1324
1325
1326struct GNUNET_JSON_Specification
1327GNUNET_JSON_spec_blinded_message (const char *name,
1328 struct GNUNET_CRYPTO_BlindedMessage **msg)
1329{
1330 struct GNUNET_JSON_Specification ret = {
1331 .parser = &parse_blinded_message,
1332 .cleaner = &clean_blinded_message,
1333 .cls = NULL,
1334 .field = name,
1335 .ptr = msg,
1336 .ptr_size = 0,
1337 .size_ptr = NULL
1338 };
1339
1340 *msg = NULL;
1341 return ret;
1342}
1343
1344
1183/* end of json_helper.c */ 1345/* end of json_helper.c */