MCPcopy Index your code
hub / github.com/go-git/go-git / Verify

Method Verify

plumbing/object/commit.go:498–523  ·  view source on GitHub ↗

Verify performs PGP verification of the commit with a provided armored keyring and returns openpgp.Entity associated with verifying key on success.

(armoredKeyRing string)

Source from the content-addressed store, hash-verified

496// Verify performs PGP verification of the commit with a provided armored
497// keyring and returns openpgp.Entity associated with verifying key on success.
498func (c *Commit) Verify(armoredKeyRing string) (*openpgp.Entity, error) {
499 if countSignatureBlocks([]byte(c.PGPSignature)) > 1 {
500 return nil, ErrMultipleSignatures
501 }
502
503 keyRingReader := strings.NewReader(armoredKeyRing)
504 keyring, err := openpgp.ReadArmoredKeyRing(keyRingReader)
505 if err != nil {
506 return nil, err
507 }
508
509 // Extract signature.
510 signature := strings.NewReader(c.PGPSignature)
511
512 encoded := &plumbing.MemoryObject{}
513 // Encode commit components, excluding signature and get a reader object.
514 if err := c.EncodeWithoutSignature(encoded); err != nil {
515 return nil, err
516 }
517 er, err := encoded.Reader()
518 if err != nil {
519 return nil, err
520 }
521
522 return openpgp.CheckArmoredDetachedSignature(keyring, er, signature, nil)
523}
524
525// Less defines a compare function to determine which commit is 'earlier' by:
526// - First use Committer.When

Callers 1

TestVerifyMethod · 0.95

Calls 3

ReaderMethod · 0.95
countSignatureBlocksFunction · 0.85

Tested by 1

TestVerifyMethod · 0.76