Documentation ¶
Overview ¶
Package merkle stores resources as Merkle Trees. It should provide security for data at rest, protecting both the data and the meta-data while storing the information in a way that makes it easy to fulfil request for partial resources with validation.
Index ¶
- Constants
- type Forest
- func (f *Forest) BuildTree(r io.Reader) (*Tree, error)
- func (f *Forest) Close()
- func (f *Forest) First(bucket []byte) ([]byte, []byte, error)
- func (f *Forest) GetTree(d *crypto.Digest) *Tree
- func (f *Forest) GetValue(bucket, key []byte) ([]byte, error)
- func (f *Forest) MakeBuckets(bkts ...[]byte) error
- func (f *Forest) New(d *crypto.Digest, l uint32) *Tree
- func (f *Forest) Next(bucket, searchKey []byte) ([]byte, []byte, error)
- func (f *Forest) SetValue(bucket, key, value []byte) error
- type Tree
- func (t *Tree) AddLeaf(vc ValidationChain, leaf []byte, lIdx int)
- func (t *Tree) Complete() bool
- func (t *Tree) Digest() *crypto.Digest
- func (t *Tree) GetLeaf(lIdx int) (ValidationChain, []byte, error)
- func (t *Tree) Len() int
- func (t *Tree) Read(p []byte) (int, error)
- func (t *Tree) ReadAll() ([]byte, error)
- func (t *Tree) Seek(offset int64, whence int) (int64, error)
- func (t *Tree) ValidateLeaf(vc ValidationChain, leaf []byte, lIdx int) bool
- type ValidationChain
Constants ¶
const BlockSize = 8112
BlockSize is the size of each leaf. The encryption adds about 40 bytes. Most disks have a physical sector size of 4096. The block size is designed to use 2 sectors per leaf, a compromize between current effiency and future- proofing. There's also 40 bytes extra (double the encryption overhead) to ensure that it doesn't go over and require a 3rd sector.
const ErrBadWhence = errors.String("Bad whence value")
ErrBadWhence is returned if the whence value given to Seek is unknown
const ErrBucketDoesNotExist = errors.String("Bucket does not exist")
ErrBucketDoesNotExist is returned when trying to read from a bucket that does not exist.
const ErrIncomplete = errors.String("Tree is incomplete")
ErrIncomplete is returned when trying to perform an operation limited to a complete Tree (Read or ReadAll). Check if the Tree is complete with Tree.Complete()
const ErrNegativeOffset = errors.String("Attempting to Seek to negative offset")
ErrNegativeOffset is returned if the result of a seek would set the tree offset position to a negative value.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Forest ¶
type Forest struct {
// contains filtered or unexported fields
}
Forest is a directory used to store Merkle Trees. A Forest has a symmetric encryption key that is used to secure the data. It also has a Bolt DB file to store structural information (branches and roots).
func (*Forest) BuildTree ¶
BuildTree takes a reader and saves the data read from it to a Merkle tree in the Forest.
func (*Forest) Close ¶
func (f *Forest) Close()
Close will close a Forest, specifically, it will close the Bolt DB and directory.
func (*Forest) GetTree ¶
GetTree will return a Tree from a Forest. It is only a reference to the Tree, not the data in the tree. If the tree is not found, it will return nil.
func (*Forest) GetValue ¶
GetValue returns a single value from the Bolt Database stored with SetValue. It does not use the Merkle tree structure, but provides a simple method to store secure information in the same container as the trees
func (*Forest) MakeBuckets ¶
MakeBuckets takes a list of buckets and calls CreateBucketIfNotExists on each of them.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is how a resource is stored. It represents the top level digest of a Merkle tree.
func (*Tree) AddLeaf ¶
func (t *Tree) AddLeaf(vc ValidationChain, leaf []byte, lIdx int)
AddLeaf will add a validated leaf to a Sapling.
func (*Tree) Digest ¶
Digest gives the Digest that identifies the tree. This can be used to request the tree from a forest.
func (*Tree) GetLeaf ¶
func (t *Tree) GetLeaf(lIdx int) (ValidationChain, []byte, error)
GetLeaf returns the ValidationChain and Leaf for a tree.
func (*Tree) Read ¶
Read implements the io.Reader interface to allow a tree to be read into a byte slice
func (*Tree) ValidateLeaf ¶
func (t *Tree) ValidateLeaf(vc ValidationChain, leaf []byte, lIdx int) bool
ValidateLeaf uses a ValidationChain to confirm that a leaf belongs to a tree
type ValidationChain ¶
ValidationChain is used to validate that a leaf belongs to a tree. It includes all the Uncle digests.