aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny <me@darkowlzz.space>2017-11-24 23:30:34 +0530
committerSunny <me@darkowlzz.space>2017-11-24 23:34:11 +0530
commite1ce83fcaf620db6a03026185617908a83dfe841 (patch)
treedff2708f4c2b9fcbb22e73a7fa14ca6a8041b8fc
parente2dbd3a4f6ec8c6467eb1bc30ed937399a4456e4 (diff)
downloadgo-git-e1ce83fcaf620db6a03026185617908a83dfe841.tar.gz
plumbing: object/{commit,tag}, encode method with sig optional
Adds Commit.encode() and Tag.encode() with optional `includeSig` parameter to include or exclude signature from the encoded object.
-rw-r--r--plumbing/object/commit.go13
-rw-r--r--plumbing/object/tag.go12
2 files changed, 14 insertions, 11 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()
diff --git a/plumbing/object/tag.go b/plumbing/object/tag.go
index 9b4250f..19e55cf 100644
--- a/plumbing/object/tag.go
+++ b/plumbing/object/tag.go
@@ -165,6 +165,10 @@ func (t *Tag) Decode(o plumbing.EncodedObject) (err error) {
// Encode transforms a Tag into a plumbing.EncodedObject.
func (t *Tag) Encode(o plumbing.EncodedObject) error {
+ return t.encode(o, true)
+}
+
+func (t *Tag) encode(o plumbing.EncodedObject, includeSig bool) error {
o.SetType(plumbing.TagObject)
w, err := o.Writer()
if err != nil {
@@ -190,7 +194,7 @@ func (t *Tag) Encode(o plumbing.EncodedObject) error {
return err
}
- if t.PGPSignature != "" {
+ if t.PGPSignature != "" && includeSig {
// Split all the signature lines and write with a newline at the end.
lines := strings.Split(t.PGPSignature, "\n")
for _, line := range lines {
@@ -281,11 +285,9 @@ func (t *Tag) Verify(armoredKeyRing string) (*openpgp.Entity, error) {
// Extract signature.
signature := strings.NewReader(t.PGPSignature)
- // Remove signature. Keep only the tag components.
- t.PGPSignature = ""
-
encoded := &plumbing.MemoryObject{}
- if err := t.Encode(encoded); err != nil {
+ // Encode tag components, excluding signature and get a reader object.
+ if err := t.encode(encoded, false); err != nil {
return nil, err
}
er, err := encoded.Reader()