Browse Source

json: Add helper to extract a secret from JSON

travis-debug
Christian Decker 5 years ago
parent
commit
43fb2a6ed0
  1. 6
      common/json.c
  2. 4
      common/json.h

6
common/json.c

@ -143,6 +143,12 @@ bool json_to_bool(const char *buffer, const jsmntok_t *tok, bool *b)
return false; return false;
} }
bool json_to_secret(const char *buffer, const jsmntok_t *tok, struct secret *dest)
{
return hex_decode(buffer + tok->start, tok->end - tok->start,
dest->data, sizeof(struct secret));
}
u8 *json_tok_bin_from_hex(const tal_t *ctx, const char *buffer, const jsmntok_t *tok) u8 *json_tok_bin_from_hex(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
{ {
u8 *result; u8 *result;

4
common/json.h

@ -2,6 +2,7 @@
#define LIGHTNING_COMMON_JSON_H #define LIGHTNING_COMMON_JSON_H
#include "config.h" #include "config.h"
#include <bitcoin/preimage.h> #include <bitcoin/preimage.h>
#include <bitcoin/privkey.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -49,6 +50,9 @@ bool json_to_int(const char *buffer, const jsmntok_t *tok, int *num);
/* Extract boolean from this */ /* Extract boolean from this */
bool json_to_bool(const char *buffer, const jsmntok_t *tok, bool *b); bool json_to_bool(const char *buffer, const jsmntok_t *tok, bool *b);
/* Extract a secret from this. */
bool json_to_secret(const char *buffer, const jsmntok_t *tok, struct secret *dest);
/* Is this a number? [0..9]+ */ /* Is this a number? [0..9]+ */
bool json_tok_is_num(const char *buffer, const jsmntok_t *tok); bool json_tok_is_num(const char *buffer, const jsmntok_t *tok);

Loading…
Cancel
Save