| 113 | } |
| 114 | |
| 115 | int main(int argc, char *argv[]) |
| 116 | { |
| 117 | char *json; |
| 118 | size_t i; |
| 119 | jsmn_parser parser; |
| 120 | jsmntok_t toks[5000]; |
| 121 | const jsmntok_t *t, *generate_tok; |
| 122 | struct sphinx_path *sp; |
| 123 | struct secret session_key; |
| 124 | struct onionpacket *op; |
| 125 | u8 *assoc_data, *expected, *actual; |
| 126 | struct secret *unused_path_secrets; |
| 127 | u8 *payloads[5]; |
| 128 | |
| 129 | common_setup(argv[0]); |
| 130 | |
| 131 | if (argv[1]) |
| 132 | json = grab_file(tmpctx, argv[1]); |
| 133 | else { |
| 134 | char *dir = getenv("BOLTDIR"); |
| 135 | json = grab_file(tmpctx, |
| 136 | path_join(tmpctx, |
| 137 | dir ? dir : "../bolts", |
| 138 | "bolt04/onion-test.json")); |
| 139 | if (!json) { |
| 140 | printf("test file not found, skipping\n"); |
| 141 | goto out; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | jsmn_init(&parser); |
| 146 | if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0) |
| 147 | abort(); |
| 148 | |
| 149 | generate_tok = json_get_member(json, toks, "generate"); |
| 150 | json_to_secret(json, json_get_member(json, generate_tok, "session_key"), &session_key); |
| 151 | assoc_data = json_tok_bin_from_hex(tmpctx, json, json_get_member(json, generate_tok, "associated_data")); |
| 152 | sp = sphinx_path_new_with_key(tmpctx, assoc_data, &session_key); |
| 153 | json_for_each_arr(i, t, json_get_member(json, generate_tok, "hops")) { |
| 154 | struct pubkey k; |
| 155 | const u8 *cursor; |
| 156 | size_t max, len; |
| 157 | |
| 158 | json_to_pubkey(json, json_get_member(json, t, "pubkey"), &k); |
| 159 | payloads[i] = json_tok_bin_from_hex(NULL, json, json_get_member(json, t, "payload")); |
| 160 | /* First byte(s) are length: check and remove them for our API. */ |
| 161 | cursor = payloads[i]; |
| 162 | max = tal_bytelen(payloads[i]); |
| 163 | len = fromwire_bigsize(&cursor, &max); |
| 164 | assert(len == max); |
| 165 | sphinx_add_hop(sp, &k, take(tal_dup_arr(NULL, u8, cursor, max, 0))); |
| 166 | } |
| 167 | assert(i == ARRAY_SIZE(payloads)); |
| 168 | |
| 169 | op = create_onionpacket(tmpctx, sp, ROUTING_INFO_SIZE, &unused_path_secrets); |
| 170 | |
| 171 | expected = json_tok_bin_from_hex(tmpctx, json, json_get_member(json, toks, "onion")); |
| 172 | actual = serialize_onionpacket(tmpctx, op); |
nothing calls this directly
no test coverage detected