Skip to content

Commit

Permalink
Find GPG payload in commit data
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Oct 13, 2016
1 parent 88b15e3 commit 6309a1e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ l:
return nil, err
}
commit.Committer = sig
case "gpgsig":
verif, err := newVerificationFromCommitline(data[nextline+spacepos+1:])
if err != nil {
return nil, err
}
commit.Verification = verif
}
nextline += eol + 1
case eol == 0:
Expand Down
32 changes: 32 additions & 0 deletions verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

package git

import (
"bytes"
)

// Verification represents the PGP payload information of a signed commit.
type Verification struct {
Verified bool
Expand All @@ -12,3 +16,31 @@ type Verification struct {
Payload string
}

// Helper to get verification data from the commit inforamtion, which looks like these:
//gpgsig -----BEGIN PGP SIGNATURE-----
// Version: GnuPG v2
//
// iQIcBAABCAAGBQJXD4OAAAoJEFYV4RsDRH59URsP/1on/dZKWKQQeogZVe1F1Yi/
// vvmvhEkOIaGhFREi7GA5LLyOonKbTmYoH5/xCuZvOJIp5/KbR5qpdahhfT1J/9fh
// iJAIm6MDSXAAiRMASLQVcwBmJTweOwm5LaKZxdY70s8WWqnN4hQt1irodzxpikLl
// EQ2rfbvfOP4/MDYkQUI1Yvb3e+cNK2o0R1DjFbfSE5xX9X+miqnOjIvmBZ7vL3Hp
// GhxJ9dtGyhM7vsGiWk42dCbOnJshCeJnCZIeXKH6Xlo6EJnwiGAvFUy4UQP7bhzO
// ZgE+leWrUiyPs7P1OYIMV6sXPpMZmKh/UVOjEmxzbC8P6/ye5pURYZpkB70P7d2w
// bbxnLmVDK+pIedAdY3VWOhrAg26Jmq/i51un+OsYet3rpPOPC9Q9WzRg/s9aMg+S
// hLle77kjzAqK2m38qIJjVRZFFRM00WW4GnbmSu1xJw125jEfNnqjS5CfioQ+MyYN
// 9ARfLk4hTe5gZ/jgJ8AFQWygEruQxzUAkZLgeFt6TbOm5HSmTh2OpSJCupwJjwNu
// iMXQ0gLF99rUs5vtEXqDs5xfEYxdb1H/dDe++Of+NDcXcoJE4LtdK9kP8/ilYiBu
// MlShuryaeNtdNB6javCBA1mXwI7WIOhYlFzaNQ3KW2+vTA3VjiGJLB5jjYGmgrpz
// 0SuOoRPfFT3QY4xrOXIR
// =aEJU
// -----END PGP SIGNATURE-----
// but without the "gpgsig " at the beginning
//
func newVerificationFromCommitline(line []byte) (_ *Verification, err error) {
verif := new(Verification)

signatureEnd := bytes.LastIndex(line, []byte("-----END PGP SIGNATURE-----"))
verif.Signature = string(line[:signatureEnd+27])

return verif, nil
}

0 comments on commit 6309a1e

Please sign in to comment.