mirror of
https://github.com/opencontainers/go-digest.git
synced 2025-04-18 03:24:02 +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:
parent
22b78e4785
commit
a1f6e2eda3
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.
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"bytes"
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
@ -56,7 +57,7 @@ func TestFlagInterface(t *testing.T) {
|
||||
} {
|
||||
t.Run(testcase.Name, func(t *testing.T) {
|
||||
alg = Canonical
|
||||
if err := flagSet.Parse(testcase.Args); err != testcase.Err {
|
||||
if err := flagSet.Parse(testcase.Args); !errors.Is(err, testcase.Err) {
|
||||
if testcase.Err == nil {
|
||||
t.Fatal("unexpected error", err)
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func (dst *Set) Lookup(d string) (digest.Digest, error) {
|
||||
hex string
|
||||
)
|
||||
dgst, err := digest.Parse(d)
|
||||
if err == digest.ErrDigestInvalidFormat {
|
||||
if errors.Is(err, digest.ErrDigestInvalidFormat) {
|
||||
hex = d
|
||||
searchFunc = func(i int) bool {
|
||||
return dst.entries[i].val >= d
|
||||
|
@ -20,6 +20,7 @@
|
||||
package testdigest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
pkgdigest "github.com/opencontainers/go-digest"
|
||||
@ -38,7 +39,7 @@ type TestCase struct {
|
||||
|
||||
func RunTestCase(t *testing.T, testcase TestCase) {
|
||||
digest, err := pkgdigest.Parse(testcase.Input)
|
||||
if err != testcase.Err {
|
||||
if errors.Is(err, testcase.Err) {
|
||||
t.Fatalf("error differed from expected while parsing %q: %v != %v", testcase.Input, err, testcase.Err)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user