mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-10 06:14:22 +00:00
Matching short/long GPG key IDs. #71
This commit is contained in:
@@ -42,6 +42,23 @@ var (
|
|||||||
// GpgKey is key in GPG representation
|
// GpgKey is key in GPG representation
|
||||||
type GpgKey string
|
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
|
// GpgKeyInfo is response from signature verification
|
||||||
type GpgKeyInfo struct {
|
type GpgKeyInfo struct {
|
||||||
GoodKeys []GpgKey
|
GoodKeys []GpgKey
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user