github.com/ethersphere/bee/v2@v2.2.0/pkg/bmt/interface.go (about)

     1  // Copyright 2021 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package bmt
     6  
     7  import (
     8  	"hash"
     9  )
    10  
    11  const (
    12  	SpanSize = 8
    13  )
    14  
    15  // Hash provides the necessary extension of the hash interface to add the length-prefix of the BMT hash.
    16  //
    17  // Any implementation should make it possible to generate a BMT hash using the hash.Hash interface only.
    18  // However, the limitation will be that the Span of the BMT hash always must be limited to the amount of bytes actually written.
    19  type Hash interface {
    20  	hash.Hash
    21  
    22  	// SetHeaderInt64 sets the header bytes of BMT hash to the little endian binary representation of the int64 argument.
    23  	SetHeaderInt64(int64)
    24  
    25  	// SetHeader sets the header bytes of BMT hash by copying the first 8 bytes of the argument.
    26  	SetHeader([]byte)
    27  
    28  	// Hash calculates the BMT hash of the buffer written so far and appends it to the argument
    29  	Hash([]byte) ([]byte, error)
    30  
    31  	// Capacity returns the maximum amount of bytes that will be processed by the implementation.
    32  	Capacity() int
    33  }