all: Remove crypto/md5 (#7493)

This is a mostly pointless change to make security scanners and static
analysis tools happy, as they all hate seeing md5. None of our md5 uses
were security relevant, but still. Only visible effect of this change is
that our temp file names for very long file names become slightly longer
than they were previously...
This commit is contained in:
Jakob Borg
2021-03-17 22:22:49 +01:00
committed by GitHub
parent f39477bbd5
commit f4372710bf
6 changed files with 44 additions and 52 deletions
+3 -4
View File
@@ -7,11 +7,12 @@
package fs
import (
"crypto/md5"
"fmt"
"path/filepath"
"runtime"
"strings"
"github.com/syncthing/syncthing/lib/sha256"
)
const (
@@ -50,9 +51,7 @@ func TempNameWithPrefix(name, prefix string) string {
tdir := filepath.Dir(name)
tbase := filepath.Base(name)
if len(tbase) > maxFilenameLength {
hash := md5.New()
hash.Write([]byte(name))
tbase = fmt.Sprintf("%x", hash.Sum(nil))
tbase = fmt.Sprintf("%x", sha256.Sum256([]byte(name)))
}
tname := fmt.Sprintf("%s%s.tmp", prefix, tbase)
return filepath.Join(tdir, tname)