Added json_tok_sha256 (#1779)

Added json_tok_sha256

Converted json_tok_tok over a few places.

[ Folded: fixed spacing ]
Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
Mark Beckwith
2018-07-30 23:11:01 -05:00
committed by Rusty Russell
parent d3edfc8028
commit 1fca7ab562
5 changed files with 17 additions and 36 deletions

View File

@@ -96,24 +96,13 @@ static void json_rhash(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
struct json_result *response = new_json_result(cmd);
const jsmntok_t *secrettok;
struct sha256 secret;
if (!param(cmd, buffer, params,
p_req("secret", json_tok_tok, &secrettok),
p_req("secret", json_tok_sha256, &secret),
NULL))
return;
if (!hex_decode(buffer + secrettok->start,
secrettok->end - secrettok->start,
&secret, sizeof(secret))) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%.*s' is not a valid 32-byte hex value",
secrettok->end - secrettok->start,
buffer + secrettok->start);
return;
}
/* Hash in place. */
sha256(&secret, &secret, sizeof(secret));
json_object_start(response, NULL);