MCPcopy
hub / github.com/getsops/sops / EncryptContext

Method EncryptContext

pgp/keysource.go:275–296  ·  view source on GitHub ↗

EncryptContext encrypts the data key with the PGP key with the same fingerprint as the MasterKey.

(ctx context.Context, dataKey []byte)

Source from the content-addressed store, hash-verified

273// EncryptContext encrypts the data key with the PGP key with the same
274// fingerprint as the MasterKey.
275func (key *MasterKey) EncryptContext(ctx context.Context, dataKey []byte) error {
276 var errs errSet
277
278 if !key.disableOpenPGP {
279 openpgpErr := key.encryptWithOpenPGP(dataKey)
280 if openpgpErr == nil {
281 log.WithField("fingerprint", key.Fingerprint).Info("Encryption succeeded")
282 return nil
283 }
284 errs = append(errs, fmt.Errorf("github.com/ProtonMail/go-crypto/openpgp error: %w", openpgpErr))
285 }
286
287 binaryErr := key.encryptWithGnuPG(ctx, dataKey)
288 if binaryErr == nil {
289 log.WithField("fingerprint", key.Fingerprint).Info("Encryption succeeded")
290 return nil
291 }
292 errs = append(errs, fmt.Errorf("GnuPG binary error: %w", binaryErr))
293
294 log.WithField("fingerprint", key.Fingerprint).Info("Encryption failed")
295 return fmt.Errorf("could not encrypt data key with PGP key: %w", errs)
296}
297
298// encryptWithOpenPGP attempts to encrypt the data key using OpenPGP with the
299// PGP key that belongs to Fingerprint. It sets EncryptedDataKey, or returns

Callers 1

EncryptMethod · 0.95

Calls 2

encryptWithOpenPGPMethod · 0.95
encryptWithGnuPGMethod · 0.95

Tested by

no test coverage detected