mirror of
https://github.com/luxfi/crypto.git
synced 2026-10-30 16:59:13 +00:00
Lux Partners Limited is not the entity behind this work. Every place the old name stood — copyright lines, site footers, brand config, legal and compliance text — now names the company that actually holds it. lux.fund is the exception and is not renamed to match: that site belongs to Lux Assets Management LLC, a different company, and it says so. Two kinds of line were left for a person rather than rewritten. A dated news item recording that Lux Partners Limited was established in the Isle of Man is a historical fact, and renaming it would falsify the record. And a sentence asserting that the company is domiciled in the Isle of Man is a claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle of Man company, so swapping the name there would assert something untrue.
42 lines
1021 B
Go
42 lines
1021 B
Go
// Copyright (C) 2022, Lux Industries Inc All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package hash
|
|
|
|
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.Split(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)
|
|
}
|