Skip to content

Commit 0958a34

Browse files
committed
Move blobPipelineDecryptionStep and blobPipelineEncryptionStep to imageCopier
We will want to access imageCopier.cannotModifyManifestReason. All the ...Step functions are now methods of imageCopier, which is more consistent. Should not change behavior. Signed-off-by: Miloslav Trmač <[email protected]>
1 parent 5746710 commit 0958a34

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

copy/blob.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (ic *imageCopier) copyBlobFromStream(ctx context.Context, srcReader io.Read
4343
stream.reader = bar.ProxyReader(stream.reader)
4444

4545
// === Decrypt the stream, if required.
46-
decryptionStep, err := ic.c.blobPipelineDecryptionStep(&stream, srcInfo)
46+
decryptionStep, err := ic.blobPipelineDecryptionStep(&stream, srcInfo)
4747
if err != nil {
4848
return types.BlobInfo{}, err
4949
}
@@ -78,7 +78,7 @@ func (ic *imageCopier) copyBlobFromStream(ctx context.Context, srcReader io.Read
7878
// Before relaxing this, see the original pull request’s review if there are other reasons to reject this.
7979
return types.BlobInfo{}, errors.New("Unable to support both decryption and encryption in the same copy")
8080
}
81-
encryptionStep, err := ic.c.blobPipelineEncryptionStep(&stream, toEncrypt, srcInfo, decryptionStep)
81+
encryptionStep, err := ic.blobPipelineEncryptionStep(&stream, toEncrypt, srcInfo, decryptionStep)
8282
if err != nil {
8383
return types.BlobInfo{}, err
8484
}

copy/encryption.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)