diff options
author | Ori Rawlings <orirawlings@gmail.com> | 2017-11-24 17:38:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-24 17:38:51 -0500 |
commit | da62c676588f73cc6d1f05f621fead6890c65eea (patch) | |
tree | dff2708f4c2b9fcbb22e73a7fa14ca6a8041b8fc /plumbing/object/commit.go | |
parent | d92d437af0fb23865c79e45b4acd3d7544593260 (diff) | |
parent | e1ce83fcaf620db6a03026185617908a83dfe841 (diff) | |
download | go-git-da62c676588f73cc6d1f05f621fead6890c65eea.tar.gz |
Merge pull request #658 from darkowlzz/tag_sign_and_verify
plumbing: object/tag, add signature and verification support
Diffstat (limited to 'plumbing/object/commit.go')
-rw-r--r-- | plumbing/object/commit.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go index e54eb7d..a317714 100644 --- a/plumbing/object/commit.go +++ b/plumbing/object/commit.go @@ -223,6 +223,10 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) { // Encode transforms a Commit into a plumbing.EncodedObject. func (b *Commit) Encode(o plumbing.EncodedObject) error { + return b.encode(o, true) +} + +func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) error { o.SetType(plumbing.CommitObject) w, err := o.Writer() if err != nil { @@ -257,7 +261,7 @@ func (b *Commit) Encode(o plumbing.EncodedObject) error { return err } - if b.PGPSignature != "" { + if b.PGPSignature != "" && includeSig { if _, err = fmt.Fprint(w, "pgpsig"); err != nil { return err } @@ -325,12 +329,9 @@ func (c *Commit) Verify(armoredKeyRing string) (*openpgp.Entity, error) { // Extract signature. signature := strings.NewReader(c.PGPSignature) - // Remove signature. Keep only the commit components. - c.PGPSignature = "" - - // Encode commit and get a reader object. encoded := &plumbing.MemoryObject{} - if err := c.Encode(encoded); err != nil { + // Encode commit components, excluding signature and get a reader object. + if err := c.encode(encoded, false); err != nil { return nil, err } er, err := encoded.Reader() |