Skip to content

Commit 2d2c5b4

Browse files
committed
deprecate sha1
1 parent 78acbaf commit 2d2c5b4

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

.golangci.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
version: "2"
3+
run:
4+
allow-parallel-runners: true
5+
linters:
6+
enable:
7+
- "gosec"
8+
disable:
9+
- "errcheck"
10+
settings:
11+
gosec:
12+
includes:
13+
- G501 # Import blocklist: crypto/md5
14+
- G502 # Import blocklist: crypto/des
15+
- G503 # Import blocklist: crypto/rc4
16+
- G504 # Import blocklist: net/http/cgi
17+
- G505 # Import blocklist: crypto/sha1
18+
- G506 # Import blocklist: golang.org/x/crypto/md4
19+
- G507 # Import blocklist: golang.org/x/crypto/ripemd160
20+

mage/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package mage
22

33
import (
44
"bytes"
5-
"crypto/sha1"
5+
"crypto/sha3"
66
"errors"
77
"flag"
88
"fmt"
@@ -173,7 +173,7 @@ func ParseAndRun(stdout, stderr io.Writer, stdin io.Reader, args []string) int {
173173
case None:
174174
return Invoke(inv)
175175
default:
176-
panic(fmt.Errorf("Unknown command type: %v", cmd))
176+
panic(fmt.Errorf("unknown command type: %v", cmd))
177177
}
178178
}
179179

@@ -656,13 +656,13 @@ func ExeName(goCmd, cacheDir string, files []string) (string, error) {
656656
}
657657
// hash the mainfile template to ensure if it gets updated, we make a new
658658
// binary.
659-
hashes = append(hashes, fmt.Sprintf("%x", sha1.Sum([]byte(mageMainfileTplString))))
659+
hashes = append(hashes, fmt.Sprintf("%x", sha3.Sum256([]byte(mageMainfileTplString))))
660660
sort.Strings(hashes)
661661
ver, err := internal.OutputDebug(goCmd, "version")
662662
if err != nil {
663663
return "", err
664664
}
665-
hash := sha1.Sum([]byte(strings.Join(hashes, "") + magicRebuildKey + ver))
665+
hash := sha3.Sum256([]byte(strings.Join(hashes, "") + magicRebuildKey + ver))
666666
filename := fmt.Sprintf("%x", hash)
667667

668668
out := filepath.Join(cacheDir, filename)
@@ -679,7 +679,7 @@ func hashFile(fn string) (string, error) {
679679
}
680680
defer f.Close()
681681

682-
h := sha1.New()
682+
h := sha3.New256()
683683
if _, err := io.Copy(h, f); err != nil {
684684
return "", fmt.Errorf("can't write data to hash: %v", err)
685685
}

mage/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ func TestOnlyStdLib(t *testing.T) {
920920
if err != nil {
921921
t.Fatal(err)
922922
}
923-
if !filepath.HasPrefix(pkg.Dir, build.Default.GOROOT) {
923+
if !strings.HasPrefix(pkg.Dir, build.Default.GOROOT) {
924924
t.Errorf("import of non-stdlib package: %s", s.Path.Value)
925925
}
926926
}

mg/deps_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestDepError(t *testing.T) {
8686
t.Fatal("expected panic, but didn't get one")
8787
}
8888
actual := fmt.Sprint(err)
89-
if "ouch" != actual {
89+
if actual != "ouch" {
9090
t.Fatalf(`expected to get "ouch" but got "%s"`, actual)
9191
}
9292
}()
@@ -103,7 +103,7 @@ func TestDepFatal(t *testing.T) {
103103
t.Fatal("expected panic, but didn't get one")
104104
}
105105
actual := fmt.Sprint(v)
106-
if "ouch!" != actual {
106+
if actual != "ouch!" {
107107
t.Fatalf(`expected to get "ouch!" but got "%s"`, actual)
108108
}
109109
err, ok := v.(error)
@@ -132,7 +132,7 @@ func TestDepTwoFatal(t *testing.T) {
132132
}
133133
actual := fmt.Sprint(v)
134134
// order is non-deterministic, so check for both orders
135-
if "ouch!\nbang!" != actual && "bang!\nouch!" != actual {
135+
if actual != "ouch!\nbang!" && actual != "bang!\nouch!" {
136136
t.Fatalf(`expected to get "ouch!" and "bang!" but got "%s"`, actual)
137137
}
138138
err, ok := v.(error)
@@ -157,7 +157,7 @@ func TestDepWithUnhandledFunc(t *testing.T) {
157157
t.Fatalf("Expected type error from panic")
158158
}
159159
}()
160-
var NotValid func(string) string = func(a string) string {
160+
var NotValid = func(a string) string {
161161
return a
162162
}
163163
Deps(NotValid)

mg/fn_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestFuncCheck(t *testing.T) {
5151
t.Error("func is not on a namespace")
5252
}
5353

54-
hasContext, isNamespace, err = checkF(Foo.Bare, nil)
54+
_, _, err = checkF(Foo.Bare, nil)
5555
if err != nil {
5656
t.Error(err)
5757
}
@@ -117,11 +117,11 @@ func TestFuncCheck(t *testing.T) {
117117
}
118118

119119
defer func() {
120-
if r := recover(); r !=nil {
120+
if r := recover(); r != nil {
121121
t.Error("expected a nil function argument to be handled gracefully")
122122
}
123123
}()
124-
_, _, err = checkF(nil, []interface{}{1,2})
124+
_, _, err = checkF(nil, []interface{}{1, 2})
125125
if err == nil {
126126
t.Error("expected a nil function argument to be invalid")
127127
}

parse/parse.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func checkDupes(info *PkgInfo, imports []*Import) error {
214214
for _, f := range funcs[alias] {
215215
ids = append(ids, f.ID())
216216
}
217-
return fmt.Errorf("alias %q duplicates existing target(s): %s\n", alias, strings.Join(ids, ", "))
217+
return fmt.Errorf("alias %q duplicates existing target(s): %s", alias, strings.Join(ids, ", "))
218218
}
219219
funcs[alias] = append(funcs[alias], f)
220220
}
@@ -792,11 +792,6 @@ func hasContextParam(ft *ast.FuncType) (bool, error) {
792792
return true, nil
793793
}
794794

795-
func hasVoidReturn(ft *ast.FuncType) bool {
796-
res := ft.Results
797-
return res.NumFields() == 0
798-
}
799-
800795
func hasErrorReturn(ft *ast.FuncType) (bool, error) {
801796
res := ft.Results
802797
if res.NumFields() == 0 {
@@ -847,7 +842,7 @@ func funcType(ft *ast.FuncType) (*Function, error) {
847842
}
848843

849844
func toOneLine(s string) string {
850-
return strings.TrimSpace(strings.Replace(s, "\n", " ", -1))
845+
return strings.TrimSpace(strings.ReplaceAll(s, "\n", " "))
851846
}
852847

853848
var argTypes = map[string]string{

0 commit comments

Comments
 (0)