MCPcopy Create free account
hub / github.com/containers/image / blobPipelineEncryptionStep

Method blobPipelineEncryptionStep

copy/encryption.go:86–120  ·  view source on GitHub ↗

blobPipelineEncryptionStep updates *stream to encrypt if, it required by toEncrypt. srcInfo is primarily used for error messages. Returns data for other steps; the caller should eventually call updateCryptoOperationAndAnnotations.

(stream *sourceStream, toEncrypt bool, srcInfo types.BlobInfo,
	decryptionStep *bpDecryptionStepData)

Source from the content-addressed store, hash-verified

84// srcInfo is primarily used for error messages.
85// Returns data for other steps; the caller should eventually call updateCryptoOperationAndAnnotations.
86func (ic *imageCopier) blobPipelineEncryptionStep(stream *sourceStream, toEncrypt bool, srcInfo types.BlobInfo,
87 decryptionStep *bpDecryptionStepData) (*bpEncryptionStepData, error) {
88 if !toEncrypt || isOciEncrypted(srcInfo.MediaType) || ic.c.options.OciEncryptConfig == nil {
89 return &bpEncryptionStepData{
90 encrypting: false,
91 }, nil
92 }
93
94 if ic.cannotModifyManifestReason != "" {
95 return nil, fmt.Errorf("layer %s should be encrypted, but we can’t modify the manifest: %s", srcInfo.Digest, ic.cannotModifyManifestReason)
96 }
97
98 var annotations map[string]string
99 if !decryptionStep.decrypting {
100 annotations = srcInfo.Annotations
101 }
102 desc := imgspecv1.Descriptor{
103 MediaType: srcInfo.MediaType,
104 Digest: srcInfo.Digest,
105 Size: srcInfo.Size,
106 Annotations: annotations,
107 }
108 reader, finalizer, err := ocicrypt.EncryptLayer(ic.c.options.OciEncryptConfig, stream.reader, desc)
109 if err != nil {
110 return nil, fmt.Errorf("encrypting blob %s: %w", srcInfo.Digest, err)
111 }
112
113 stream.reader = reader
114 stream.info.Digest = ""
115 stream.info.Size = -1
116 return &bpEncryptionStepData{
117 encrypting: true,
118 finalizer: finalizer,
119 }, nil
120}
121
122// updateCryptoOperationAndAnnotations sets *operation and updates *annotations, if necessary.
123func (d *bpEncryptionStepData) updateCryptoOperationAndAnnotations(operation *types.LayerCrypto, annotations *map[string]string) error {

Callers 1

copyBlobFromStreamMethod · 0.95

Calls 1

isOciEncryptedFunction · 0.85

Tested by

no test coverage detected