MCPcopy Index your code
hub / github.com/coder/coder / sha1HashFile

Function sha1HashFile

site/bin.go:459–477  ·  view source on GitHub ↗

sha1HashFile computes a SHA1 hash of the file, returning the hex representation.

(name string)

Source from the content-addressed store, hash-verified

457// sha1HashFile computes a SHA1 hash of the file, returning the hex
458// representation.
459func sha1HashFile(name string) (string, error) {
460 //#nosec // Not used for cryptography.
461 hash := sha1.New()
462 f, err := os.Open(name)
463 if err != nil {
464 return "", err
465 }
466 defer f.Close()
467
468 _, err = io.Copy(hash, f)
469 if err != nil {
470 return "", err
471 }
472
473 b := make([]byte, hash.Size())
474 hash.Sum(b[:0])
475
476 return hex.EncodeToString(b), nil
477}
478
479func parseSHA1(siteFS fs.FS) (map[string]string, error) {
480 b, err := fs.ReadFile(siteFS, "bin/coder.sha1")

Callers 1

verifyBinSha1IsCurrentFunction · 0.85

Calls 5

SizeMethod · 0.80
NewMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected