@@ -15,6 +15,7 @@ import (
1515	ociSpec "github.com/opencontainers/image-spec/specs-go/v1" 
1616	"github.com/sirupsen/logrus" 
1717	"go.podman.io/common/pkg/config" 
18+ 	"go.podman.io/common/pkg/digestutils" 
1819	registryTransport "go.podman.io/image/v5/docker" 
1920	dockerArchiveTransport "go.podman.io/image/v5/docker/archive" 
2021	dockerDaemonTransport "go.podman.io/image/v5/docker/daemon" 
@@ -26,6 +27,7 @@ import (
2627	"go.podman.io/image/v5/transports/alltransports" 
2728	"go.podman.io/image/v5/types" 
2829	"go.podman.io/storage" 
30+ 	supportedDigests "go.podman.io/storage/pkg/supported-digests" 
2931)
3032
3133// PullOptions allows for customizing image pulls. 
@@ -101,7 +103,7 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
101103
102104		// If the image clearly refers to a local one, we can look it up directly. 
103105		// In fact, we need to since they are not parseable. 
104- 		if  strings . HasPrefix (name ,  "sha256:" )  ||  ( len ( name )  ==   64   &&   ! strings . ContainsAny ( name ,  "/.:@" ) ) {
106+ 		if  digestutils . IsDigestReference (name ) {
105107			if  pullPolicy  ==  config .PullPolicyAlways  {
106108				return  nil , fmt .Errorf ("pull policy is always but image has been referred to by ID (%s)" , name )
107109			}
@@ -261,7 +263,16 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
261263			if  err  !=  nil  {
262264				return  nil , nil , err 
263265			}
264- 			imageName  =  "sha256:"  +  storageName [1 :]
266+ 			// Extract the algorithm from the getImageID result 
267+ 			// getImageID returns something like "@sha256:abc123" or "@sha512:def456" 
268+ 			// We need to preserve the algorithm that was actually used 
269+ 			if  algorithm , hash  :=  digestutils .ExtractAlgorithmFromDigest (storageName ); algorithm  !=  ""  {
270+ 				imageName  =  algorithm  +  ":"  +  hash 
271+ 			} else  {
272+ 				// Fallback to configured algorithm 
273+ 				digestAlgorithm  :=  supportedDigests .TmpDigestForNewObjects ()
274+ 				imageName  =  digestAlgorithm .String () +  ":"  +  storageName [1 :]
275+ 			}
265276		} else  { // If the OCI-reference includes an image reference, use it 
266277			storageName  =  refName 
267278			imageName  =  storageName 
@@ -280,7 +291,16 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
280291			if  err  !=  nil  {
281292				return  nil , nil , err 
282293			}
283- 			imageName  =  "sha256:"  +  storageName [1 :]
294+ 			// Extract the algorithm from the getImageID result 
295+ 			// getImageID returns something like "@sha256:abc123" or "@sha512:def456" 
296+ 			// We need to preserve the algorithm that was actually used 
297+ 			if  algorithm , hash  :=  digestutils .ExtractAlgorithmFromDigest (storageName ); algorithm  !=  ""  {
298+ 				imageName  =  algorithm  +  ":"  +  hash 
299+ 			} else  {
300+ 				// Fallback to configured algorithm 
301+ 				digestAlgorithm  :=  supportedDigests .TmpDigestForNewObjects ()
302+ 				imageName  =  digestAlgorithm .String () +  ":"  +  storageName [1 :]
303+ 			}
284304		default :
285305			named , err  :=  NormalizeName (storageName )
286306			if  err  !=  nil  {
@@ -306,7 +326,16 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
306326		if  err  !=  nil  {
307327			return  nil , nil , err 
308328		}
309- 		imageName  =  "sha256:"  +  storageName [1 :]
329+ 		// Extract the algorithm from the getImageID result 
330+ 		// getImageID returns something like "@sha256:abc123" or "@sha512:def456" 
331+ 		// We need to preserve the algorithm that was actually used 
332+ 		if  algorithm , hash  :=  digestutils .ExtractAlgorithmFromDigest (storageName ); algorithm  !=  ""  {
333+ 			imageName  =  algorithm  +  ":"  +  hash 
334+ 		} else  {
335+ 			// Fallback to configured algorithm 
336+ 			digestAlgorithm  :=  supportedDigests .TmpDigestForNewObjects ()
337+ 			imageName  =  digestAlgorithm .String () +  ":"  +  storageName [1 :]
338+ 		}
310339	}
311340
312341	// Create a storage reference. 
@@ -340,8 +369,17 @@ func (r *Runtime) storageReferencesReferencesFromArchiveReader(ctx context.Conte
340369		}
341370		destNames  =  append (destNames , destName )
342371		// Make sure the image can be loaded after the pull by 
343- 		// replacing the @ with sha256:. 
344- 		imageNames  =  append (imageNames , "sha256:" + destName [1 :])
372+ 		// replacing the @ with the correct algorithm. 
373+ 		// Extract the algorithm from the getImageID result 
374+ 		// getImageID returns something like "@sha256:abc123" or "@sha512:def456" 
375+ 		// We need to preserve the algorithm that was actually used 
376+ 		if  algorithm , hash  :=  digestutils .ExtractAlgorithmFromDigest (destName ); algorithm  !=  ""  {
377+ 			imageNames  =  append (imageNames , algorithm + ":" + hash )
378+ 		} else  {
379+ 			// Fallback to configured algorithm 
380+ 			digestAlgorithm  :=  supportedDigests .TmpDigestForNewObjects ()
381+ 			imageNames  =  append (imageNames , digestAlgorithm .String ()+ ":" + destName [1 :])
382+ 		}
345383	} else  {
346384		for  i  :=  range  destNames  {
347385			ref , err  :=  NormalizeName (destNames [i ])
0 commit comments