@@ -60,12 +60,28 @@ type AssertionUrl interface {
6060 ToString () string
6161 MatchSet (ps ProofSet ) bool
6262 MatchProof (p Proof ) bool
63+ ToKeyValuePair () (string , string )
64+ CacheKey () string
65+ GetValue () string
66+ ToLookup () (string , string , error )
6367}
6468
6569type AssertionUrlBase struct {
6670 Key , Value string
6771}
6872
73+ func (b AssertionUrlBase ) ToKeyValuePair () (string , string ) {
74+ return b .Key , b .Value
75+ }
76+
77+ func (b AssertionUrlBase ) CacheKey () string {
78+ return b .Key + ":" + b .Value
79+ }
80+
81+ func (b AssertionUrlBase ) GetValue () string {
82+ return b .Value
83+ }
84+
6985func (a AssertionUrlBase ) matchSet (v AssertionUrl , ps ProofSet ) bool {
7086 proofs := ps .Get (v .Keys ())
7187 for _ , proof := range proofs {
@@ -76,15 +92,18 @@ func (a AssertionUrlBase) matchSet(v AssertionUrl, ps ProofSet) bool {
7692 return false
7793}
7894
79- func (a AssertionKeybase ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
80- func (a AssertionWeb ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
81- func (a AssertionSocial ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
82- func (a AssertionHttp ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
83- func (a AssertionHttps ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
84- func (a AssertionDns ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
85- func (a AssertionFingerprint ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
86-
87- func (a AssertionWeb ) Keys () []string { return []string {"dns" , "http" , "https" } }
95+ func (a AssertionKeybase ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
96+ func (a AssertionWeb ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
97+ func (a AssertionSocial ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
98+ func (a AssertionHttp ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
99+ func (a AssertionHttps ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
100+ func (a AssertionDns ) MatchSet (ps ProofSet ) bool { return a .matchSet (a , ps ) }
101+ func (a AssertionFingerprint ) MatchSet (ps ProofSet ) bool {
102+ return a .matchSet (a , ps )
103+ }
104+ func (a AssertionWeb ) Keys () []string {
105+ return []string {"dns" , "http" , "https" }
106+ }
88107func (a AssertionHttp ) Keys () []string { return []string {"http" , "https" } }
89108func (a AssertionUrlBase ) Keys () []string { return []string {a .Key } }
90109func (a AssertionUrlBase ) IsKeybase () bool { return false }
@@ -141,16 +160,54 @@ func (a AssertionUrlBase) ToString() string {
141160 return fmt .Sprintf ("%s://%s" , a .Key , a .Value )
142161}
143162
144- func parseToKVPair (s string ) (key string , value string ) {
145- colon := strings .IndexByte (s , byte (':' ))
146- if colon < 0 {
147- value = s
163+ func (k AssertionWeb ) ToLookup () (key , value string , err error ) {
164+ return "web" , k .Value , nil
165+ }
166+ func (k AssertionHttp ) ToLookup () (key , value string , err error ) {
167+ return "http" , k .Value , nil
168+ }
169+ func (k AssertionHttps ) ToLookup () (key , value string , err error ) {
170+ return "https" , k .Value , nil
171+ }
172+ func (k AssertionDns ) ToLookup () (key , value string , err error ) {
173+ return "dns" , k .Value , nil
174+ }
175+ func (k AssertionFingerprint ) ToLookup () (key , value string , err error ) {
176+ cmp := len (k .Value ) - PGP_FINGERPRINT_HEX_LEN
177+ value = k .Value
178+ if len (k .Value ) < 4 {
179+ err = fmt .Errorf ("fingerprint queries must be at least 2 bytes long" )
180+ } else if cmp == 0 {
181+ key = "key_fingerprint"
182+ } else if cmp < 0 {
183+ key = "key_suffix"
148184 } else {
185+ err = fmt .Errorf ("bad fingerprint; too long: %s" , k .Value )
186+ }
187+ return
188+ }
189+
190+ func parseToKVPair (s string ) (key string , value string , err error ) {
191+
192+ re := regexp .MustCompile (`^[0-9a-zA-Z@:/_-]` )
193+ if ! re .MatchString (s ) {
194+ err = fmt .Errorf ("Invalid key-value identity: %s" , s )
195+ return
196+ }
197+
198+ colon := strings .IndexByte (s , byte (':' ))
199+ atsign := strings .IndexByte (s , byte ('@' ))
200+ if colon >= 0 {
149201 key = s [0 :colon ]
150202 value = s [(colon + 1 ):]
151203 if len (value ) >= 2 && value [0 :2 ] == "//" {
152204 value = value [2 :]
153205 }
206+ } else if atsign >= 0 {
207+ value = s [0 :atsign ]
208+ key = s [(atsign + 1 ):]
209+ } else {
210+ value = s
154211 }
155212 key = strings .ToLower (key )
156213 value = strings .ToLower (value )
@@ -161,6 +218,10 @@ func (k AssertionKeybase) IsKeybase() bool {
161218 return true
162219}
163220
221+ func (k AssertionKeybase ) ToLookup () (key , value string , err error ) {
222+ return "username" , k .Value , nil
223+ }
224+
164225func (s AssertionSocial ) Check () (err error ) {
165226 networks := map [string ]bool {
166227 "github" : true ,
@@ -176,12 +237,26 @@ func (s AssertionSocial) Check() (err error) {
176237 return
177238}
178239
240+ func (k AssertionSocial ) ToLookup () (key , value string , err error ) {
241+ return k .Key , k .Value , nil
242+ }
243+
179244func ParseAssertionUrl (s string , strict bool ) (ret AssertionUrl , err error ) {
180- key , val := parseToKVPair (s )
245+ key , val , err := parseToKVPair (s )
246+
247+ if err != nil {
248+ return
249+ }
250+ return ParseAssertionUrlKeyValue (key , val , strict )
251+ }
252+
253+ func ParseAssertionUrlKeyValue (key , val string ,
254+ strict bool ) (ret AssertionUrl , err error ) {
181255
182256 if len (key ) == 0 {
183257 if strict {
184- err = fmt .Errorf ("Bad assertion, no 'type' given: %s" , s )
258+ err = fmt .Errorf ("Bad assertion, no 'type' given: %s" , val )
259+ return
185260 } else {
186261 key = "keybase"
187262 }
0 commit comments