| 988 | } |
| 989 | |
| 990 | struct sphinx_compressed_onion * |
| 991 | sphinx_compressed_onion_deserialize(const tal_t *ctx, const u8 *src) |
| 992 | { |
| 993 | const u8 *cursor = src; |
| 994 | size_t max = tal_bytelen(src); |
| 995 | struct sphinx_compressed_onion *dst = |
| 996 | tal(ctx, struct sphinx_compressed_onion); |
| 997 | |
| 998 | /* This is not a compressed onion, so let's not parse it. */ |
| 999 | if (max > TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)) |
| 1000 | return tal_free(dst); |
| 1001 | |
| 1002 | dst->version = fromwire_u8(&cursor, &max); |
| 1003 | if (dst->version != 0x00) |
| 1004 | return tal_free(dst); |
| 1005 | |
| 1006 | fromwire_pubkey(&cursor, &max, &dst->ephemeralkey); |
| 1007 | dst->routinginfo = fromwire_tal_arrn(dst, &cursor, &max, max - HMAC_SIZE); |
| 1008 | fromwire_hmac(&cursor, &max, &dst->hmac); |
| 1009 | |
| 1010 | /* If at any point we failed to pull from the serialized compressed |
| 1011 | * onion the entire deserialization is considered to have failed. */ |
| 1012 | if (cursor == NULL) |
| 1013 | return tal_free(dst); |
| 1014 | return dst; |
| 1015 | } |
no test coverage detected