You've already forked go-digest
mirror of
https://github.com/opencontainers/go-digest.git
synced 2025-10-23 14:48:27 +03:00
address some linting issues
- rename "digester" vars that shadowed package-level digester type - rename "hexdigestbytes" to be properly camelCase - use "errors.Is()" instead of straight comparing errors Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
18
algorithm.go
18
algorithm.go
@@ -156,8 +156,8 @@ func RegisterAlgorithm(algorithm Algorithm, implementation CryptoHash) bool {
|
||||
|
||||
// hexDigestRegex can be used to generate a regex for RegisterAlgorithm.
|
||||
func hexDigestRegex(cryptoHash CryptoHash) *regexp.Regexp {
|
||||
hexdigestbytes := cryptoHash.Size() * 2
|
||||
return regexp.MustCompile(fmt.Sprintf("^[a-f0-9]{%d}$", hexdigestbytes))
|
||||
hexDigestBytes := cryptoHash.Size() * 2
|
||||
return regexp.MustCompile(fmt.Sprintf("^[a-f0-9]{%d}$", hexDigestBytes))
|
||||
}
|
||||
|
||||
// Available returns true if the digest type is available for use. If this
|
||||
@@ -254,20 +254,18 @@ func (a Algorithm) Encode(d []byte) string {
|
||||
|
||||
// FromReader returns the digest of the reader using the algorithm.
|
||||
func (a Algorithm) FromReader(rd io.Reader) (Digest, error) {
|
||||
digester := a.Digester()
|
||||
|
||||
if _, err := io.Copy(digester.Hash(), rd); err != nil {
|
||||
d := a.Digester()
|
||||
if _, err := io.Copy(d.Hash(), rd); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return digester.Digest(), nil
|
||||
return d.Digest(), nil
|
||||
}
|
||||
|
||||
// FromBytes digests the input and returns a Digest.
|
||||
func (a Algorithm) FromBytes(p []byte) Digest {
|
||||
digester := a.Digester()
|
||||
|
||||
if _, err := digester.Hash().Write(p); err != nil {
|
||||
d := a.Digester()
|
||||
if _, err := d.Hash().Write(p); err != nil {
|
||||
// Writes to a Hash should never fail. None of the existing
|
||||
// hash implementations in the stdlib or hashes vendored
|
||||
// here can return errors from Write. Having a panic in this
|
||||
@@ -276,7 +274,7 @@ func (a Algorithm) FromBytes(p []byte) Digest {
|
||||
panic("write to hash function returned error: " + err.Error())
|
||||
}
|
||||
|
||||
return digester.Digest()
|
||||
return d.Digest()
|
||||
}
|
||||
|
||||
// FromString digests the string input and returns a Digest.
|
||||
|
Reference in New Issue
Block a user