|
|
|
@ -125,10 +125,15 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
|
|
|
|
var digest32 [32]byte
|
|
|
|
var digest32 [32]byte
|
|
|
|
if hash != "" {
|
|
|
|
if hash != "" {
|
|
|
|
// if there is a hash, populate the other formats
|
|
|
|
// if there is a hash, populate the other formats
|
|
|
|
digest, err = hex.DecodeString(hash)
|
|
|
|
// Strip the algorithm prefix (e.g., "sha256:") if present
|
|
|
|
|
|
|
|
digest, err = hex.DecodeString(stripDigestAlgorithm(hash))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(digest) != 32 {
|
|
|
|
|
|
|
|
return "", nil, fmt.Errorf("invalid digest length: %d", len(digest))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
copy(digest32[:], digest)
|
|
|
|
copy(digest32[:], digest)
|
|
|
|
if pth, err := c.Cache.Get(digest32, CacheChart); err == nil {
|
|
|
|
if pth, err := c.Cache.Get(digest32, CacheChart); err == nil {
|
|
|
|
fdata, err := os.ReadFile(pth)
|
|
|
|
fdata, err := os.ReadFile(pth)
|
|
|
|
@ -231,10 +236,14 @@ func (c *ChartDownloader) DownloadToCache(ref, version string) (string, *provena
|
|
|
|
c.Options = append(c.Options, getter.WithAcceptHeader("application/gzip,application/octet-stream"))
|
|
|
|
c.Options = append(c.Options, getter.WithAcceptHeader("application/gzip,application/octet-stream"))
|
|
|
|
|
|
|
|
|
|
|
|
// Check the cache for the file
|
|
|
|
// Check the cache for the file
|
|
|
|
digest, err := hex.DecodeString(digestString)
|
|
|
|
// Strip the algorithm prefix (e.g., "sha256:") if present
|
|
|
|
|
|
|
|
digest, err := hex.DecodeString(stripDigestAlgorithm(digestString))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, fmt.Errorf("unable to decode digest: %w", err)
|
|
|
|
return "", nil, fmt.Errorf("unable to decode digest: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if digestString != "" && len(digest) != 32 {
|
|
|
|
|
|
|
|
return "", nil, fmt.Errorf("invalid digest length: %d", len(digest))
|
|
|
|
|
|
|
|
}
|
|
|
|
var digest32 [32]byte
|
|
|
|
var digest32 [32]byte
|
|
|
|
copy(digest32[:], digest)
|
|
|
|
copy(digest32[:], digest)
|
|
|
|
|
|
|
|
|
|
|
|
@ -584,3 +593,12 @@ func loadRepoConfig(file string) (*repo.File, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r, nil
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// stripDigestAlgorithm removes the algorithm prefix (e.g., "sha256:") from a digest string.
|
|
|
|
|
|
|
|
// If no prefix is present, the original string is returned unchanged.
|
|
|
|
|
|
|
|
func stripDigestAlgorithm(digest string) string {
|
|
|
|
|
|
|
|
if idx := strings.Index(digest, ":"); idx >= 0 {
|
|
|
|
|
|
|
|
return digest[idx+1:]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return digest
|
|
|
|
|
|
|
|
}
|
|
|
|
|