Skip to content

Commit 6309a1e

Browse files
committed
Find GPG payload in commit data
1 parent 88b15e3 commit 6309a1e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

repo_commit.go

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ l:
7878
return nil, err
7979
}
8080
commit.Committer = sig
81+
case "gpgsig":
82+
verif, err := newVerificationFromCommitline(data[nextline+spacepos+1:])
83+
if err != nil {
84+
return nil, err
85+
}
86+
commit.Verification = verif
8187
}
8288
nextline += eol + 1
8389
case eol == 0:

verification.go

+32
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
package git
66

7+
import (
8+
"bytes"
9+
)
10+
711
// Verification represents the PGP payload information of a signed commit.
812
type Verification struct {
913
Verified bool
@@ -12,3 +16,31 @@ type Verification struct {
1216
Payload string
1317
}
1418

19+
// Helper to get verification data from the commit inforamtion, which looks like these:
20+
//gpgsig -----BEGIN PGP SIGNATURE-----
21+
// Version: GnuPG v2
22+
//
23+
// iQIcBAABCAAGBQJXD4OAAAoJEFYV4RsDRH59URsP/1on/dZKWKQQeogZVe1F1Yi/
24+
// vvmvhEkOIaGhFREi7GA5LLyOonKbTmYoH5/xCuZvOJIp5/KbR5qpdahhfT1J/9fh
25+
// iJAIm6MDSXAAiRMASLQVcwBmJTweOwm5LaKZxdY70s8WWqnN4hQt1irodzxpikLl
26+
// EQ2rfbvfOP4/MDYkQUI1Yvb3e+cNK2o0R1DjFbfSE5xX9X+miqnOjIvmBZ7vL3Hp
27+
// GhxJ9dtGyhM7vsGiWk42dCbOnJshCeJnCZIeXKH6Xlo6EJnwiGAvFUy4UQP7bhzO
28+
// ZgE+leWrUiyPs7P1OYIMV6sXPpMZmKh/UVOjEmxzbC8P6/ye5pURYZpkB70P7d2w
29+
// bbxnLmVDK+pIedAdY3VWOhrAg26Jmq/i51un+OsYet3rpPOPC9Q9WzRg/s9aMg+S
30+
// hLle77kjzAqK2m38qIJjVRZFFRM00WW4GnbmSu1xJw125jEfNnqjS5CfioQ+MyYN
31+
// 9ARfLk4hTe5gZ/jgJ8AFQWygEruQxzUAkZLgeFt6TbOm5HSmTh2OpSJCupwJjwNu
32+
// iMXQ0gLF99rUs5vtEXqDs5xfEYxdb1H/dDe++Of+NDcXcoJE4LtdK9kP8/ilYiBu
33+
// MlShuryaeNtdNB6javCBA1mXwI7WIOhYlFzaNQ3KW2+vTA3VjiGJLB5jjYGmgrpz
34+
// 0SuOoRPfFT3QY4xrOXIR
35+
// =aEJU
36+
// -----END PGP SIGNATURE-----
37+
// but without the "gpgsig " at the beginning
38+
//
39+
func newVerificationFromCommitline(line []byte) (_ *Verification, err error) {
40+
verif := new(Verification)
41+
42+
signatureEnd := bytes.LastIndex(line, []byte("-----END PGP SIGNATURE-----"))
43+
verif.Signature = string(line[:signatureEnd+27])
44+
45+
return verif, nil
46+
}

0 commit comments

Comments
 (0)