1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/python3
# ./swap_content.py <encoded_file>
#
# Reads input from stdin and replaces the content (but not the hashes!) of the
# encoded file with the stdin bytes. If stdin is shorter than the content, the
# remaining content bytes are unmodified. If stdin is longer, only the input up
# to the length of the encoded content is used. Either way, the encoded file
# length is unchanged.
#
# This tool is used to construct corrupted Bao encodings, for testing and
# demos. Normally any difference between two inputs would result in a different
# root node, so a decoder reading the wrong file will abort immediately with no
# output. However, it's possible that corruption in the tree only shows up
# halfway through, and in that case the decoder can emit valid output before
# encountering the corruption and aborting.
# We might get fewer input bytes than requested, if the input stream is
# finished. That's fine. All the writes after that point will be empty,
# and the rest of the tree will be left as is.
=
# Read past the parent node and then recurse to the children.
=
=
=