@@ -3,6 +3,7 @@ package desync
33import (
44 "bytes"
55 "context"
6+ "crypto"
67 "crypto/tls"
78 "errors"
89 "fmt"
@@ -31,6 +32,12 @@ type OCIStore struct {
3132
3233// NewOCIStore initializes a new Open Registry As Storage backend.
3334func NewOCIStore (u * url.URL , creds auth.CredentialFunc , opt StoreOptions ) (OCIStore , error ) {
35+ // The OCI spec does not support desync's default hash algorithm (SHA512/256), so we must
36+ // be using SHA256 only.
37+ if Digest .Algorithm () != crypto .SHA256 {
38+ return OCIStore {}, errors .New ("OCI stores only support SHA256, use --digest=sha256" )
39+ }
40+
3441 repo , err := remote .NewRepository (u .Host + u .Path )
3542 if err != nil {
3643 return OCIStore {}, fmt .Errorf ("failed to initialize oci registry store: %w" , err )
@@ -65,7 +72,14 @@ func (s OCIStore) Close() error { return nil }
6572
6673// GetChunk reads and returns one chunk from the store
6774func (s OCIStore ) GetChunk (id ChunkID ) (* Chunk , error ) {
68- r , err := s .repo .Fetch (context .Background (), ociDescriptorForChunk (id ))
75+ descriptor , err := s .repo .Blobs ().Resolve (context .Background (), ociReference (id ))
76+ if err != nil {
77+ if errors .Is (err , errdef .ErrNotFound ) {
78+ return nil , ChunkMissing {id }
79+ }
80+ return nil , err
81+ }
82+ r , err := s .repo .Fetch (context .Background (), descriptor )
6983 if err != nil {
7084 if errors .Is (err , errdef .ErrNotFound ) {
7185 return nil , ChunkMissing {id }
@@ -112,8 +126,11 @@ func (s OCIStore) RemoveChunk(id ChunkID) error {
112126
113127func ociDescriptorForChunk (id ChunkID ) ocispec.Descriptor {
114128 return ocispec.Descriptor {
115- // TODO: this may only work for SHA256 stores
116- Digest : digest .Digest ("sha256:" + id .String ()),
129+ Digest : digest .Digest (ociReference (id )),
117130 MediaType : "application/vnd.oci.image.layer.v1.tar+zstd" ,
118131 }
119132}
133+
134+ func ociReference (id ChunkID ) string {
135+ return "sha256:" + id .String ()
136+ }
0 commit comments