aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorSunny <me@darkowlzz.space>2017-11-24 19:19:44 +0530
committerSunny <me@darkowlzz.space>2017-11-24 19:19:44 +0530
commit850b9f81c2f025d8a75c4728520553504e3a425c (patch)
tree6bbeaef3ca37822e1171c16aefe52e6e96f89a94 /plumbing
parentd92d437af0fb23865c79e45b4acd3d7544593260 (diff)
downloadgo-git-850b9f81c2f025d8a75c4728520553504e3a425c.tar.gz
plumbing: object/tag, add PGPSignature support
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/tag.go44
-rw-r--r--plumbing/object/tag_test.go26
2 files changed, 69 insertions, 1 deletions
diff --git a/plumbing/object/tag.go b/plumbing/object/tag.go
index d8b71a0..6295205 100644
--- a/plumbing/object/tag.go
+++ b/plumbing/object/tag.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
stdioutil "io/ioutil"
+ "strings"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
@@ -30,6 +31,8 @@ type Tag struct {
Tagger Signature
// Message is an arbitrary text message.
Message string
+ // PGPSignature is the PGP signature of the tag.
+ PGPSignature string
// TargetType is the object type of the target.
TargetType plumbing.ObjectType
// Target is the hash of the target object.
@@ -124,7 +127,36 @@ func (t *Tag) Decode(o plumbing.EncodedObject) (err error) {
if err != nil {
return err
}
- t.Message = string(data)
+
+ var pgpsig bool
+ // Check if data contains PGP signature.
+ if bytes.Contains(data, []byte(beginpgp)) {
+ // Split the lines at newline.
+ messageAndSig := bytes.Split(data, []byte("\n"))
+
+ for _, l := range messageAndSig {
+ if pgpsig {
+ if bytes.Contains(l, []byte(endpgp)) {
+ t.PGPSignature += endpgp + "\n"
+ pgpsig = false
+ } else {
+ t.PGPSignature += string(l) + "\n"
+ }
+ continue
+ }
+
+ // Check if it's the beginning of a PGP signature.
+ if bytes.Contains(l, []byte(beginpgp)) {
+ t.PGPSignature += beginpgp + "\n"
+ pgpsig = true
+ continue
+ }
+
+ t.Message += string(l) + "\n"
+ }
+ } else {
+ t.Message = string(data)
+ }
return nil
}
@@ -156,6 +188,16 @@ func (t *Tag) Encode(o plumbing.EncodedObject) error {
return err
}
+ if t.PGPSignature != "" {
+ // Split all the signature lines and write with a newline at the end.
+ lines := strings.Split(t.PGPSignature, "\n")
+ for _, line := range lines {
+ if _, err = fmt.Fprintf(w, "%s\n", line); err != nil {
+ return err
+ }
+ }
+ }
+
return err
}
diff --git a/plumbing/object/tag_test.go b/plumbing/object/tag_test.go
index 608fe72..edd23f5 100644
--- a/plumbing/object/tag_test.go
+++ b/plumbing/object/tag_test.go
@@ -285,3 +285,29 @@ func (s *TagSuite) TestLongTagNameSerialization(c *C) {
c.Assert(err, IsNil)
c.Assert(decoded.Name, Equals, longName)
}
+
+func (s *TagSuite) TestPGPSignatureSerialization(c *C) {
+ encoded := &plumbing.MemoryObject{}
+ decoded := &Tag{}
+ tag := s.tag(c, plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69"))
+
+ pgpsignature := `-----BEGIN PGP SIGNATURE-----
+
+iQEcBAABAgAGBQJTZbQlAAoJEF0+sviABDDrZbQH/09PfE51KPVPlanr6q1v4/Ut
+LQxfojUWiLQdg2ESJItkcuweYg+kc3HCyFejeDIBw9dpXt00rY26p05qrpnG+85b
+hM1/PswpPLuBSr+oCIDj5GMC2r2iEKsfv2fJbNW8iWAXVLoWZRF8B0MfqX/YTMbm
+ecorc4iXzQu7tupRihslbNkfvfciMnSDeSvzCpWAHl7h8Wj6hhqePmLm9lAYqnKp
+8S5B/1SSQuEAjRZgI4IexpZoeKGVDptPHxLLS38fozsyi0QyDyzEgJxcJQVMXxVi
+RUysgqjcpT8+iQM1PblGfHR4XAhuOqN5Fx06PSaFZhqvWFezJ28/CLyX5q+oIVk=
+=EFTF
+-----END PGP SIGNATURE-----
+`
+ tag.PGPSignature = pgpsignature
+
+ err := tag.Encode(encoded)
+ c.Assert(err, IsNil)
+
+ err = decoded.Decode(encoded)
+ c.Assert(err, IsNil)
+ c.Assert(decoded.PGPSignature, Equals, pgpsignature)
+}