Matching short/long GPG key IDs. #71

This commit is contained in:
Andrey Smirnov
2015-03-19 00:25:54 +03:00
parent c53060d95a
commit c4692bec3d
2 changed files with 37 additions and 0 deletions

View File

@@ -42,6 +42,23 @@ var (
// GpgKey is key in GPG representation
type GpgKey string
// Matches checks two keys for equality
func (key1 GpgKey) Matches(key2 GpgKey) bool {
if key1 == key2 {
return true
}
if len(key1) == 8 && len(key2) == 16 {
return key1 == key2[8:]
}
if len(key1) == 16 && len(key2) == 8 {
return key1[8:] == key2
}
return false
}
// GpgKeyInfo is response from signature verification
type GpgKeyInfo struct {
GoodKeys []GpgKey

20
utils/gpg_test.go Normal file
View File

@@ -0,0 +1,20 @@
package utils
import (
. "gopkg.in/check.v1"
)
type GpgSuite struct{}
var _ = Suite(&GpgSuite{})
func (s *GpgSuite) TestGpgKeyMatch(c *C) {
c.Check(GpgKey("EC4B033C70096AD1").Matches(GpgKey("EC4B033C70096AD1")), Equals, true)
c.Check(GpgKey("37E1C17570096AD1").Matches(GpgKey("EC4B033C70096AD1")), Equals, false)
c.Check(GpgKey("70096AD1").Matches(GpgKey("70096AD1")), Equals, true)
c.Check(GpgKey("70096AD1").Matches(GpgKey("EC4B033C")), Equals, false)
c.Check(GpgKey("37E1C17570096AD1").Matches(GpgKey("70096AD1")), Equals, true)
c.Check(GpgKey("70096AD1").Matches(GpgKey("EC4B033C70096AD1")), Equals, true)
}