Writes and verify image
This commit is contained in:
30
clitools/pkg/catalog/checksums.go
Normal file
30
clitools/pkg/catalog/checksums.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user