Verify performs PGP verification of the commit with a provided armored keyring and returns openpgp.Entity associated with verifying key on success.
(armoredKeyRing string)
| 496 | // Verify performs PGP verification of the commit with a provided armored |
| 497 | // keyring and returns openpgp.Entity associated with verifying key on success. |
| 498 | func (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 |