Files
zeekayandHanzo Dev 5d1623a055 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 19:25:30 -07:00

42 lines
1022 B
Go

// Copyright (C) 2022, Lux Industries Inc All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
"strings"
)
func GetSHA256FromDisk(binPath string) (string, error) {
if _, err := os.Stat(binPath); err != nil {
return "", fmt.Errorf("failed looking up plugin binary at %s: %w", binPath, err)
}
hasher := sha256.New()
s, err := os.ReadFile(binPath)
if err != nil {
return "", err
}
if _, err := hasher.Write(s); err != nil {
return "", fmt.Errorf("failed calculating the sha256 hash of the binary %s: %w", binPath, err)
}
return hex.EncodeToString(hasher.Sum(nil)), nil
}
func SearchSHA256File(file []byte, toSearch string) (string, error) {
lines := strings.SplitSeq(string(file), "\n")
for line := range lines {
sha256Info := strings.Fields(line)
if len(sha256Info) == 2 {
if sha256Info[1] == toSearch {
return sha256Info[0], nil
}
}
}
return "", fmt.Errorf("%q not found in sha256 file", toSearch)
}