Initial commit

This commit is contained in:
Ian Gulliver
2023-04-20 17:54:42 +00:00
parent 57736da893
commit cb9d3aef62
10 changed files with 565 additions and 0 deletions

30
bodyintercept.go Normal file
View File

@@ -0,0 +1,30 @@
package potency
import (
"crypto/sha256"
"hash"
"io"
)
type bodyIntercept struct {
source io.ReadCloser
sha256 hash.Hash
}
func newBodyIntercept(source io.ReadCloser) *bodyIntercept {
return &bodyIntercept{
source: source,
sha256: sha256.New(),
}
}
func (bi *bodyIntercept) Read(p []byte) (int, error) {
numBytes, err := bi.source.Read(p)
bi.sha256.Write(p[:numBytes])
return numBytes, err
}
func (bi *bodyIntercept) Close() error {
return bi.source.Close()
}