| 132 | } |
| 133 | |
| 134 | static void do_decode(int argc, char **argv, const u8 *assocdata) |
| 135 | { |
| 136 | const tal_t *ctx = talz(NULL, tal_t); |
| 137 | u8 *serialized; |
| 138 | struct route_step *step; |
| 139 | |
| 140 | if (argc != 4) |
| 141 | opt_usage_exit_fail("Expect an filename and privkey with 'decode' method"); |
| 142 | |
| 143 | /* "-" means stdin, which is NULL for grab_file */ |
| 144 | char *hextemp = grab_file_str(ctx, streq(argv[2], "-") ? NULL : argv[2]); |
| 145 | size_t hexlen = strlen(hextemp); |
| 146 | |
| 147 | // trim trailing whitespace |
| 148 | while (cisspace(hextemp[hexlen-1])) |
| 149 | hexlen--; |
| 150 | |
| 151 | serialized = tal_hexdata(hextemp, hextemp, hexlen); |
| 152 | if (!serialized) { |
| 153 | errx(1, "Invalid onion hex '%s'", hextemp); |
| 154 | } |
| 155 | |
| 156 | step = decode_with_privkey(ctx, serialized, tal_strdup(ctx, argv[3]), assocdata); |
| 157 | |
| 158 | if (!step || !step->next) |
| 159 | errx(1, "Error processing message."); |
| 160 | |
| 161 | printf("payload=%s\n", tal_hex(ctx, step->raw_payload)); |
| 162 | if (step->nextcase == ONION_FORWARD) { |
| 163 | u8 *ser = serialize_onionpacket(ctx, step->next); |
| 164 | if (!ser) |
| 165 | errx(1, "Error serializing message."); |
| 166 | printf("next=%s\n", tal_hex(ctx, ser)); |
| 167 | } |
| 168 | tal_free(ctx); |
| 169 | } |
| 170 | |
| 171 | static char *opt_set_ad(const char *arg, u8 **assocdata) |
| 172 | { |
no test coverage detected