| 876 | } |
| 877 | |
| 878 | struct sphinx_compressed_onion * |
| 879 | sphinx_compressed_onion_deserialize(const tal_t *ctx, const u8 *src) |
| 880 | { |
| 881 | const u8 *cursor = src; |
| 882 | size_t max = tal_bytelen(src); |
| 883 | struct sphinx_compressed_onion *dst = |
| 884 | tal(ctx, struct sphinx_compressed_onion); |
| 885 | |
| 886 | /* This is not a compressed onion, so let's not parse it. */ |
| 887 | if (max > TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)) |
| 888 | return tal_free(dst); |
| 889 | |
| 890 | dst->version = fromwire_u8(&cursor, &max); |
| 891 | if (dst->version != 0x00) |
| 892 | return tal_free(dst); |
| 893 | |
| 894 | fromwire_pubkey(&cursor, &max, &dst->ephemeralkey); |
| 895 | dst->routinginfo = fromwire_tal_arrn(dst, &cursor, &max, max - HMAC_SIZE); |
| 896 | fromwire_hmac(&cursor, &max, &dst->hmac); |
| 897 | |
| 898 | /* If at any point we failed to pull from the serialized compressed |
| 899 | * onion the entire deserialization is considered to have failed. */ |
| 900 | if (cursor == NULL) |
| 901 | return tal_free(dst); |
| 902 | return dst; |
| 903 | } |
no test coverage detected