Files
HexaHost-GameCloud/apps/node-agent/internal/transfer/hash.go
smueller d29a02f2a4
Some checks failed
CI / Node — lint, typecheck, test, build (push) Failing after 9s
CI / Go — node-agent tests (push) Failing after 9s
CI / Go — edge-gateway build (push) Successful in 13s
Phase5
2026-06-26 13:00:01 +02:00

35 lines
548 B
Go

package transfer
import (
"crypto/sha512"
"encoding/hex"
"fmt"
"io"
"os"
)
// VerifySha512File checks that a file matches the expected sha512 hash.
func VerifySha512File(path, expected string) error {
if expected == "" {
return nil
}
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
hasher := sha512.New()
if _, err := io.Copy(hasher, file); err != nil {
return err
}
actual := hex.EncodeToString(hasher.Sum(nil))
if actual != expected {
return fmt.Errorf("sha512 mismatch")
}
return nil
}