Skip to content

Commit cae3943

Browse files
committed
Stop using deprecated digest.Digest.Hex
Should not change behavior. Signed-off-by: Miloslav Trmač <[email protected]>
1 parent b95c064 commit cae3943

File tree

15 files changed

+35
-35
lines changed

15 files changed

+35
-35
lines changed

docker/internal/tarfile/writer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (w *Writer) writeLegacyMetadataLocked(layerDescriptors []manifest.Schema2De
164164
return fmt.Errorf("marshaling layer config: %w", err)
165165
}
166166
delete(layerConfig, "layer_id")
167-
layerID := digest.Canonical.FromBytes(b).Hex()
167+
layerID := digest.Canonical.FromBytes(b).Encoded()
168168
layerConfig["id"] = layerID
169169

170170
configBytes, err := json.Marshal(layerConfig)
@@ -309,26 +309,26 @@ func (w *Writer) Close() error {
309309
// NOTE: This is an internal implementation detail, not a format property, and can change
310310
// any time.
311311
func (w *Writer) configPath(configDigest digest.Digest) (string, error) {
312-
if err := configDigest.Validate(); err != nil { // digest.Digest.Hex() panics on failure, and could possibly result in unexpected paths, so validate explicitly.
312+
if err := configDigest.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, and could possibly result in unexpected paths, so validate explicitly.
313313
return "", err
314314
}
315-
return configDigest.Hex() + ".json", nil
315+
return configDigest.Encoded() + ".json", nil
316316
}
317317

318318
// physicalLayerPath returns a path we choose for storing a layer with the specified digest
319319
// (the actual path, i.e. a regular file, not a symlink that may be used in the legacy format).
320320
// NOTE: This is an internal implementation detail, not a format property, and can change
321321
// any time.
322322
func (w *Writer) physicalLayerPath(layerDigest digest.Digest) (string, error) {
323-
if err := layerDigest.Validate(); err != nil { // digest.Digest.Hex() panics on failure, and could possibly result in unexpected paths, so validate explicitly.
323+
if err := layerDigest.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, and could possibly result in unexpected paths, so validate explicitly.
324324
return "", err
325325
}
326-
// Note that this can't be e.g. filepath.Join(l.Digest.Hex(), legacyLayerFileName); due to the way
326+
// Note that this can't be e.g. filepath.Join(l.Digest.Encoded(), legacyLayerFileName); due to the way
327327
// writeLegacyMetadata constructs layer IDs differently from inputinfo.Digest values (as described
328328
// inside it), most of the layers would end up in subdirectories alone without any metadata; (docker load)
329329
// tries to load every subdirectory as an image and fails if the config is missing. So, keep the layers
330330
// in the root of the tarball.
331-
return layerDigest.Hex() + ".tar", nil
331+
return layerDigest.Encoded() + ".tar", nil
332332
}
333333

334334
type tarFI struct {

docker/registries_d.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ func (ns registryNamespace) signatureTopLevel(write bool) string {
288288
// base is not nil from the caller
289289
// NOTE: Keep this in sync with docs/signature-protocols.md!
290290
func lookasideStorageURL(base lookasideStorageBase, manifestDigest digest.Digest, index int) (*url.URL, error) {
291-
if err := manifestDigest.Validate(); err != nil { // digest.Digest.Hex() panics on failure, and could possibly result in a path with ../, so validate explicitly.
291+
if err := manifestDigest.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, and could possibly result in a path with ../, so validate explicitly.
292292
return nil, err
293293
}
294294
sigURL := *base
295-
sigURL.Path = fmt.Sprintf("%s@%s=%s/signature-%d", sigURL.Path, manifestDigest.Algorithm(), manifestDigest.Hex(), index+1)
295+
sigURL.Path = fmt.Sprintf("%s@%s=%s/signature-%d", sigURL.Path, manifestDigest.Algorithm(), manifestDigest.Encoded(), index+1)
296296
return &sigURL, nil
297297
}

internal/image/docker_schema2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func v1IDFromBlobDigestAndComponents(blobDigest digest.Digest, others ...string)
366366
if err := blobDigest.Validate(); err != nil {
367367
return "", err
368368
}
369-
parts := append([]string{blobDigest.Hex()}, others...)
369+
parts := append([]string{blobDigest.Encoded()}, others...)
370370
v1IDHash := sha256.Sum256([]byte(strings.Join(parts, " ")))
371371
return hex.EncodeToString(v1IDHash[:]), nil
372372
}

manifest/docker_schema1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,5 @@ func (m *Schema1) ImageID(diffIDs []digest.Digest) (string, error) {
342342
if err != nil {
343343
return "", err
344344
}
345-
return digest.FromBytes(image).Hex(), nil
345+
return digest.FromBytes(image).Encoded(), nil
346346
}

manifest/docker_schema2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (m *Schema2) ImageID([]digest.Digest) (string, error) {
295295
if err := m.ConfigDescriptor.Digest.Validate(); err != nil {
296296
return "", err
297297
}
298-
return m.ConfigDescriptor.Digest.Hex(), nil
298+
return m.ConfigDescriptor.Digest.Encoded(), nil
299299
}
300300

301301
// CanChangeLayerCompression returns true if we can compress/decompress layers with mimeType in the current image

manifest/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (m *OCI1) ImageID(diffIDs []digest.Digest) (string, error) {
260260
if err := m.Config.Digest.Validate(); err != nil {
261261
return "", err
262262
}
263-
return m.Config.Digest.Hex(), nil
263+
return m.Config.Digest.Encoded(), nil
264264
}
265265

266266
// CanChangeLayerCompression returns true if we can compress/decompress layers with mimeType in the current image

oci/layout/oci_delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,15 @@ func loadFixture(t *testing.T, fixtureName string) string {
318318
func assertBlobExists(t *testing.T, blobsDir string, blobDigest string) {
319319
digest, err := digest.Parse(blobDigest)
320320
require.NoError(t, err)
321-
blobPath := filepath.Join(blobsDir, digest.Algorithm().String(), digest.Hex())
321+
blobPath := filepath.Join(blobsDir, digest.Algorithm().String(), digest.Encoded())
322322
_, err = os.Stat(blobPath)
323323
require.NoError(t, err)
324324
}
325325

326326
func assertBlobDoesNotExist(t *testing.T, blobsDir string, blobDigest string) {
327327
digest, err := digest.Parse(blobDigest)
328328
require.NoError(t, err)
329-
blobPath := filepath.Join(blobsDir, digest.Algorithm().String(), digest.Hex())
329+
blobPath := filepath.Join(blobsDir, digest.Algorithm().String(), digest.Encoded())
330330
_, err = os.Stat(blobPath)
331331
require.True(t, os.IsNotExist(err))
332332
}

oci/layout/oci_transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,5 @@ func (ref ociReference) blobPath(digest digest.Digest, sharedBlobDir string) (st
256256
} else {
257257
blobDir = filepath.Join(ref.dir, imgspecv1.ImageBlobsDir)
258258
}
259-
return filepath.Join(blobDir, digest.Algorithm().String(), digest.Hex()), nil
259+
return filepath.Join(blobDir, digest.Algorithm().String(), digest.Encoded()), nil
260260
}

ostree/ostree_dest.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (d *ostreeImageDestination) PutBlobWithOptions(ctx context.Context, stream
164164
return private.UploadedBlob{}, err
165165
}
166166

167-
hash := blobDigest.Hex()
167+
hash := blobDigest.Encoded()
168168
d.blobs[hash] = &blobToImport{Size: size, Digest: blobDigest, BlobPath: blobPath}
169169
return private.UploadedBlob{Digest: blobDigest, Size: size}, nil
170170
}
@@ -282,8 +282,8 @@ func generateTarSplitMetadata(output *bytes.Buffer, file string) (digest.Digest,
282282
func (d *ostreeImageDestination) importBlob(selinuxHnd *C.struct_selabel_handle, repo *otbuiltin.Repo, blob *blobToImport) error {
283283
// TODO: This can take quite some time, and should ideally be cancellable using a context.Context.
284284

285-
ostreeBranch := fmt.Sprintf("ociimage/%s", blob.Digest.Hex())
286-
destinationPath := filepath.Join(d.tmpDirPath, blob.Digest.Hex(), "root")
285+
ostreeBranch := fmt.Sprintf("ociimage/%s", blob.Digest.Encoded())
286+
destinationPath := filepath.Join(d.tmpDirPath, blob.Digest.Encoded(), "root")
287287
if err := ensureDirectoryExists(destinationPath); err != nil {
288288
return err
289289
}
@@ -323,7 +323,7 @@ func (d *ostreeImageDestination) importBlob(selinuxHnd *C.struct_selabel_handle,
323323
}
324324

325325
func (d *ostreeImageDestination) importConfig(repo *otbuiltin.Repo, blob *blobToImport) error {
326-
ostreeBranch := fmt.Sprintf("ociimage/%s", blob.Digest.Hex())
326+
ostreeBranch := fmt.Sprintf("ociimage/%s", blob.Digest.Encoded())
327327
destinationPath := filepath.Dir(blob.BlobPath)
328328

329329
return d.ostreeCommit(repo, ostreeBranch, destinationPath, []string{fmt.Sprintf("docker.size=%d", blob.Size)})
@@ -348,10 +348,10 @@ func (d *ostreeImageDestination) TryReusingBlobWithOptions(ctx context.Context,
348348
d.repo = repo
349349
}
350350

351-
if err := info.Digest.Validate(); err != nil { // digest.Digest.Hex() panics on failure, so validate explicitly.
351+
if err := info.Digest.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, so validate explicitly.
352352
return false, private.ReusedBlob{}, err
353353
}
354-
branch := fmt.Sprintf("ociimage/%s", info.Digest.Hex())
354+
branch := fmt.Sprintf("ociimage/%s", info.Digest.Encoded())
355355

356356
found, data, err := readMetadata(d.repo, branch, "docker.uncompressed_digest")
357357
if err != nil || !found {
@@ -479,7 +479,7 @@ func (d *ostreeImageDestination) Commit(context.Context, types.UnparsedImage) er
479479
if err := layer.Digest.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, so validate explicitly.
480480
return err
481481
}
482-
hash := layer.Digest.Hex()
482+
hash := layer.Digest.Encoded()
483483
if err = checkLayer(hash); err != nil {
484484
return err
485485
}
@@ -488,7 +488,7 @@ func (d *ostreeImageDestination) Commit(context.Context, types.UnparsedImage) er
488488
if err := layer.BlobSum.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, so validate explicitly.
489489
return err
490490
}
491-
hash := layer.BlobSum.Hex()
491+
hash := layer.BlobSum.Encoded()
492492
if err = checkLayer(hash); err != nil {
493493
return err
494494
}

ostree/ostree_src.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (s *ostreeImageSource) GetBlob(ctx context.Context, info types.BlobInfo, ca
289289
if err := info.Digest.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, so validate explicitly.
290290
return nil, -1, err
291291
}
292-
blob := info.Digest.Hex()
292+
blob := info.Digest.Encoded()
293293

294294
// Ensure s.compressed is initialized. It is build by LayerInfosForCopy.
295295
if s.compressed == nil {
@@ -301,7 +301,7 @@ func (s *ostreeImageSource) GetBlob(ctx context.Context, info types.BlobInfo, ca
301301
}
302302
compressedBlob, isCompressed := s.compressed[info.Digest]
303303
if isCompressed {
304-
blob = compressedBlob.Hex()
304+
blob = compressedBlob.Encoded()
305305
}
306306
branch := fmt.Sprintf("ociimage/%s", blob)
307307

@@ -424,7 +424,7 @@ func (s *ostreeImageSource) LayerInfosForCopy(ctx context.Context, instanceDiges
424424
layerBlobs := man.LayerInfos()
425425

426426
for _, layerBlob := range layerBlobs {
427-
branch := fmt.Sprintf("ociimage/%s", layerBlob.Digest.Hex())
427+
branch := fmt.Sprintf("ociimage/%s", layerBlob.Digest.Encoded())
428428
found, uncompressedDigestStr, err := readMetadata(s.repo, branch, "docker.uncompressed_digest")
429429
if err != nil || !found {
430430
return nil, err

0 commit comments

Comments
 (0)