mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove CheckSum from utils; replace with a TeeReader
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
parent
c18b38f912
commit
ef6b78f7db
2 changed files with 3 additions and 26 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
_ "crypto/sha512"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -642,7 +643,7 @@ func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registr
|
|||
h := sha256.New()
|
||||
h.Write(jsonRaw)
|
||||
h.Write([]byte{'\n'})
|
||||
checksumLayer := &utils.CheckSum{Reader: tarsumLayer, Hash: h}
|
||||
checksumLayer := io.TeeReader(tarsumLayer, h)
|
||||
|
||||
req, err := r.reqFactory.NewRequest("PUT", registry+"images/"+imgID+"/layer", checksumLayer)
|
||||
if err != nil {
|
||||
|
@ -671,7 +672,7 @@ func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registr
|
|||
return "", "", utils.NewHTTPRequestError(fmt.Sprintf("Received HTTP code %d while uploading layer: %s", res.StatusCode, errBody), res)
|
||||
}
|
||||
|
||||
checksumPayload = "sha256:" + checksumLayer.Sum()
|
||||
checksumPayload = "sha256:" + hex.EncodeToString(h.Sum(nil))
|
||||
return tarsumLayer.Sum(jsonRaw), checksumPayload, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"hash"
|
||||
"io"
|
||||
)
|
||||
|
||||
type CheckSum struct {
|
||||
io.Reader
|
||||
Hash hash.Hash
|
||||
}
|
||||
|
||||
func (cs *CheckSum) Read(buf []byte) (int, error) {
|
||||
n, err := cs.Reader.Read(buf)
|
||||
if err == nil {
|
||||
cs.Hash.Write(buf[:n])
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (cs *CheckSum) Sum() string {
|
||||
return hex.EncodeToString(cs.Hash.Sum(nil))
|
||||
}
|
Loading…
Add table
Reference in a new issue