本文整理汇总了Golang中github.com/keybase/client/go/protocol.UID函数的典型用法代码示例。如果您正苦于以下问题:Golang UID函数的具体用法?Golang UID怎么用?Golang UID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: assertionToUIDLocked
func (k *KeybaseDaemonLocal) assertionToUIDLocked(ctx context.Context,
assertion string) (uid keybase1.UID, err error) {
expr, err := libkb.AssertionParseAndOnly(assertion)
if err != nil {
return keybase1.UID(""), err
}
urls := expr.CollectUrls(nil)
if len(urls) == 0 {
return keybase1.UID(""), errors.New("No assertion URLs")
}
for _, url := range urls {
var currUID keybase1.UID
if url.IsUID() {
currUID = url.ToUID()
} else {
key, val := url.ToKeyValuePair()
a := fmt.Sprintf("%[email protected]%s", val, key)
if url.IsKeybase() {
a = val
}
var ok bool
currUID, ok = k.asserts[a]
if !ok {
return keybase1.UID(""), NoSuchUserError{a}
}
}
if uid != keybase1.UID("") && currUID != uid {
return keybase1.UID(""),
errors.New("AND assertions resolve to different UIDs")
}
uid = currUID
}
return uid, nil
}
示例2: testIdentifyResolve2
func testIdentifyResolve2(t *testing.T, g *libkb.GlobalContext) {
cli, err := client.GetIdentifyClient(g)
if err != nil {
t.Fatalf("failed to get new identifyclient: %v", err)
}
if _, err := cli.Resolve(context.TODO(), "uid:eb72f49f2dde6429e5d78003dae0c919"); err != nil {
t.Fatalf("Resovle failed: %v\n", err)
}
// We don't want to hit the cache, since the previous lookup never hit the
// server. For Resolve2, we have to, since we need a username. So test that
// here.
if res, err := cli.Resolve2(context.TODO(), "uid:eb72f49f2dde6429e5d78003dae0c919"); err != nil {
t.Fatalf("Resovle failed: %v\n", err)
} else if res.Username != "t_tracy" {
t.Fatalf("Wrong username: %s != 't_tracy", res.Username)
}
if res, err := cli.Resolve2(context.TODO(), "[email protected]"); err != nil {
t.Fatalf("Resolve2 failed: %v\n", err)
} else if res.Username != "t_tracy" {
t.Fatalf("Wrong name: %s != 't_tracy", res.Username)
} else if !res.Uid.Equal(keybase1.UID("eb72f49f2dde6429e5d78003dae0c919")) {
t.Fatalf("Wrong uid for tracy: %s\n", res.Uid)
}
if _, err := cli.Resolve2(context.TODO(), "[email protected]"); err == nil {
t.Fatalf("expected an error on a bad resolve, but got none")
} else if _, ok := err.(libkb.ResolutionError); !ok {
t.Fatalf("Wrong error: wanted type %T but got (%v, %T)", libkb.ResolutionError{}, err, err)
}
}
示例3: testLoadAllPublicKeysUnverified
func testLoadAllPublicKeysUnverified(t *testing.T, g *libkb.GlobalContext) {
cli, err := client.GetUserClient(g)
if err != nil {
t.Fatalf("failed to get user client: %s", err)
}
// t_rosetta
arg := keybase1.LoadAllPublicKeysUnverifiedArg{Uid: keybase1.UID("b8939251cb3d367e68587acb33a64d19")}
res, err := cli.LoadAllPublicKeysUnverified(context.TODO(), arg)
if err != nil {
t.Fatalf("failed to make load keys call: %s", err)
}
if len(res) != 3 {
t.Fatalf("wrong amount of keys loaded: %d != %d", len(res), 3)
}
keys := map[keybase1.KID]bool{
keybase1.KID("0101fe1183765f256289427d6943cd8bab3b5fe095bcdd27f031ed298da523efd3120a"): true,
keybase1.KID("0101b5839c4ccaa9d03b3016b9aa73a7e3eafb067f9c86c07a6f2f79cb8558b1c97f0a"): true,
keybase1.KID("0101188ee7e63ccbd05af498772ab2975ee29df773240d17dde09aecf6c132a5a9a60a"): true,
}
for _, key := range res {
if _, ok := keys[key.KID]; !ok {
t.Fatalf("unknown key in response: %s", key.KID)
}
}
}
示例4: resolve
func (ra resolvableAssertion) resolve(ctx context.Context) (
nameUIDPair, keybase1.SocialAssertion, error) {
if ra.assertion == PublicUIDName {
return nameUIDPair{}, keybase1.SocialAssertion{}, fmt.Errorf("Invalid name %s", ra.assertion)
}
name, uid, err := ra.resolver.Resolve(ctx, ra.assertion)
if err == nil && ra.mustBeUser != keybase1.UID("") && ra.mustBeUser != uid {
// Force an unresolved assertion sinced the forced user doesn't match
err = NoSuchUserError{ra.assertion}
}
switch err := err.(type) {
default:
return nameUIDPair{}, keybase1.SocialAssertion{}, err
case nil:
return nameUIDPair{
name: name,
uid: uid,
}, keybase1.SocialAssertion{}, nil
case NoSuchUserError:
if !ra.sharingBeforeSignupEnabled {
return nameUIDPair{}, keybase1.SocialAssertion{}, err
}
socialAssertion, ok := libkb.NormalizeSocialAssertion(ra.assertion)
if !ok {
return nameUIDPair{}, keybase1.SocialAssertion{}, err
}
return nameUIDPair{}, socialAssertion, nil
}
}
示例5: genUID
func genUID(t *testing.T) keybase1.UID {
uid := make([]byte, 8)
if _, err := rand.Read(uid); err != nil {
t.Fatalf("rand failed: %v\n", err)
}
return keybase1.UID(hex.EncodeToString(uid))
}
示例6: Call
func (c *fakeKeybaseClient) Call(ctx context.Context, s string, args interface{},
res interface{}) error {
switch s {
case "keybase.1.session.currentSession":
*res.(*keybase1.Session) = keybase1.Session{
Uid: c.session.UID,
Username: "fake username",
Token: c.session.Token,
DeviceSubkeyKid: c.session.CryptPublicKey.kid,
DeviceSibkeyKid: c.session.VerifyingKey.kid,
}
c.currentSessionCalled = true
return nil
case "keybase.1.identify.identify2":
arg := args.([]interface{})[0].(keybase1.Identify2Arg)
uidStr := strings.TrimPrefix(arg.UserAssertion, "uid:")
if len(uidStr) == len(arg.UserAssertion) {
return fmt.Errorf("Non-uid assertion %s", arg.UserAssertion)
}
uid := keybase1.UID(uidStr)
userInfo, ok := c.users[uid]
if !ok {
return fmt.Errorf("Could not find user info for UID %s", uid)
}
*res.(*keybase1.Identify2Res) = keybase1.Identify2Res{
Upk: keybase1.UserPlusKeys{
Uid: uid,
Username: string(userInfo.Name),
},
}
c.identifyCalled = true
return nil
case "keybase.1.user.loadUserPlusKeys":
arg := args.([]interface{})[0].(keybase1.LoadUserPlusKeysArg)
userInfo, ok := c.users[arg.Uid]
if !ok {
return fmt.Errorf("Could not find user info for UID %s", arg.Uid)
}
*res.(*keybase1.UserPlusKeys) = keybase1.UserPlusKeys{
Uid: arg.Uid,
Username: string(userInfo.Name),
}
c.loadUserPlusKeysCalled = true
return nil
default:
return fmt.Errorf("Unknown call: %s %v %v", s, args, res)
}
}
示例7: Resolve
// Resolve implements the KeybaseDaemon interface for KeybaseDaemonRPC.
func (k *KeybaseDaemonRPC) Resolve(ctx context.Context, assertion string) (
libkb.NormalizedUsername, keybase1.UID, error) {
user, err := k.identifyClient.Resolve2(ctx, assertion)
if err != nil {
return libkb.NormalizedUsername(""), keybase1.UID(""),
convertIdentifyError(assertion, err)
}
return libkb.NewNormalizedUsername(user.Username), user.Uid, nil
}
示例8: GetCurrentUID
// GetCurrentUID implements the KBPKI interface for KBPKIClient.
func (k *KBPKIClient) GetCurrentUID(ctx context.Context) (keybase1.UID, error) {
s, err := k.session(ctx)
if err != nil {
// TODO: something more intelligent; maybe just shut down
// unless we want anonymous browsing of public data
return keybase1.UID(""), err
}
return s.UID, nil
}
示例9: Resolve
// Resolve implements KeybaseDaemon for KeybaseDaemonLocal.
func (k KeybaseDaemonLocal) Resolve(ctx context.Context, assertion string) (
keybase1.UID, error) {
uid, ok := k.asserts[assertion]
if !ok {
return keybase1.UID(""), NoSuchUserError{assertion}
}
return uid, nil
}
示例10: addNewAssertionForTest
// addNewAssertionForTest makes newAssertion, which should be a single
// assertion that doesn't already resolve to anything, resolve to the
// same UID as oldAssertion, which should be an arbitrary assertion
// that does already resolve to something. It returns the UID of the
// user associated with the given assertions.
func (k *KeybaseDaemonLocal) addNewAssertionForTest(
oldAssertion, newAssertion string) (keybase1.UID, error) {
k.lock.Lock()
defer k.lock.Unlock()
uid, err := k.assertionToUIDLocked(context.Background(), oldAssertion)
if err != nil {
return keybase1.UID(""), err
}
lu, err := k.localUsers.getLocalUser(uid)
if err != nil {
return keybase1.UID(""), err
}
lu.Asserts = append(lu.Asserts, newAssertion)
k.asserts[newAssertion] = uid
k.localUsers[uid] = lu
return uid, nil
}
示例11: GetCurrentUserInfo
// GetCurrentUserInfo implements the KBPKI interface for KBPKIClient.
func (k *KBPKIClient) GetCurrentUserInfo(ctx context.Context) (
libkb.NormalizedUsername, keybase1.UID, error) {
s, err := k.session(ctx)
if err != nil {
// TODO: something more intelligent; maybe just shut down
// unless we want anonymous browsing of public data
return libkb.NormalizedUsername(""), keybase1.UID(""), err
}
return s.Name, s.UID, nil
}
示例12: TestKBPKIClientIdentify
func TestKBPKIClientIdentify(t *testing.T) {
c, _, _ := makeTestKBPKIClient(t)
u, err := c.Identify(context.Background(), "test_name1", "")
if err != nil {
t.Fatal(err)
}
if u.UID == keybase1.UID("") {
t.Fatal("empty user")
}
}
示例13: Resolve
// Resolve implements KeybaseDaemon for KeybaseDaemonLocal.
func (k *KeybaseDaemonLocal) Resolve(ctx context.Context, assertion string) (
libkb.NormalizedUsername, keybase1.UID, error) {
k.lock.Lock()
defer k.lock.Unlock()
uid, err := k.assertionToUIDLocked(ctx, assertion)
if err != nil {
return libkb.NormalizedUsername(""), keybase1.UID(""), err
}
return k.localUsers[uid].Name, uid, nil
}
示例14: CurrentSession
// CurrentSession implements the KeybaseDaemon interface for KeybaseDaemonRPC.
func (k *KeybaseDaemonRPC) CurrentSession(ctx context.Context, sessionID int) (
SessionInfo, error) {
cachedCurrentSession := k.getCachedCurrentSession()
if cachedCurrentSession != (SessionInfo{}) {
return cachedCurrentSession, nil
}
res, err := k.sessionClient.CurrentSession(ctx, sessionID)
if err != nil {
if ncs := (NoCurrentSessionError{}); err.Error() ==
NoCurrentSessionExpectedError {
// Use an error with a proper OS error code attached to
// it. TODO: move ErrNoSession from client/go/service to
// client/go/libkb, so we can use types for the check
// above.
err = ncs
}
return SessionInfo{}, err
}
// Import the KIDs to validate them.
deviceSubkey, err := libkb.ImportKeypairFromKID(res.DeviceSubkeyKid)
if err != nil {
return SessionInfo{}, err
}
deviceSibkey, err := libkb.ImportKeypairFromKID(res.DeviceSibkeyKid)
if err != nil {
return SessionInfo{}, err
}
cryptPublicKey := MakeCryptPublicKey(deviceSubkey.GetKID())
verifyingKey := MakeVerifyingKey(deviceSibkey.GetKID())
s := SessionInfo{
Name: libkb.NewNormalizedUsername(res.Username),
UID: keybase1.UID(res.Uid),
Token: res.Token,
CryptPublicKey: cryptPublicKey,
VerifyingKey: verifyingKey,
}
k.log.CDebugf(
ctx, "new session with username %s, uid %s, crypt public key %s, and verifying key %s",
s.Name, s.UID, s.CryptPublicKey, s.VerifyingKey)
k.setCachedCurrentSession(s)
return s, nil
}
示例15: runTable
func (e *ListTrackingEngine) runTable(trackList TrackList) error {
for _, link := range trackList {
uid, err := link.GetTrackedUID()
if err != nil {
return err
}
entry := keybase1.UserSummary{
Username: link.ToDisplayString(),
SigIDDisplay: link.GetSigID().ToDisplayString(true),
TrackTime: keybase1.ToTime(link.GetCTime()),
Uid: keybase1.UID(uid),
}
entry.Proofs.PublicKeys = e.linkPGPKeys(link)
entry.Proofs.Social = e.linkSocialProofs(link)
entry.Proofs.Web = e.linkWebProofs(link)
e.tableResult = append(e.tableResult, entry)
}
return nil
}