wire: expose fromwire_fail to allow others to use it to mark failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-06-06 12:33:31 +09:30
parent a2ffccd740
commit f7bd95173d
2 changed files with 7 additions and 6 deletions

View File

@ -10,7 +10,7 @@
#include <type_to_string.h>
/* Sets *cursor to NULL and returns NULL when extraction fails. */
static const void *fail_pull(const u8 **cursor, size_t *max)
const void *fromwire_fail(const u8 **cursor, size_t *max)
{
*cursor = NULL;
*max = 0;
@ -25,7 +25,7 @@ const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n)
/* Just make sure we don't leak uninitialized mem! */
if (copy)
memset(copy, 0, n);
return fail_pull(cursor, max);
return fromwire_fail(cursor, max);
}
*cursor += n;
*max -= n;
@ -88,7 +88,7 @@ bool fromwire_bool(const u8 **cursor, size_t *max)
if (!fromwire(cursor, max, &ret, sizeof(ret)))
return false;
if (ret != 0 && ret != 1)
fail_pull(cursor, max);
fromwire_fail(cursor, max);
return ret;
}
@ -103,7 +103,7 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
* See towire_gossip_resolve_channel_reply --RR */
if (!memeqzero(der, sizeof(der))
&& !pubkey_from_der(der, sizeof(der), pubkey))
fail_pull(cursor, max);
fromwire_fail(cursor, max);
}
void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret)
@ -126,7 +126,7 @@ void fromwire_secp256k1_ecdsa_signature(const u8 **cursor,
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, sig, compact)
!= 1)
fail_pull(cursor, max);
fromwire_fail(cursor, max);
}
void fromwire_channel_id(const u8 **cursor, size_t *max,
@ -182,7 +182,7 @@ void fromwire_ipaddr(const u8 **cursor, size_t *max, struct ipaddr *addr)
addr->addrlen = 16;
break;
default:
fail_pull(cursor, max);
fromwire_fail(cursor, max);
return;
}
fromwire(cursor, max, addr->addr, addr->addrlen);

View File

@ -49,6 +49,7 @@ void derive_channel_id(struct channel_id *channel_id,
/* Read the type; returns -1 if not long enough. cursor is a tal ptr. */
int fromwire_peektype(const u8 *cursor);
const void *fromwire_fail(const u8 **cursor, size_t *max);
void towire(u8 **pptr, const void *data, size_t len);
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey);