This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 8
8
"io"
9
9
"strings"
10
10
11
+ "golang.org/x/crypto/openpgp"
12
+
11
13
"gopkg.in/src-d/go-git.v4/plumbing"
12
14
"gopkg.in/src-d/go-git.v4/plumbing/storer"
13
15
"gopkg.in/src-d/go-git.v4/utils/ioutil"
@@ -311,6 +313,34 @@ func (c *Commit) String() string {
311
313
)
312
314
}
313
315
316
+ // Verify performs PGP verification of the commit with a provided armored
317
+ // keyring and returns openpgp.Entity associated with verifying key on success.
318
+ func (c * Commit ) Verify (armoredKeyRing string ) (* openpgp.Entity , error ) {
319
+ keyRingReader := strings .NewReader (armoredKeyRing )
320
+ keyring , err := openpgp .ReadArmoredKeyRing (keyRingReader )
321
+ if err != nil {
322
+ return nil , err
323
+ }
324
+
325
+ // Extract signature.
326
+ signature := strings .NewReader (c .PGPSignature )
327
+
328
+ // Remove signature. Keep only the commit components.
329
+ c .PGPSignature = ""
330
+
331
+ // Encode commit and get a reader object.
332
+ encoded := & plumbing.MemoryObject {}
333
+ if err := c .Encode (encoded ); err != nil {
334
+ return nil , err
335
+ }
336
+ er , err := encoded .Reader ()
337
+ if err != nil {
338
+ return nil , err
339
+ }
340
+
341
+ return openpgp .CheckArmoredDetachedSignature (keyring , er , signature )
342
+ }
343
+
314
344
func indent (t string ) string {
315
345
var output []string
316
346
for _ , line := range strings .Split (t , "\n " ) {
You can’t perform that action at this time.
0 commit comments