bao

package
v0.0.0-...-8ec3fd9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2024 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package bao implements BLAKE3 verified streaming.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(dst io.Writer, data, outboard io.Reader, group int, root [32]byte) (bool, error)

Decode reads content and tree data from the provided reader(s), and streams the verified content to dst. It returns false if verification fails. If the content and tree data are interleaved, outboard should be nil.

func DecodeSlice

func DecodeSlice(dst io.Writer, data io.Reader, group int, offset, length uint64, root [32]byte) (bool, error)

DecodeSlice reads from data, which must contain a slice encoding for the given offset and length, and streams verified content to dst. It returns false if verification fails.

func Encode

func Encode(dst io.WriterAt, data io.Reader, dataLen int64, group int, outboard bool) ([32]byte, error)

Encode computes the intermediate BLAKE3 tree hashes of data and writes them to dst. If outboard is false, the contents of data are also written to dst, interleaved with the tree hashes. It also returns the tree root, i.e. the 256-bit BLAKE3 hash. The group parameter controls how many chunks are hashed per "group," as a power of 2; for standard Bao, use 0.

Note that dst is not written sequentially, and therefore must be initialized with sufficient capacity to hold the encoding; see EncodedSize.

func EncodeBuf

func EncodeBuf(data []byte, group int, outboard bool) ([]byte, [32]byte)

EncodeBuf returns the Bao encoding and root (i.e. BLAKE3 hash) for data.

func EncodedSize

func EncodedSize(dataLen int, group int, outboard bool) int

EncodedSize returns the size of a Bao encoding for the provided quantity of data.

func ExtractSlice

func ExtractSlice(dst io.Writer, data, outboard io.Reader, group int, offset uint64, length uint64) error

ExtractSlice returns the slice encoding for the given offset and length. When extracting from an outboard encoding, data should contain only the chunk groups that will be present in the slice.

func VerifyBuf

func VerifyBuf(data, outboard []byte, group int, root [32]byte) bool

VerifyBuf verifies the Bao encoding and root (i.e. BLAKE3 hash) for data. If the content and tree data are interleaved, outboard should be nil.

func VerifyChunk

func VerifyChunk(chunks, outboard []byte, group int, offset uint64, root [32]byte) bool

VerifyChunks verifies the provided chunks with a full outboard encoding.

func VerifySlice

func VerifySlice(data []byte, group int, offset uint64, length uint64, root [32]byte) ([]byte, bool)

VerifySlice verifies the Bao slice encoding in data, returning the verified bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL