If @elements is non-NULL it must hold at least as many slots as the * stack claims. A failure may have written a prefix; ignore it. */
| 37 | /* If @elements is non-NULL it must hold at least as many slots as the |
| 38 | * stack claims. A failure may have written a prefix; ignore it. */ |
| 39 | static bool parse_witness_stack(const u8 *witness, size_t *num_items, |
| 40 | struct witness_element *elements) |
| 41 | { |
| 42 | const u8 *cursor = witness; |
| 43 | size_t max = tal_bytelen(witness); |
| 44 | size_t n, item_len; |
| 45 | |
| 46 | if (!next_size(&cursor, &max, &n)) |
| 47 | return false; |
| 48 | |
| 49 | for (size_t i = 0; i < n; i++) { |
| 50 | if (!next_size(&cursor, &max, &item_len)) |
| 51 | return false; |
| 52 | if (max < item_len) |
| 53 | return false; |
| 54 | if (elements) { |
| 55 | elements[i].data = cursor; |
| 56 | elements[i].len = item_len; |
| 57 | } |
| 58 | cursor += item_len; |
| 59 | max -= item_len; |
| 60 | } |
| 61 | |
| 62 | /* Encoding ends here; anything left is not a witness. */ |
| 63 | if (max != 0) |
| 64 | return false; |
| 65 | |
| 66 | *num_items = n; |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | bool witness_stack_items(const u8 *witness, size_t *num_items) |
| 71 | { |
no test coverage detected