BIP-0174: * := * := * := */
| 70 | * <value> := <valuelen> <valuedata> |
| 71 | */ |
| 72 | static struct keypair *fromwire_keypair(const tal_t *ctx, |
| 73 | const u8 **cursor, |
| 74 | size_t *max) |
| 75 | { |
| 76 | struct keypair *kp = tal(ctx, struct keypair); |
| 77 | u64 len; |
| 78 | size_t keylen; |
| 79 | |
| 80 | /* 0 byte terminates */ |
| 81 | len = fromwire_compact_len(cursor, max); |
| 82 | if (len == 0) |
| 83 | return tal_free(kp); |
| 84 | |
| 85 | kp->keytype = fromwire_compact_size(cursor, max); |
| 86 | /* Sanity check */ |
| 87 | if (compact_size_len(kp->keytype) > len) |
| 88 | return tal_free(kp); |
| 89 | keylen = len - compact_size_len(kp->keytype); |
| 90 | kp->key = tal_arr(kp, u8, keylen); |
| 91 | fromwire_u8_array(cursor, max, kp->key, keylen); |
| 92 | |
| 93 | len = fromwire_compact_len(cursor, max); |
| 94 | kp->value = tal_arr(kp, u8, len); |
| 95 | fromwire_u8_array(cursor, max, kp->value, len); |
| 96 | return kp; |
| 97 | } |
| 98 | |
| 99 | static void towire_compact_size(u8 **pptr, u64 v) |
| 100 | { |
no test coverage detected