@@ -33,12 +33,15 @@ type bpDecryptionStepData struct {
3333// blobPipelineDecryptionStep updates *stream to decrypt if, it necessary.
3434// srcInfo is only used for error messages.
3535// Returns data for other steps; the caller should eventually use updateCryptoOperation.
36- func (c * copier ) blobPipelineDecryptionStep (stream * sourceStream , srcInfo types.BlobInfo ) (* bpDecryptionStepData , error ) {
37- if isOciEncrypted (stream .info .MediaType ) && c .ociDecryptConfig != nil {
36+ func (ic * imageCopier ) blobPipelineDecryptionStep (stream * sourceStream , srcInfo types.BlobInfo ) (* bpDecryptionStepData , error ) {
37+ if isOciEncrypted (stream .info .MediaType ) && ic .c .ociDecryptConfig != nil {
38+ if ic .cannotModifyManifestReason != "" {
39+ return nil , fmt .Errorf ("layer %s should be decrypted, but we can’t modify the manifest: %s" , srcInfo .Digest , ic .cannotModifyManifestReason )
40+ }
3841 desc := imgspecv1.Descriptor {
3942 Annotations : stream .info .Annotations ,
4043 }
41- reader , decryptedDigest , err := ocicrypt .DecryptLayer (c .ociDecryptConfig , stream .reader , desc , false )
44+ reader , decryptedDigest , err := ocicrypt .DecryptLayer (ic . c .ociDecryptConfig , stream .reader , desc , false )
4245 if err != nil {
4346 return nil , fmt .Errorf ("decrypting layer %s: %w" , srcInfo .Digest , err )
4447 }
@@ -74,9 +77,13 @@ type bpEncryptionStepData struct {
7477// blobPipelineEncryptionStep updates *stream to encrypt if, it required by toEncrypt.
7578// srcInfo is primarily used for error messages.
7679// Returns data for other steps; the caller should eventually call updateCryptoOperationAndAnnotations.
77- func (c * copier ) blobPipelineEncryptionStep (stream * sourceStream , toEncrypt bool , srcInfo types.BlobInfo ,
80+ func (ic * imageCopier ) blobPipelineEncryptionStep (stream * sourceStream , toEncrypt bool , srcInfo types.BlobInfo ,
7881 decryptionStep * bpDecryptionStepData ) (* bpEncryptionStepData , error ) {
79- if toEncrypt && ! isOciEncrypted (srcInfo .MediaType ) && c .ociEncryptConfig != nil {
82+ if toEncrypt && ! isOciEncrypted (srcInfo .MediaType ) && ic .c .ociEncryptConfig != nil {
83+ if ic .cannotModifyManifestReason != "" {
84+ return nil , fmt .Errorf ("layer %s should be encrypted, but we can’t modify the manifest: %s" , srcInfo .Digest , ic .cannotModifyManifestReason )
85+ }
86+
8087 var annotations map [string ]string
8188 if ! decryptionStep .decrypting {
8289 annotations = srcInfo .Annotations
@@ -87,7 +94,7 @@ func (c *copier) blobPipelineEncryptionStep(stream *sourceStream, toEncrypt bool
8794 Size : srcInfo .Size ,
8895 Annotations : annotations ,
8996 }
90- reader , finalizer , err := ocicrypt .EncryptLayer (c .ociEncryptConfig , stream .reader , desc )
97+ reader , finalizer , err := ocicrypt .EncryptLayer (ic . c .ociEncryptConfig , stream .reader , desc )
9198 if err != nil {
9299 return nil , fmt .Errorf ("encrypting blob %s: %w" , srcInfo .Digest , err )
93100 }
0 commit comments