forked from keybase/client
/
social_assertion.go
33 lines (29 loc) · 1.14 KB
/
social_assertion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package libkb
import (
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
// IsSocialAssertion returns true for strings that are valid
// social assertions. They do not need to be normalized, so
// user@twitter and twitter:user will work, as will
// USER@Twitter.
func IsSocialAssertion(ctx AssertionContext, s string) bool {
_, ok := NormalizeSocialAssertion(ctx, s)
return ok
}
// NormalizeSocialAssertion creates a SocialAssertion from its
// input and normalizes it. The service name will be lowercased.
// If the service is case-insensitive, then the username will also
// be lowercased. Colon assertions (twitter:user) will be
// transformed to the user@twitter format.
func NormalizeSocialAssertion(ctx AssertionContext, s string) (keybase1.SocialAssertion, bool) {
url, err := ParseAssertionURL(ctx, s, true)
if err != nil || !url.IsRemote() {
return keybase1.SocialAssertion{}, false
}
return keybase1.SocialAssertion{
User: url.GetValue(),
Service: keybase1.SocialAssertionService(url.GetKey()),
}, true
}