github.com/braveheart12/insolar-09-08-19@v0.8.7/platformpolicy/internal/hash/wrapper.go (about) 1 /* 2 * Copyright 2019 Insolar Technologies 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package hash 18 19 import ( 20 "hash" 21 ) 22 23 type hashWrapper struct { 24 hash hash.Hash 25 sumFunc func([]byte) []byte 26 } 27 28 func (h *hashWrapper) Write(p []byte) (n int, err error) { 29 return h.hash.Write(p) 30 } 31 32 func (h *hashWrapper) Sum(b []byte) []byte { 33 return h.hash.Sum(b) 34 } 35 36 func (h *hashWrapper) Reset() { 37 h.hash.Reset() 38 } 39 40 func (h *hashWrapper) Size() int { 41 return h.hash.Size() 42 } 43 44 func (h *hashWrapper) BlockSize() int { 45 return h.hash.BlockSize() 46 } 47 48 func (h *hashWrapper) Hash(b []byte) []byte { 49 return h.sumFunc(b)[:] 50 }