Skip to Content
oxcrypto
HashesProtocol compatibility

Bao

Encode, verify and slice BLAKE3 content with the experimental Bao format.

Warning

Experimental: Bao is defined by the Bao specification, not by a standards body. oxcrypto wraps the bao crate 0.13.1, which its author describes as beta software that has not been formally audited (no published audit). It declares no rust-version; oxcrypto builds it with Rust 1.88.

encode and outboard return the encoding and the 32-byte root hash, which equals the BLAKE3 digest of the content. decode, decode_outboard and decode_slice check the input against the root hash and raise ValueError for a hash mismatch or truncated input; they never return partly checked content. extract_slice and extract_slice_outboard copy the parts of an encoding needed for a content range without checking them; the receiver checks the slice with decode_slice and the same start and length. Bytes after the end of a combined encoding or slice are ignored; decode_outboard raises ValueError when data is longer than the content the outboard tree covers. Bao takes no key, so it holds no secret state.

new returns a BaoEncoder that takes the content in chunks: update(data) adds a chunk, finalize() returns the same result as encode (or outboard with outboard=True), copy() forks the state and reset() starts over. The encoding is kept in memory until finalize.

Important

finalize can be called once. After it, update and finalize raise ValueError until reset. Encoders can be shared between threads but are not meant for concurrent use.

Example

from oxcrypto.hash.bao import BAO

algorithm = BAO.BAO
data = b"hello" * 1000
encoded, root = algorithm.encode(data)
assert algorithm.decode(encoded, root) == data
piece = algorithm.extract_slice(encoded, start=1024, length=10)
assert algorithm.decode_slice(piece, root, start=1024, length=10) == data[1024:1034]

encoder = algorithm.new()
for chunk in (data[:2000], data[2000:]):
    encoder.update(chunk)
assert encoder.finalize() == (encoded, root)

Variants

  • BAO.BAO

Methods

new(self, *, outboard: bool=False) -> BaoEncoder
encode(self, data: bytes, /) -> tuple[bytes, bytes]
outboard(self, data: bytes, /) -> tuple[bytes, bytes]
decode(self, encoded: bytes, hash: bytes, /) -> bytes
decode_outboard(self, data: bytes, outboard: bytes, hash: bytes, /) -> bytes
extract_slice(self, encoded: bytes, /, *, start: int, length: int) -> bytes
extract_slice_outboard(self, data: bytes, outboard: bytes, /, *, start: int, length: int) -> bytes
decode_slice(self, slice: bytes, hash: bytes, /, *, start: int, length: int) -> bytes
BaoEncoder.update(self, data: bytes, /) -> None
BaoEncoder.copy(self) -> BaoEncoder
BaoEncoder.finalize(self) -> tuple[bytes, bytes]
BaoEncoder.reset(self) -> None

On this page