Verify performs PGP verification of the commit with a provided armored keyring and returns openpgp.Entity associated with verifying key on success.
(armoredKeyRing string)
| 409 | // Verify performs PGP verification of the commit with a provided armored |
| 410 | // keyring and returns openpgp.Entity associated with verifying key on success. |
| 411 | func (c *Commit) Verify(armoredKeyRing string) (*openpgp.Entity, error) { |
| 412 | keyRingReader := strings.NewReader(armoredKeyRing) |
| 413 | keyring, err := openpgp.ReadArmoredKeyRing(keyRingReader) |
| 414 | if err != nil { |
| 415 | return nil, err |
| 416 | } |
| 417 | |
| 418 | // Extract signature. |
| 419 | signature := strings.NewReader(c.PGPSignature) |
| 420 | |
| 421 | encoded := &plumbing.MemoryObject{} |
| 422 | // Encode commit components, excluding signature and get a reader object. |
| 423 | if err := c.EncodeWithoutSignature(encoded); err != nil { |
| 424 | return nil, err |
| 425 | } |
| 426 | er, err := encoded.Reader() |
| 427 | if err != nil { |
| 428 | return nil, err |
| 429 | } |
| 430 | |
| 431 | return openpgp.CheckArmoredDetachedSignature(keyring, er, signature, nil) |
| 432 | } |
| 433 | |
| 434 | // Less defines a compare function to determine which commit is 'earlier' by: |
| 435 | // - First use Committer.When |