github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/hash/identity.go (about)

     1  // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
     2  //
     3  // Copyright 2020 Stafi Protocol
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package hash
    18  
    19  import (
    20  	"hash"
    21  )
    22  
    23  type identity struct {
    24  	data []byte
    25  }
    26  
    27  func NewIdentity(b []byte) hash.Hash {
    28  	return &identity{data: b}
    29  }
    30  
    31  // Write (via the embedded io.Writer interface) adds more data to the running hash.
    32  // It never returns an error.
    33  func (i *identity) Write(p []byte) (n int, err error) {
    34  	i.data = append(i.data, p...)
    35  	return len(p), nil
    36  }
    37  
    38  // Sum appends the current hash to b and returns the resulting slice.
    39  // It does not change the underlying hash state.
    40  func (i *identity) Sum(b []byte) []byte {
    41  	return append(b, i.data...)
    42  }
    43  
    44  // Reset resets the Hash to its initial state.
    45  func (i *identity) Reset() {
    46  	i.data = make([]byte, 0)
    47  }
    48  
    49  // Size returns the number of bytes Sum will return.
    50  func (i *identity) Size() int {
    51  	return len(i.Sum(nil))
    52  }
    53  
    54  // BlockSize returns the hash's underlying block size.
    55  // The Write method must be able to accept any amount
    56  // of data, but it may operate more efficiently if all writes
    57  // are a multiple of the block size.
    58  func (i *identity) BlockSize() int {
    59  	return 0
    60  }