Writes and verify image

This commit is contained in:
2026-04-04 02:45:46 +08:00
parent 9cb593ffc0
commit 4f490ab37e
20 changed files with 596 additions and 65 deletions

View File

@@ -0,0 +1,30 @@
package catalog
import (
"encoding/hex"
"fmt"
"strings"
)
func (c *CatalogImage) SHA256() (string, error) {
if c.Checksum == "" {
return "", fmt.Errorf("checksum is empty")
}
const prefix = "sha256:"
if !strings.HasPrefix(c.Checksum, prefix) {
return "", fmt.Errorf("unsupported checksum format (expected sha256:...)")
}
hash := strings.TrimPrefix(c.Checksum, prefix)
if len(hash) != 64 {
return "", fmt.Errorf("invalid sha256 length: got %d, want 64", len(hash))
}
if _, err := hex.DecodeString(hash); err != nil {
return "", fmt.Errorf("invalid sha256 hex: %w", err)
}
return hash, nil
}