예제 #1
0
def slices():
    ret = []
    for case in seeks():
        size = case["input_len"]
        offsets = case["seek_offsets"]
        b = input_bytes(size)
        encoded = bao.bao_encode(b)
        slices = []
        for offset in offsets:
            slice_bytes = io.BytesIO()
            slice_len = 2 * CHUNK_SIZE
            bao.bao_slice(io.BytesIO(encoded), slice_bytes, offset, slice_len)
            slice_hash = blake2b_hash(slice_bytes.getbuffer())
            fields = [
                ("start", offset),
                ("len", slice_len),
                ("output_len", len(slice_bytes.getbuffer())),
                ("output_blake2b", slice_hash),
                ("corruptions",
                 slice_corruption_points(size, offset, slice_len)),
            ]
            slices.append(OrderedDict(fields))
        fields = [
            ("input_len", size),
            ("bao_hash", bao.bao_hash(io.BytesIO(b)).hex()),
            ("slices", slices),
        ]
        ret.append(OrderedDict(fields))
    return ret
예제 #2
0
def encoded():
    ret = []
    for size in SIZES:
        b = input_bytes(size)
        encoded = bao.bao_encode(b)
        fields = [
            ("input_len", size),
            ("output_len", len(encoded)),
            ("bao_hash", bao.bao_hash(io.BytesIO(b)).hex()),
            ("encoded_blake2b", blake2b_hash(encoded)),
            ("corruptions", encode_corruption_points(size)),
        ]
        ret.append(OrderedDict(fields))
    return ret
예제 #3
0
def outboard():
    ret = []
    for size in SIZES:
        b = input_bytes(size)
        encoded = bao.bao_encode(b, outboard=True)
        input_corruptions = []
        corruption = 0
        while corruption < size:
            input_corruptions.append(corruption)
            corruption += CHUNK_SIZE
        fields = [
            ("input_len", size),
            ("output_len", len(encoded)),
            ("bao_hash", bao.bao_hash(io.BytesIO(b)).hex()),
            ("encoded_blake2b", blake2b_hash(encoded)),
            ("outboard_corruptions",
             encode_corruption_points(size, outboard=True)),
            ("input_corruptions", input_corruptions),
        ]
        ret.append(OrderedDict(fields))
    return ret
예제 #4
0
파일: test_bao.py 프로젝트: pombredanne/bao
def bao_encode_outboard(content):
    # Note that unlike the other functions, this one already takes bytes.
    return bao.bao_encode(content, outboard=True)
예제 #5
0
def bao_encode(content):
    # Note that unlike the other functions, this one already takes bytes.
    encoded, hash_ = bao.bao_encode(content, outboard=False)
    return encoded, hash_.hex()