| 954 | } |
| 955 | |
| 956 | struct sphinx_compressed_onion * |
| 957 | sphinx_compressed_onion_deserialize(const tal_t *ctx, const u8 *src) |
| 958 | { |
| 959 | const u8 *cursor = src; |
| 960 | size_t max = tal_bytelen(src); |
| 961 | struct sphinx_compressed_onion *dst = |
| 962 | tal(ctx, struct sphinx_compressed_onion); |
| 963 | |
| 964 | /* This is not a compressed onion, so let's not parse it. */ |
| 965 | if (max > TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)) |
| 966 | return tal_free(dst); |
| 967 | |
| 968 | dst->version = fromwire_u8(&cursor, &max); |
| 969 | if (dst->version != 0x00) |
| 970 | return tal_free(dst); |
| 971 | |
| 972 | fromwire_pubkey(&cursor, &max, &dst->ephemeralkey); |
| 973 | dst->routinginfo = fromwire_tal_arrn(dst, &cursor, &max, max - HMAC_SIZE); |
| 974 | fromwire_hmac(&cursor, &max, &dst->hmac); |
| 975 | |
| 976 | /* If at any point we failed to pull from the serialized compressed |
| 977 | * onion the entire deserialization is considered to have failed. */ |
| 978 | if (cursor == NULL) |
| 979 | return tal_free(dst); |
| 980 | return dst; |
| 981 | } |
no test coverage detected