Implements macOS v0: verae-print stamp + install-macos PDF menu items.
Saves {name}.pdf, {name}-verae-timestamp-{RECEIPTID}.pdf, and .verae.json.
Channels: verae (api.veraetime.net JWT) and zapier (zap.verae.ai xVerae- + attachPdf).
39 lines
850 B
Go
39 lines
850 B
Go
package hash
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// FileSHA256 returns the lowercase hex SHA-256 of the file at path.
|
|
func FileSHA256(path string) (string, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer f.Close()
|
|
h := sha256.New()
|
|
if _, err := io.Copy(h, f); err != nil {
|
|
return "", err
|
|
}
|
|
return hex.EncodeToString(h.Sum(nil)), nil
|
|
}
|
|
|
|
// NormalizeDigest lowercases and strips an optional sha256: prefix.
|
|
func NormalizeDigest(d string) (string, error) {
|
|
s := strings.TrimSpace(strings.ToLower(d))
|
|
s = strings.TrimPrefix(s, "sha256:")
|
|
if len(s) != 64 {
|
|
return "", fmt.Errorf("digest must be 64 hex chars, got %d", len(s))
|
|
}
|
|
for _, c := range s {
|
|
if (c < '0' || c > '9') && (c < 'a' || c > 'f') {
|
|
return "", fmt.Errorf("digest is not hex")
|
|
}
|
|
}
|
|
return s, nil
|
|
}
|