id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
159,700 | keybase/client | go/auth/credential_authority.go | pollOnce | func (v *CredentialAuthority) pollOnce() error {
var err error
var uids []keybase1.UID
err = v.runWithCancel(func(ctx context.Context) error {
var err error
uids, err = v.api.PollForChanges(ctx)
return err
})
if err == nil {
for _, uid := range uids {
v.invalidateCh <- uid
}
}
return err
} | go | func (v *CredentialAuthority) pollOnce() error {
var err error
var uids []keybase1.UID
err = v.runWithCancel(func(ctx context.Context) error {
var err error
uids, err = v.api.PollForChanges(ctx)
return err
})
if err == nil {
for _, uid := range uids {
v.invalidateCh <- uid
}
}
return err
} | [
"func",
"(",
"v",
"*",
"CredentialAuthority",
")",
"pollOnce",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"uids",
"[",
"]",
"keybase1",
".",
"UID",
"\n",
"err",
"=",
"v",
".",
"runWithCancel",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"uids",
",",
"err",
"=",
"v",
".",
"api",
".",
"PollForChanges",
"(",
"ctx",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"uid",
":=",
"range",
"uids",
"{",
"v",
".",
"invalidateCh",
"<-",
"uid",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // pollOnce polls the API server once for which users have changed. | [
"pollOnce",
"polls",
"the",
"API",
"server",
"once",
"for",
"which",
"users",
"have",
"changed",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L197-L211 |
159,701 | keybase/client | go/auth/credential_authority.go | makeUser | func (v *CredentialAuthority) makeUser(uid keybase1.UID) *user {
uw := v.users[uid]
if uw == nil {
u := newUser(uid, v)
uw = &userWrapper{u: u}
v.users[uid] = uw
}
uw.atime = v.eng.Now()
return uw.u
} | go | func (v *CredentialAuthority) makeUser(uid keybase1.UID) *user {
uw := v.users[uid]
if uw == nil {
u := newUser(uid, v)
uw = &userWrapper{u: u}
v.users[uid] = uw
}
uw.atime = v.eng.Now()
return uw.u
} | [
"func",
"(",
"v",
"*",
"CredentialAuthority",
")",
"makeUser",
"(",
"uid",
"keybase1",
".",
"UID",
")",
"*",
"user",
"{",
"uw",
":=",
"v",
".",
"users",
"[",
"uid",
"]",
"\n",
"if",
"uw",
"==",
"nil",
"{",
"u",
":=",
"newUser",
"(",
"uid",
",",
"v",
")",
"\n",
"uw",
"=",
"&",
"userWrapper",
"{",
"u",
":",
"u",
"}",
"\n",
"v",
".",
"users",
"[",
"uid",
"]",
"=",
"uw",
"\n",
"}",
"\n",
"uw",
".",
"atime",
"=",
"v",
".",
"eng",
".",
"Now",
"(",
")",
"\n",
"return",
"uw",
".",
"u",
"\n",
"}"
] | // makeUser either pulls a user from the in-memory table, or constructs a new
// one. In either case, it updates the CA's `atime` bit for now for this user
// record. | [
"makeUser",
"either",
"pulls",
"a",
"user",
"from",
"the",
"in",
"-",
"memory",
"table",
"or",
"constructs",
"a",
"new",
"one",
".",
"In",
"either",
"case",
"it",
"updates",
"the",
"CA",
"s",
"atime",
"bit",
"for",
"now",
"for",
"this",
"user",
"record",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L299-L308 |
159,702 | keybase/client | go/auth/credential_authority.go | repopulate | func (u *user) repopulate() error {
if u.isPopulated() {
return nil
}
// Register that this item should eventually be cleaned out by the cleaner
// thread. Don't block on the send, though, since that could deadlock the process
// (since the process is blocked on sending to us).
ctime := u.Now()
go func() {
u.ca.cleanItemCh <- cleanItem{uid: u.uid, ctime: ctime}
}()
un, sibkeys, subkeys, isDeleted, err := u.ca.getUserFromServer(u.uid)
if err != nil {
u.isOK = false
return err
}
u.username = un
for _, k := range sibkeys {
u.sibkeys[k] = struct{}{}
}
for _, k := range subkeys {
u.subkeys[k] = struct{}{}
}
u.isOK = true
u.ctime = ctime
u.isDeleted = isDeleted
u.ca.log.Debug("Repopulated info for %s", u)
return nil
} | go | func (u *user) repopulate() error {
if u.isPopulated() {
return nil
}
// Register that this item should eventually be cleaned out by the cleaner
// thread. Don't block on the send, though, since that could deadlock the process
// (since the process is blocked on sending to us).
ctime := u.Now()
go func() {
u.ca.cleanItemCh <- cleanItem{uid: u.uid, ctime: ctime}
}()
un, sibkeys, subkeys, isDeleted, err := u.ca.getUserFromServer(u.uid)
if err != nil {
u.isOK = false
return err
}
u.username = un
for _, k := range sibkeys {
u.sibkeys[k] = struct{}{}
}
for _, k := range subkeys {
u.subkeys[k] = struct{}{}
}
u.isOK = true
u.ctime = ctime
u.isDeleted = isDeleted
u.ca.log.Debug("Repopulated info for %s", u)
return nil
} | [
"func",
"(",
"u",
"*",
"user",
")",
"repopulate",
"(",
")",
"error",
"{",
"if",
"u",
".",
"isPopulated",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Register that this item should eventually be cleaned out by the cleaner",
"// thread. Don't block on the send, though, since that could deadlock the process",
"// (since the process is blocked on sending to us).",
"ctime",
":=",
"u",
".",
"Now",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"u",
".",
"ca",
".",
"cleanItemCh",
"<-",
"cleanItem",
"{",
"uid",
":",
"u",
".",
"uid",
",",
"ctime",
":",
"ctime",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"un",
",",
"sibkeys",
",",
"subkeys",
",",
"isDeleted",
",",
"err",
":=",
"u",
".",
"ca",
".",
"getUserFromServer",
"(",
"u",
".",
"uid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"isOK",
"=",
"false",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"u",
".",
"username",
"=",
"un",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"sibkeys",
"{",
"u",
".",
"sibkeys",
"[",
"k",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"subkeys",
"{",
"u",
".",
"subkeys",
"[",
"k",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"u",
".",
"isOK",
"=",
"true",
"\n",
"u",
".",
"ctime",
"=",
"ctime",
"\n",
"u",
".",
"isDeleted",
"=",
"isDeleted",
"\n",
"u",
".",
"ca",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"u",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // repopulate is intended to repopulate our representation of the user with the
// server's up-to-date notion of what the user looks like. If our version is recent
// enough, this is a no-op. If not, we'll go to the server and send the main loop
// a "Cleanup" event to eventually clean us out. | [
"repopulate",
"is",
"intended",
"to",
"repopulate",
"our",
"representation",
"of",
"the",
"user",
"with",
"the",
"server",
"s",
"up",
"-",
"to",
"-",
"date",
"notion",
"of",
"what",
"the",
"user",
"looks",
"like",
".",
"If",
"our",
"version",
"is",
"recent",
"enough",
"this",
"is",
"a",
"no",
"-",
"op",
".",
"If",
"not",
"we",
"ll",
"go",
"to",
"the",
"server",
"and",
"send",
"the",
"main",
"loop",
"a",
"Cleanup",
"event",
"to",
"eventually",
"clean",
"us",
"out",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L348-L378 |
159,703 | keybase/client | go/auth/credential_authority.go | isPopulated | func (u *user) isPopulated() bool {
return u.isOK && u.Now().Sub(u.ctime) <= userTimeout
} | go | func (u *user) isPopulated() bool {
return u.isOK && u.Now().Sub(u.ctime) <= userTimeout
} | [
"func",
"(",
"u",
"*",
"user",
")",
"isPopulated",
"(",
")",
"bool",
"{",
"return",
"u",
".",
"isOK",
"&&",
"u",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"u",
".",
"ctime",
")",
"<=",
"userTimeout",
"\n",
"}"
] | // isPopulated returned true if this user is populated and current enough to
// trust. | [
"isPopulated",
"returned",
"true",
"if",
"this",
"user",
"is",
"populated",
"and",
"current",
"enough",
"to",
"trust",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L382-L384 |
159,704 | keybase/client | go/auth/credential_authority.go | check | func (u *user) check(ca checkArg) {
var err error
defer func() {
u.ca.log.Debug("Check %s, err: %v", ca, err)
ca.retCh <- err
}()
if err = u.repopulate(); err != nil {
return
}
if !ca.loadDeleted && u.isDeleted {
err = ErrUserDeleted
return
}
if ca.username != nil {
if err = u.checkUsername(*ca.username); err != nil {
return
}
}
if ca.kid != nil {
if err = u.checkKey(*ca.kid); err != nil {
return
}
}
if ca.sibkeys != nil {
if err = u.compareSibkeys(ca.sibkeys); err != nil {
return
}
}
if ca.subkeys != nil {
if err = u.compareSubkeys(ca.subkeys); err != nil {
return
}
}
} | go | func (u *user) check(ca checkArg) {
var err error
defer func() {
u.ca.log.Debug("Check %s, err: %v", ca, err)
ca.retCh <- err
}()
if err = u.repopulate(); err != nil {
return
}
if !ca.loadDeleted && u.isDeleted {
err = ErrUserDeleted
return
}
if ca.username != nil {
if err = u.checkUsername(*ca.username); err != nil {
return
}
}
if ca.kid != nil {
if err = u.checkKey(*ca.kid); err != nil {
return
}
}
if ca.sibkeys != nil {
if err = u.compareSibkeys(ca.sibkeys); err != nil {
return
}
}
if ca.subkeys != nil {
if err = u.compareSubkeys(ca.subkeys); err != nil {
return
}
}
} | [
"func",
"(",
"u",
"*",
"user",
")",
"check",
"(",
"ca",
"checkArg",
")",
"{",
"var",
"err",
"error",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"u",
".",
"ca",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"ca",
",",
"err",
")",
"\n",
"ca",
".",
"retCh",
"<-",
"err",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"err",
"=",
"u",
".",
"repopulate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"!",
"ca",
".",
"loadDeleted",
"&&",
"u",
".",
"isDeleted",
"{",
"err",
"=",
"ErrUserDeleted",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"ca",
".",
"username",
"!=",
"nil",
"{",
"if",
"err",
"=",
"u",
".",
"checkUsername",
"(",
"*",
"ca",
".",
"username",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"ca",
".",
"kid",
"!=",
"nil",
"{",
"if",
"err",
"=",
"u",
".",
"checkKey",
"(",
"*",
"ca",
".",
"kid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"ca",
".",
"sibkeys",
"!=",
"nil",
"{",
"if",
"err",
"=",
"u",
".",
"compareSibkeys",
"(",
"ca",
".",
"sibkeys",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"ca",
".",
"subkeys",
"!=",
"nil",
"{",
"if",
"err",
"=",
"u",
".",
"compareSubkeys",
"(",
"ca",
".",
"subkeys",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // check that a user matches the given username and has the given key as one of
// its valid keys. This is where the actually work of this whole library happens. | [
"check",
"that",
"a",
"user",
"matches",
"the",
"given",
"username",
"and",
"has",
"the",
"given",
"key",
"as",
"one",
"of",
"its",
"valid",
"keys",
".",
"This",
"is",
"where",
"the",
"actually",
"work",
"of",
"this",
"whole",
"library",
"happens",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L388-L428 |
159,705 | keybase/client | go/auth/credential_authority.go | checkUsername | func (u *user) checkUsername(un libkb.NormalizedUsername) error {
var err error
if !u.username.Eq(un) {
err = BadUsernameError{u.username, un}
}
return err
} | go | func (u *user) checkUsername(un libkb.NormalizedUsername) error {
var err error
if !u.username.Eq(un) {
err = BadUsernameError{u.username, un}
}
return err
} | [
"func",
"(",
"u",
"*",
"user",
")",
"checkUsername",
"(",
"un",
"libkb",
".",
"NormalizedUsername",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"!",
"u",
".",
"username",
".",
"Eq",
"(",
"un",
")",
"{",
"err",
"=",
"BadUsernameError",
"{",
"u",
".",
"username",
",",
"un",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // checkUsername checks that a username is a match for this user. | [
"checkUsername",
"checks",
"that",
"a",
"username",
"is",
"a",
"match",
"for",
"this",
"user",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L443-L449 |
159,706 | keybase/client | go/auth/credential_authority.go | compareSibkeys | func (u *user) compareSibkeys(sibkeys []keybase1.KID) error {
return compareKeys(sibkeys, u.sibkeys)
} | go | func (u *user) compareSibkeys(sibkeys []keybase1.KID) error {
return compareKeys(sibkeys, u.sibkeys)
} | [
"func",
"(",
"u",
"*",
"user",
")",
"compareSibkeys",
"(",
"sibkeys",
"[",
"]",
"keybase1",
".",
"KID",
")",
"error",
"{",
"return",
"compareKeys",
"(",
"sibkeys",
",",
"u",
".",
"sibkeys",
")",
"\n",
"}"
] | // compareSibkeys returns true if the passed set of sibkeys is equal. | [
"compareSibkeys",
"returns",
"true",
"if",
"the",
"passed",
"set",
"of",
"sibkeys",
"is",
"equal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L452-L454 |
159,707 | keybase/client | go/auth/credential_authority.go | compareSubkeys | func (u *user) compareSubkeys(subkeys []keybase1.KID) error {
return compareKeys(subkeys, u.subkeys)
} | go | func (u *user) compareSubkeys(subkeys []keybase1.KID) error {
return compareKeys(subkeys, u.subkeys)
} | [
"func",
"(",
"u",
"*",
"user",
")",
"compareSubkeys",
"(",
"subkeys",
"[",
"]",
"keybase1",
".",
"KID",
")",
"error",
"{",
"return",
"compareKeys",
"(",
"subkeys",
",",
"u",
".",
"subkeys",
")",
"\n",
"}"
] | // compareSubkeys returns true if the passed set of subkeys is equal. | [
"compareSubkeys",
"returns",
"true",
"if",
"the",
"passed",
"set",
"of",
"subkeys",
"is",
"equal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L457-L459 |
159,708 | keybase/client | go/auth/credential_authority.go | compareKeys | func compareKeys(keys []keybase1.KID, expected map[keybase1.KID]struct{}) error {
if len(keys) != len(expected) {
return ErrKeysNotEqual
}
for _, kid := range keys {
if _, ok := expected[kid]; !ok {
return ErrKeysNotEqual
}
}
return nil
} | go | func compareKeys(keys []keybase1.KID, expected map[keybase1.KID]struct{}) error {
if len(keys) != len(expected) {
return ErrKeysNotEqual
}
for _, kid := range keys {
if _, ok := expected[kid]; !ok {
return ErrKeysNotEqual
}
}
return nil
} | [
"func",
"compareKeys",
"(",
"keys",
"[",
"]",
"keybase1",
".",
"KID",
",",
"expected",
"map",
"[",
"keybase1",
".",
"KID",
"]",
"struct",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"keys",
")",
"!=",
"len",
"(",
"expected",
")",
"{",
"return",
"ErrKeysNotEqual",
"\n",
"}",
"\n",
"for",
"_",
",",
"kid",
":=",
"range",
"keys",
"{",
"if",
"_",
",",
"ok",
":=",
"expected",
"[",
"kid",
"]",
";",
"!",
"ok",
"{",
"return",
"ErrKeysNotEqual",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Helper method for the two above. | [
"Helper",
"method",
"for",
"the",
"two",
"above",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L462-L472 |
159,709 | keybase/client | go/auth/credential_authority.go | checkKey | func (u *user) checkKey(kid keybase1.KID) error {
var err error
if _, ok := u.sibkeys[kid]; !ok {
if _, ok := u.subkeys[kid]; !ok {
err = BadKeyError{u.uid, kid}
}
}
return err
} | go | func (u *user) checkKey(kid keybase1.KID) error {
var err error
if _, ok := u.sibkeys[kid]; !ok {
if _, ok := u.subkeys[kid]; !ok {
err = BadKeyError{u.uid, kid}
}
}
return err
} | [
"func",
"(",
"u",
"*",
"user",
")",
"checkKey",
"(",
"kid",
"keybase1",
".",
"KID",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"_",
",",
"ok",
":=",
"u",
".",
"sibkeys",
"[",
"kid",
"]",
";",
"!",
"ok",
"{",
"if",
"_",
",",
"ok",
":=",
"u",
".",
"subkeys",
"[",
"kid",
"]",
";",
"!",
"ok",
"{",
"err",
"=",
"BadKeyError",
"{",
"u",
".",
"uid",
",",
"kid",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // checkKey checks that the given key is still valid for this user. | [
"checkKey",
"checks",
"that",
"the",
"given",
"key",
"is",
"still",
"valid",
"for",
"this",
"user",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L475-L483 |
159,710 | keybase/client | go/auth/credential_authority.go | CheckUserKey | func (v *CredentialAuthority) CheckUserKey(ctx context.Context, uid keybase1.UID,
username *libkb.NormalizedUsername, kid *keybase1.KID, loadDeleted bool) (err error) {
v.log.Debug("CheckUserKey uid %s, kid %s", uid, kid)
retCh := make(chan error, 1) // buffered in case the ctx is canceled
v.checkCh <- checkArg{uid: uid, username: username, kid: kid, loadDeleted: loadDeleted, retCh: retCh}
select {
case <-ctx.Done():
err = ctx.Err()
case err = <-retCh:
}
return err
} | go | func (v *CredentialAuthority) CheckUserKey(ctx context.Context, uid keybase1.UID,
username *libkb.NormalizedUsername, kid *keybase1.KID, loadDeleted bool) (err error) {
v.log.Debug("CheckUserKey uid %s, kid %s", uid, kid)
retCh := make(chan error, 1) // buffered in case the ctx is canceled
v.checkCh <- checkArg{uid: uid, username: username, kid: kid, loadDeleted: loadDeleted, retCh: retCh}
select {
case <-ctx.Done():
err = ctx.Err()
case err = <-retCh:
}
return err
} | [
"func",
"(",
"v",
"*",
"CredentialAuthority",
")",
"CheckUserKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"uid",
"keybase1",
".",
"UID",
",",
"username",
"*",
"libkb",
".",
"NormalizedUsername",
",",
"kid",
"*",
"keybase1",
".",
"KID",
",",
"loadDeleted",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"v",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"uid",
",",
"kid",
")",
"\n",
"retCh",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"// buffered in case the ctx is canceled",
"\n",
"v",
".",
"checkCh",
"<-",
"checkArg",
"{",
"uid",
":",
"uid",
",",
"username",
":",
"username",
",",
"kid",
":",
"kid",
",",
"loadDeleted",
":",
"loadDeleted",
",",
"retCh",
":",
"retCh",
"}",
"\n",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"err",
"=",
"ctx",
".",
"Err",
"(",
")",
"\n",
"case",
"err",
"=",
"<-",
"retCh",
":",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // CheckUserKey is the main point of entry to this library. It takes as input a UID, a
// username and a kid that should refer to a current valid triple, perhaps
// extracted from a signed authentication statement. It returns an error if the
// check fails, and nil otherwise. If username or kid are nil they aren't checked. | [
"CheckUserKey",
"is",
"the",
"main",
"point",
"of",
"entry",
"to",
"this",
"library",
".",
"It",
"takes",
"as",
"input",
"a",
"UID",
"a",
"username",
"and",
"a",
"kid",
"that",
"should",
"refer",
"to",
"a",
"current",
"valid",
"triple",
"perhaps",
"extracted",
"from",
"a",
"signed",
"authentication",
"statement",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"check",
"fails",
"and",
"nil",
"otherwise",
".",
"If",
"username",
"or",
"kid",
"are",
"nil",
"they",
"aren",
"t",
"checked",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L489-L500 |
159,711 | keybase/client | go/auth/credential_authority.go | CheckUsers | func (v *CredentialAuthority) CheckUsers(ctx context.Context, users []keybase1.UID) (err error) {
for _, uid := range users {
if uid == keybase1.PUBLIC_UID {
continue
}
if err = v.CheckUserKey(ctx, uid, nil, nil, false); err != nil {
break
}
}
return err
} | go | func (v *CredentialAuthority) CheckUsers(ctx context.Context, users []keybase1.UID) (err error) {
for _, uid := range users {
if uid == keybase1.PUBLIC_UID {
continue
}
if err = v.CheckUserKey(ctx, uid, nil, nil, false); err != nil {
break
}
}
return err
} | [
"func",
"(",
"v",
"*",
"CredentialAuthority",
")",
"CheckUsers",
"(",
"ctx",
"context",
".",
"Context",
",",
"users",
"[",
"]",
"keybase1",
".",
"UID",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"uid",
":=",
"range",
"users",
"{",
"if",
"uid",
"==",
"keybase1",
".",
"PUBLIC_UID",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
"=",
"v",
".",
"CheckUserKey",
"(",
"ctx",
",",
"uid",
",",
"nil",
",",
"nil",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // CheckUsers is used to validate all provided UIDs are known. | [
"CheckUsers",
"is",
"used",
"to",
"validate",
"all",
"provided",
"UIDs",
"are",
"known",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L503-L513 |
159,712 | keybase/client | go/auth/credential_authority.go | CompareUserKeys | func (v *CredentialAuthority) CompareUserKeys(ctx context.Context, uid keybase1.UID, sibkeys, subkeys []keybase1.KID) (
err error) {
retCh := make(chan error, 1) // buffered in case the ctx is canceled
v.checkCh <- checkArg{uid: uid, sibkeys: sibkeys, subkeys: subkeys, retCh: retCh}
select {
case <-ctx.Done():
err = ctx.Err()
case err = <-retCh:
}
return err
} | go | func (v *CredentialAuthority) CompareUserKeys(ctx context.Context, uid keybase1.UID, sibkeys, subkeys []keybase1.KID) (
err error) {
retCh := make(chan error, 1) // buffered in case the ctx is canceled
v.checkCh <- checkArg{uid: uid, sibkeys: sibkeys, subkeys: subkeys, retCh: retCh}
select {
case <-ctx.Done():
err = ctx.Err()
case err = <-retCh:
}
return err
} | [
"func",
"(",
"v",
"*",
"CredentialAuthority",
")",
"CompareUserKeys",
"(",
"ctx",
"context",
".",
"Context",
",",
"uid",
"keybase1",
".",
"UID",
",",
"sibkeys",
",",
"subkeys",
"[",
"]",
"keybase1",
".",
"KID",
")",
"(",
"err",
"error",
")",
"{",
"retCh",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"// buffered in case the ctx is canceled",
"\n",
"v",
".",
"checkCh",
"<-",
"checkArg",
"{",
"uid",
":",
"uid",
",",
"sibkeys",
":",
"sibkeys",
",",
"subkeys",
":",
"subkeys",
",",
"retCh",
":",
"retCh",
"}",
"\n",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"err",
"=",
"ctx",
".",
"Err",
"(",
")",
"\n",
"case",
"err",
"=",
"<-",
"retCh",
":",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // CompareUserKeys compares the passed sets to the sets known by the API server.
// It returns true if the sets are equal. | [
"CompareUserKeys",
"compares",
"the",
"passed",
"sets",
"to",
"the",
"sets",
"known",
"by",
"the",
"API",
"server",
".",
"It",
"returns",
"true",
"if",
"the",
"sets",
"are",
"equal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/auth/credential_authority.go#L517-L527 |
159,713 | keybase/client | go/chat/flip/dealer.go | String | func (s Start) String() string {
return fmt.Sprintf("{StartTime:%v CommitmentWindowMsec:%v RevealWindowMsec:%v SlackMsec:%v CommitmentCompleteWindowMsec:%v}",
s.StartTime, s.CommitmentWindowMsec, s.RevealWindowMsec, s.SlackMsec, s.CommitmentWindowMsec)
} | go | func (s Start) String() string {
return fmt.Sprintf("{StartTime:%v CommitmentWindowMsec:%v RevealWindowMsec:%v SlackMsec:%v CommitmentCompleteWindowMsec:%v}",
s.StartTime, s.CommitmentWindowMsec, s.RevealWindowMsec, s.SlackMsec, s.CommitmentWindowMsec)
} | [
"func",
"(",
"s",
"Start",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"StartTime",
",",
"s",
".",
"CommitmentWindowMsec",
",",
"s",
".",
"RevealWindowMsec",
",",
"s",
".",
"SlackMsec",
",",
"s",
".",
"CommitmentWindowMsec",
")",
"\n",
"}"
] | // Excludes `Params` from being logged. | [
"Excludes",
"Params",
"from",
"being",
"logged",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/flip/dealer.go#L19-L22 |
159,714 | keybase/client | go/chat/flip/dealer.go | inflateTimeout | func inflateTimeout(timeout int64, nPlayers int) int64 {
if nPlayers <= 5 {
return timeout
}
return int64(math.Ceil(math.Log(float64(nPlayers)) * float64(timeout) / math.Log(5.0)))
} | go | func inflateTimeout(timeout int64, nPlayers int) int64 {
if nPlayers <= 5 {
return timeout
}
return int64(math.Ceil(math.Log(float64(nPlayers)) * float64(timeout) / math.Log(5.0)))
} | [
"func",
"inflateTimeout",
"(",
"timeout",
"int64",
",",
"nPlayers",
"int",
")",
"int64",
"{",
"if",
"nPlayers",
"<=",
"5",
"{",
"return",
"timeout",
"\n",
"}",
"\n",
"return",
"int64",
"(",
"math",
".",
"Ceil",
"(",
"math",
".",
"Log",
"(",
"float64",
"(",
"nPlayers",
")",
")",
"*",
"float64",
"(",
"timeout",
")",
"/",
"math",
".",
"Log",
"(",
"5.0",
")",
")",
")",
"\n",
"}"
] | // For bigger groups, everything is slower, like the time to digest all required messages. So we're
// going to inflate our timeouts. | [
"For",
"bigger",
"groups",
"everything",
"is",
"slower",
"like",
"the",
"time",
"to",
"digest",
"all",
"required",
"messages",
".",
"So",
"we",
"re",
"going",
"to",
"inflate",
"our",
"timeouts",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/flip/dealer.go#L910-L915 |
159,715 | keybase/client | go/kbfs/libkbfs/quota_usage.go | NewEventuallyConsistentQuotaUsage | func NewEventuallyConsistentQuotaUsage(
config Config, log logger.Logger,
vlog *libkb.VDebugLog) *EventuallyConsistentQuotaUsage {
q := &EventuallyConsistentQuotaUsage{
config: config,
log: log,
}
q.fetcher = newFetchDecider(
q.log, vlog, q.getAndCache, ECQUCtxTagKey{}, ECQUID, q.config)
return q
} | go | func NewEventuallyConsistentQuotaUsage(
config Config, log logger.Logger,
vlog *libkb.VDebugLog) *EventuallyConsistentQuotaUsage {
q := &EventuallyConsistentQuotaUsage{
config: config,
log: log,
}
q.fetcher = newFetchDecider(
q.log, vlog, q.getAndCache, ECQUCtxTagKey{}, ECQUID, q.config)
return q
} | [
"func",
"NewEventuallyConsistentQuotaUsage",
"(",
"config",
"Config",
",",
"log",
"logger",
".",
"Logger",
",",
"vlog",
"*",
"libkb",
".",
"VDebugLog",
")",
"*",
"EventuallyConsistentQuotaUsage",
"{",
"q",
":=",
"&",
"EventuallyConsistentQuotaUsage",
"{",
"config",
":",
"config",
",",
"log",
":",
"log",
",",
"}",
"\n",
"q",
".",
"fetcher",
"=",
"newFetchDecider",
"(",
"q",
".",
"log",
",",
"vlog",
",",
"q",
".",
"getAndCache",
",",
"ECQUCtxTagKey",
"{",
"}",
",",
"ECQUID",
",",
"q",
".",
"config",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // NewEventuallyConsistentQuotaUsage creates a new
// EventuallyConsistentQuotaUsage object. | [
"NewEventuallyConsistentQuotaUsage",
"creates",
"a",
"new",
"EventuallyConsistentQuotaUsage",
"object",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/quota_usage.go#L67-L77 |
159,716 | keybase/client | go/kbfs/libkbfs/quota_usage.go | NewEventuallyConsistentTeamQuotaUsage | func NewEventuallyConsistentTeamQuotaUsage(
config Config, tid keybase1.TeamID,
log logger.Logger, vlog *libkb.VDebugLog) *EventuallyConsistentQuotaUsage {
q := NewEventuallyConsistentQuotaUsage(config, log, vlog)
q.tid = tid
return q
} | go | func NewEventuallyConsistentTeamQuotaUsage(
config Config, tid keybase1.TeamID,
log logger.Logger, vlog *libkb.VDebugLog) *EventuallyConsistentQuotaUsage {
q := NewEventuallyConsistentQuotaUsage(config, log, vlog)
q.tid = tid
return q
} | [
"func",
"NewEventuallyConsistentTeamQuotaUsage",
"(",
"config",
"Config",
",",
"tid",
"keybase1",
".",
"TeamID",
",",
"log",
"logger",
".",
"Logger",
",",
"vlog",
"*",
"libkb",
".",
"VDebugLog",
")",
"*",
"EventuallyConsistentQuotaUsage",
"{",
"q",
":=",
"NewEventuallyConsistentQuotaUsage",
"(",
"config",
",",
"log",
",",
"vlog",
")",
"\n",
"q",
".",
"tid",
"=",
"tid",
"\n",
"return",
"q",
"\n",
"}"
] | // NewEventuallyConsistentTeamQuotaUsage creates a new
// EventuallyConsistentQuotaUsage object. | [
"NewEventuallyConsistentTeamQuotaUsage",
"creates",
"a",
"new",
"EventuallyConsistentQuotaUsage",
"object",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/quota_usage.go#L81-L87 |
159,717 | keybase/client | go/kbfs/libkbfs/quota_usage.go | Get | func (q *EventuallyConsistentQuotaUsage) Get(
ctx context.Context, bgTolerance, blockTolerance time.Duration) (
timestamp time.Time, usageBytes, archiveBytes, limitBytes int64,
err error) {
c := q.getCached()
err = q.fetcher.Do(ctx, bgTolerance, blockTolerance, c.timestamp)
if err != nil {
return time.Time{}, -1, -1, -1, err
}
c = q.getCached()
switch q.config.DefaultBlockType() {
case keybase1.BlockType_DATA:
return c.timestamp, c.usageBytes, c.archiveBytes, c.limitBytes, nil
case keybase1.BlockType_GIT:
return c.timestamp, c.gitUsageBytes, c.gitArchiveBytes,
c.gitLimitBytes, nil
default:
return time.Time{}, -1, -1, -1, errors.Errorf(
"Unknown default block type: %d", q.config.DefaultBlockType())
}
} | go | func (q *EventuallyConsistentQuotaUsage) Get(
ctx context.Context, bgTolerance, blockTolerance time.Duration) (
timestamp time.Time, usageBytes, archiveBytes, limitBytes int64,
err error) {
c := q.getCached()
err = q.fetcher.Do(ctx, bgTolerance, blockTolerance, c.timestamp)
if err != nil {
return time.Time{}, -1, -1, -1, err
}
c = q.getCached()
switch q.config.DefaultBlockType() {
case keybase1.BlockType_DATA:
return c.timestamp, c.usageBytes, c.archiveBytes, c.limitBytes, nil
case keybase1.BlockType_GIT:
return c.timestamp, c.gitUsageBytes, c.gitArchiveBytes,
c.gitLimitBytes, nil
default:
return time.Time{}, -1, -1, -1, errors.Errorf(
"Unknown default block type: %d", q.config.DefaultBlockType())
}
} | [
"func",
"(",
"q",
"*",
"EventuallyConsistentQuotaUsage",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"bgTolerance",
",",
"blockTolerance",
"time",
".",
"Duration",
")",
"(",
"timestamp",
"time",
".",
"Time",
",",
"usageBytes",
",",
"archiveBytes",
",",
"limitBytes",
"int64",
",",
"err",
"error",
")",
"{",
"c",
":=",
"q",
".",
"getCached",
"(",
")",
"\n",
"err",
"=",
"q",
".",
"fetcher",
".",
"Do",
"(",
"ctx",
",",
"bgTolerance",
",",
"blockTolerance",
",",
"c",
".",
"timestamp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"c",
"=",
"q",
".",
"getCached",
"(",
")",
"\n",
"switch",
"q",
".",
"config",
".",
"DefaultBlockType",
"(",
")",
"{",
"case",
"keybase1",
".",
"BlockType_DATA",
":",
"return",
"c",
".",
"timestamp",
",",
"c",
".",
"usageBytes",
",",
"c",
".",
"archiveBytes",
",",
"c",
".",
"limitBytes",
",",
"nil",
"\n",
"case",
"keybase1",
".",
"BlockType_GIT",
":",
"return",
"c",
".",
"timestamp",
",",
"c",
".",
"gitUsageBytes",
",",
"c",
".",
"gitArchiveBytes",
",",
"c",
".",
"gitLimitBytes",
",",
"nil",
"\n",
"default",
":",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"q",
".",
"config",
".",
"DefaultBlockType",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Get returns KBFS bytes used and limit for user, for the current
// default block type. To help avoid having too frequent calls into
// bserver, caller can provide a positive tolerance, to accept stale
// LimitBytes and UsageBytes data. If tolerance is 0 or negative, this
// always makes a blocking RPC to bserver and return latest quota
// usage.
//
// 1) If the age of cached data is more than blockTolerance, a blocking RPC is
// issued and the function only returns after RPC finishes, with the newest
// data from RPC. The RPC causes cached data to be refreshed as well.
// 2) Otherwise, if the age of cached data is more than bgTolerance,
// a background RPC is spawned to refresh cached data, and the stale
// data is returned immediately.
// 3) Otherwise, the cached stale data is returned immediately. | [
"Get",
"returns",
"KBFS",
"bytes",
"used",
"and",
"limit",
"for",
"user",
"for",
"the",
"current",
"default",
"block",
"type",
".",
"To",
"help",
"avoid",
"having",
"too",
"frequent",
"calls",
"into",
"bserver",
"caller",
"can",
"provide",
"a",
"positive",
"tolerance",
"to",
"accept",
"stale",
"LimitBytes",
"and",
"UsageBytes",
"data",
".",
"If",
"tolerance",
"is",
"0",
"or",
"negative",
"this",
"always",
"makes",
"a",
"blocking",
"RPC",
"to",
"bserver",
"and",
"return",
"latest",
"quota",
"usage",
".",
"1",
")",
"If",
"the",
"age",
"of",
"cached",
"data",
"is",
"more",
"than",
"blockTolerance",
"a",
"blocking",
"RPC",
"is",
"issued",
"and",
"the",
"function",
"only",
"returns",
"after",
"RPC",
"finishes",
"with",
"the",
"newest",
"data",
"from",
"RPC",
".",
"The",
"RPC",
"causes",
"cached",
"data",
"to",
"be",
"refreshed",
"as",
"well",
".",
"2",
")",
"Otherwise",
"if",
"the",
"age",
"of",
"cached",
"data",
"is",
"more",
"than",
"bgTolerance",
"a",
"background",
"RPC",
"is",
"spawned",
"to",
"refresh",
"cached",
"data",
"and",
"the",
"stale",
"data",
"is",
"returned",
"immediately",
".",
"3",
")",
"Otherwise",
"the",
"cached",
"stale",
"data",
"is",
"returned",
"immediately",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/quota_usage.go#L242-L263 |
159,718 | keybase/client | go/kbfs/libkbfs/quota_usage.go | GetAllTypes | func (q *EventuallyConsistentQuotaUsage) GetAllTypes(
ctx context.Context, bgTolerance, blockTolerance time.Duration) (
timestamp time.Time,
usageBytes, archiveBytes, limitBytes,
gitUsageBytes, gitArchiveBytes, gitLimitBytes int64, err error) {
c := q.getCached()
err = q.fetcher.Do(ctx, bgTolerance, blockTolerance, c.timestamp)
if err != nil {
return time.Time{}, -1, -1, -1, -1, -1, -1, err
}
c = q.getCached()
return c.timestamp,
c.usageBytes, c.archiveBytes, c.limitBytes,
c.gitUsageBytes, c.gitArchiveBytes, c.gitLimitBytes, nil
} | go | func (q *EventuallyConsistentQuotaUsage) GetAllTypes(
ctx context.Context, bgTolerance, blockTolerance time.Duration) (
timestamp time.Time,
usageBytes, archiveBytes, limitBytes,
gitUsageBytes, gitArchiveBytes, gitLimitBytes int64, err error) {
c := q.getCached()
err = q.fetcher.Do(ctx, bgTolerance, blockTolerance, c.timestamp)
if err != nil {
return time.Time{}, -1, -1, -1, -1, -1, -1, err
}
c = q.getCached()
return c.timestamp,
c.usageBytes, c.archiveBytes, c.limitBytes,
c.gitUsageBytes, c.gitArchiveBytes, c.gitLimitBytes, nil
} | [
"func",
"(",
"q",
"*",
"EventuallyConsistentQuotaUsage",
")",
"GetAllTypes",
"(",
"ctx",
"context",
".",
"Context",
",",
"bgTolerance",
",",
"blockTolerance",
"time",
".",
"Duration",
")",
"(",
"timestamp",
"time",
".",
"Time",
",",
"usageBytes",
",",
"archiveBytes",
",",
"limitBytes",
",",
"gitUsageBytes",
",",
"gitArchiveBytes",
",",
"gitLimitBytes",
"int64",
",",
"err",
"error",
")",
"{",
"c",
":=",
"q",
".",
"getCached",
"(",
")",
"\n",
"err",
"=",
"q",
".",
"fetcher",
".",
"Do",
"(",
"ctx",
",",
"bgTolerance",
",",
"blockTolerance",
",",
"c",
".",
"timestamp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"c",
"=",
"q",
".",
"getCached",
"(",
")",
"\n",
"return",
"c",
".",
"timestamp",
",",
"c",
".",
"usageBytes",
",",
"c",
".",
"archiveBytes",
",",
"c",
".",
"limitBytes",
",",
"c",
".",
"gitUsageBytes",
",",
"c",
".",
"gitArchiveBytes",
",",
"c",
".",
"gitLimitBytes",
",",
"nil",
"\n",
"}"
] | // GetAllTypes is the same as Get, except it returns usage and limits
// for all block types. | [
"GetAllTypes",
"is",
"the",
"same",
"as",
"Get",
"except",
"it",
"returns",
"usage",
"and",
"limits",
"for",
"all",
"block",
"types",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/quota_usage.go#L267-L282 |
159,719 | keybase/client | go/engine/kex2_provisionee.go | NewKex2Provisionee | func NewKex2Provisionee(g *libkb.GlobalContext, device *libkb.Device, secret kex2.Secret,
expectedUID keybase1.UID, salt []byte) *Kex2Provisionee {
return &Kex2Provisionee{
Contextified: libkb.NewContextified(g),
device: device,
secret: secret,
secretCh: make(chan kex2.Secret),
salt: salt,
expectedUID: expectedUID,
}
} | go | func NewKex2Provisionee(g *libkb.GlobalContext, device *libkb.Device, secret kex2.Secret,
expectedUID keybase1.UID, salt []byte) *Kex2Provisionee {
return &Kex2Provisionee{
Contextified: libkb.NewContextified(g),
device: device,
secret: secret,
secretCh: make(chan kex2.Secret),
salt: salt,
expectedUID: expectedUID,
}
} | [
"func",
"NewKex2Provisionee",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"device",
"*",
"libkb",
".",
"Device",
",",
"secret",
"kex2",
".",
"Secret",
",",
"expectedUID",
"keybase1",
".",
"UID",
",",
"salt",
"[",
"]",
"byte",
")",
"*",
"Kex2Provisionee",
"{",
"return",
"&",
"Kex2Provisionee",
"{",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"device",
":",
"device",
",",
"secret",
":",
"secret",
",",
"secretCh",
":",
"make",
"(",
"chan",
"kex2",
".",
"Secret",
")",
",",
"salt",
":",
"salt",
",",
"expectedUID",
":",
"expectedUID",
",",
"}",
"\n",
"}"
] | // NewKex2Provisionee creates a Kex2Provisionee engine. | [
"NewKex2Provisionee",
"creates",
"a",
"Kex2Provisionee",
"engine",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L52-L62 |
159,720 | keybase/client | go/engine/kex2_provisionee.go | GetLogFactory | func (e *Kex2Provisionee) GetLogFactory() rpc.LogFactory {
return rpc.NewSimpleLogFactory(e.G().Log, nil)
} | go | func (e *Kex2Provisionee) GetLogFactory() rpc.LogFactory {
return rpc.NewSimpleLogFactory(e.G().Log, nil)
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"GetLogFactory",
"(",
")",
"rpc",
".",
"LogFactory",
"{",
"return",
"rpc",
".",
"NewSimpleLogFactory",
"(",
"e",
".",
"G",
"(",
")",
".",
"Log",
",",
"nil",
")",
"\n",
"}"
] | // GetLogFactory implements GetLogFactory in kex2.Provisionee. | [
"GetLogFactory",
"implements",
"GetLogFactory",
"in",
"kex2",
".",
"Provisionee",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L161-L163 |
159,721 | keybase/client | go/engine/kex2_provisionee.go | HandleHello | func (e *Kex2Provisionee) HandleHello(_ context.Context, harg keybase1.HelloArg) (res keybase1.HelloRes, err error) {
m := e.mctx
defer m.Trace("Kex2Provisionee#HandleHello", func() error { return err })()
e.pps = harg.Pps
res, err = e.handleHello(m, harg.Uid, harg.Token, harg.Csrf, harg.SigBody)
return res, err
} | go | func (e *Kex2Provisionee) HandleHello(_ context.Context, harg keybase1.HelloArg) (res keybase1.HelloRes, err error) {
m := e.mctx
defer m.Trace("Kex2Provisionee#HandleHello", func() error { return err })()
e.pps = harg.Pps
res, err = e.handleHello(m, harg.Uid, harg.Token, harg.Csrf, harg.SigBody)
return res, err
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"HandleHello",
"(",
"_",
"context",
".",
"Context",
",",
"harg",
"keybase1",
".",
"HelloArg",
")",
"(",
"res",
"keybase1",
".",
"HelloRes",
",",
"err",
"error",
")",
"{",
"m",
":=",
"e",
".",
"mctx",
"\n",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n",
"e",
".",
"pps",
"=",
"harg",
".",
"Pps",
"\n",
"res",
",",
"err",
"=",
"e",
".",
"handleHello",
"(",
"m",
",",
"harg",
".",
"Uid",
",",
"harg",
".",
"Token",
",",
"harg",
".",
"Csrf",
",",
"harg",
".",
"SigBody",
")",
"\n",
"return",
"res",
",",
"err",
"\n",
"}"
] | // HandleHello implements HandleHello in kex2.Provisionee. | [
"HandleHello",
"implements",
"HandleHello",
"in",
"kex2",
".",
"Provisionee",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L166-L172 |
159,722 | keybase/client | go/engine/kex2_provisionee.go | HandleHello2 | func (e *Kex2Provisionee) HandleHello2(_ context.Context, harg keybase1.Hello2Arg) (res keybase1.Hello2Res, err error) {
m := e.mctx
defer m.Trace("Kex2Provisionee#HandleHello2()", func() error { return err })()
var res1 keybase1.HelloRes
res1, err = e.handleHello(m, harg.Uid, harg.Token, harg.Csrf, harg.SigBody)
if err != nil {
return res, err
}
res.SigPayload = res1
res.EncryptionKey = e.dh.GetKID()
res.DeviceEkKID, err = e.ekReboxer.getDeviceEKKID(m)
if err != nil {
return res, err
}
return res, err
} | go | func (e *Kex2Provisionee) HandleHello2(_ context.Context, harg keybase1.Hello2Arg) (res keybase1.Hello2Res, err error) {
m := e.mctx
defer m.Trace("Kex2Provisionee#HandleHello2()", func() error { return err })()
var res1 keybase1.HelloRes
res1, err = e.handleHello(m, harg.Uid, harg.Token, harg.Csrf, harg.SigBody)
if err != nil {
return res, err
}
res.SigPayload = res1
res.EncryptionKey = e.dh.GetKID()
res.DeviceEkKID, err = e.ekReboxer.getDeviceEKKID(m)
if err != nil {
return res, err
}
return res, err
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"HandleHello2",
"(",
"_",
"context",
".",
"Context",
",",
"harg",
"keybase1",
".",
"Hello2Arg",
")",
"(",
"res",
"keybase1",
".",
"Hello2Res",
",",
"err",
"error",
")",
"{",
"m",
":=",
"e",
".",
"mctx",
"\n",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n",
"var",
"res1",
"keybase1",
".",
"HelloRes",
"\n",
"res1",
",",
"err",
"=",
"e",
".",
"handleHello",
"(",
"m",
",",
"harg",
".",
"Uid",
",",
"harg",
".",
"Token",
",",
"harg",
".",
"Csrf",
",",
"harg",
".",
"SigBody",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n",
"res",
".",
"SigPayload",
"=",
"res1",
"\n",
"res",
".",
"EncryptionKey",
"=",
"e",
".",
"dh",
".",
"GetKID",
"(",
")",
"\n",
"res",
".",
"DeviceEkKID",
",",
"err",
"=",
"e",
".",
"ekReboxer",
".",
"getDeviceEKKID",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
",",
"err",
"\n",
"}"
] | // HandleHello2 implements HandleHello2 in kex2.Provisionee. | [
"HandleHello2",
"implements",
"HandleHello2",
"in",
"kex2",
".",
"Provisionee",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L227-L242 |
159,723 | keybase/client | go/engine/kex2_provisionee.go | HandleDidCounterSign | func (e *Kex2Provisionee) HandleDidCounterSign(_ context.Context, sig []byte) (err error) {
return e.handleDidCounterSign(e.mctx, sig, nil, nil)
} | go | func (e *Kex2Provisionee) HandleDidCounterSign(_ context.Context, sig []byte) (err error) {
return e.handleDidCounterSign(e.mctx, sig, nil, nil)
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"HandleDidCounterSign",
"(",
"_",
"context",
".",
"Context",
",",
"sig",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"return",
"e",
".",
"handleDidCounterSign",
"(",
"e",
".",
"mctx",
",",
"sig",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] | // HandleDidCounterSign implements HandleDidCounterSign in
// kex2.Provisionee interface. | [
"HandleDidCounterSign",
"implements",
"HandleDidCounterSign",
"in",
"kex2",
".",
"Provisionee",
"interface",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L263-L265 |
159,724 | keybase/client | go/engine/kex2_provisionee.go | updateTemporarySession | func (e *Kex2Provisionee) updateTemporarySession(m libkb.MetaContext, uv keybase1.UserVersion) (err error) {
defer m.Trace("Kex2Provisionee#updateTemporarySession", func() error { return err })()
m.Debug("login context: %T %+v", m.LoginContext(), m.LoginContext())
return m.LoginContext().SaveState(string(e.sessionToken), string(e.csrfToken), libkb.NewNormalizedUsername(e.username), uv, e.device.ID)
} | go | func (e *Kex2Provisionee) updateTemporarySession(m libkb.MetaContext, uv keybase1.UserVersion) (err error) {
defer m.Trace("Kex2Provisionee#updateTemporarySession", func() error { return err })()
m.Debug("login context: %T %+v", m.LoginContext(), m.LoginContext())
return m.LoginContext().SaveState(string(e.sessionToken), string(e.csrfToken), libkb.NewNormalizedUsername(e.username), uv, e.device.ID)
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"updateTemporarySession",
"(",
"m",
"libkb",
".",
"MetaContext",
",",
"uv",
"keybase1",
".",
"UserVersion",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"m",
".",
"LoginContext",
"(",
")",
",",
"m",
".",
"LoginContext",
"(",
")",
")",
"\n",
"return",
"m",
".",
"LoginContext",
"(",
")",
".",
"SaveState",
"(",
"string",
"(",
"e",
".",
"sessionToken",
")",
",",
"string",
"(",
"e",
".",
"csrfToken",
")",
",",
"libkb",
".",
"NewNormalizedUsername",
"(",
"e",
".",
"username",
")",
",",
"uv",
",",
"e",
".",
"device",
".",
"ID",
")",
"\n",
"}"
] | // updateTemporarySession commits the session token and csrf token to our temporary session,
// stored in our provisional login context. We'll need that to post successfully. | [
"updateTemporarySession",
"commits",
"the",
"session",
"token",
"and",
"csrf",
"token",
"to",
"our",
"temporary",
"session",
"stored",
"in",
"our",
"provisional",
"login",
"context",
".",
"We",
"ll",
"need",
"that",
"to",
"post",
"successfully",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L354-L358 |
159,725 | keybase/client | go/engine/kex2_provisionee.go | postSigs | func (e *Kex2Provisionee) postSigs(signingArgs, encryptArgs *libkb.HTTPArgs,
perUserKeyBox *keybase1.PerUserKeyBox, reboxArg *keybase1.UserEkReboxArg) error {
payload := make(libkb.JSONPayload)
payload["sigs"] = []map[string]string{firstValues(signingArgs.ToValues()), firstValues(encryptArgs.ToValues())}
// Post the per-user-secret encrypted for the provisionee device by the provisioner.
if perUserKeyBox != nil {
libkb.AddPerUserKeyServerArg(payload, perUserKeyBox.Generation, []keybase1.PerUserKeyBox{*perUserKeyBox}, nil)
}
libkb.AddUserEKReBoxServerArg(payload, reboxArg)
mctx := e.mctx.WithAPITokener(e)
arg := libkb.APIArg{
Endpoint: "key/multi",
SessionType: libkb.APISessionTypeREQUIRED,
JSONPayload: payload,
}
// MerkleCheckPostedUserSig was not added here. Changing kex2 is risky and there's no obvious attack.
_, err := e.G().API.PostJSON(mctx, arg)
return err
} | go | func (e *Kex2Provisionee) postSigs(signingArgs, encryptArgs *libkb.HTTPArgs,
perUserKeyBox *keybase1.PerUserKeyBox, reboxArg *keybase1.UserEkReboxArg) error {
payload := make(libkb.JSONPayload)
payload["sigs"] = []map[string]string{firstValues(signingArgs.ToValues()), firstValues(encryptArgs.ToValues())}
// Post the per-user-secret encrypted for the provisionee device by the provisioner.
if perUserKeyBox != nil {
libkb.AddPerUserKeyServerArg(payload, perUserKeyBox.Generation, []keybase1.PerUserKeyBox{*perUserKeyBox}, nil)
}
libkb.AddUserEKReBoxServerArg(payload, reboxArg)
mctx := e.mctx.WithAPITokener(e)
arg := libkb.APIArg{
Endpoint: "key/multi",
SessionType: libkb.APISessionTypeREQUIRED,
JSONPayload: payload,
}
// MerkleCheckPostedUserSig was not added here. Changing kex2 is risky and there's no obvious attack.
_, err := e.G().API.PostJSON(mctx, arg)
return err
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"postSigs",
"(",
"signingArgs",
",",
"encryptArgs",
"*",
"libkb",
".",
"HTTPArgs",
",",
"perUserKeyBox",
"*",
"keybase1",
".",
"PerUserKeyBox",
",",
"reboxArg",
"*",
"keybase1",
".",
"UserEkReboxArg",
")",
"error",
"{",
"payload",
":=",
"make",
"(",
"libkb",
".",
"JSONPayload",
")",
"\n",
"payload",
"[",
"\"",
"\"",
"]",
"=",
"[",
"]",
"map",
"[",
"string",
"]",
"string",
"{",
"firstValues",
"(",
"signingArgs",
".",
"ToValues",
"(",
")",
")",
",",
"firstValues",
"(",
"encryptArgs",
".",
"ToValues",
"(",
")",
")",
"}",
"\n\n",
"// Post the per-user-secret encrypted for the provisionee device by the provisioner.",
"if",
"perUserKeyBox",
"!=",
"nil",
"{",
"libkb",
".",
"AddPerUserKeyServerArg",
"(",
"payload",
",",
"perUserKeyBox",
".",
"Generation",
",",
"[",
"]",
"keybase1",
".",
"PerUserKeyBox",
"{",
"*",
"perUserKeyBox",
"}",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"libkb",
".",
"AddUserEKReBoxServerArg",
"(",
"payload",
",",
"reboxArg",
")",
"\n\n",
"mctx",
":=",
"e",
".",
"mctx",
".",
"WithAPITokener",
"(",
"e",
")",
"\n",
"arg",
":=",
"libkb",
".",
"APIArg",
"{",
"Endpoint",
":",
"\"",
"\"",
",",
"SessionType",
":",
"libkb",
".",
"APISessionTypeREQUIRED",
",",
"JSONPayload",
":",
"payload",
",",
"}",
"\n",
"// MerkleCheckPostedUserSig was not added here. Changing kex2 is risky and there's no obvious attack.",
"_",
",",
"err",
":=",
"e",
".",
"G",
"(",
")",
".",
"API",
".",
"PostJSON",
"(",
"mctx",
",",
"arg",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // postSigs takes the HTTP args for the signing key and encrypt
// key and posts them to the api server. | [
"postSigs",
"takes",
"the",
"HTTP",
"args",
"for",
"the",
"signing",
"key",
"and",
"encrypt",
"key",
"and",
"posts",
"them",
"to",
"the",
"api",
"server",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L487-L509 |
159,726 | keybase/client | go/engine/kex2_provisionee.go | saveKeys | func (e *Kex2Provisionee) saveKeys(m libkb.MetaContext) error {
_, err := libkb.WriteLksSKBToKeyring(m, e.eddsa, e.lks)
if err != nil {
return err
}
_, err = libkb.WriteLksSKBToKeyring(m, e.dh, e.lks)
if err != nil {
return err
}
return nil
} | go | func (e *Kex2Provisionee) saveKeys(m libkb.MetaContext) error {
_, err := libkb.WriteLksSKBToKeyring(m, e.eddsa, e.lks)
if err != nil {
return err
}
_, err = libkb.WriteLksSKBToKeyring(m, e.dh, e.lks)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"saveKeys",
"(",
"m",
"libkb",
".",
"MetaContext",
")",
"error",
"{",
"_",
",",
"err",
":=",
"libkb",
".",
"WriteLksSKBToKeyring",
"(",
"m",
",",
"e",
".",
"eddsa",
",",
"e",
".",
"lks",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"libkb",
".",
"WriteLksSKBToKeyring",
"(",
"m",
",",
"e",
".",
"dh",
",",
"e",
".",
"lks",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // saveKeys writes the device keys to LKSec. | [
"saveKeys",
"writes",
"the",
"device",
"keys",
"to",
"LKSec",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L597-L607 |
159,727 | keybase/client | go/engine/kex2_provisionee.go | saveConfig | func (e *Kex2Provisionee) saveConfig(m libkb.MetaContext, uv keybase1.UserVersion) (err error) {
defer m.Trace("Kex2Provisionee#saveConfig", func() error { return err })()
if e.eddsa == nil {
return errors.New("cacheKeys called, but eddsa key is nil")
}
if e.dh == nil {
return errors.New("cacheKeys called, but dh key is nil")
}
var deviceName string
if e.device.Description != nil {
deviceName = *e.device.Description
}
return m.SwitchUserNewConfigActiveDevice(uv, libkb.NewNormalizedUsername(e.username), e.salt, e.device.ID, e.eddsa, e.dh, deviceName)
} | go | func (e *Kex2Provisionee) saveConfig(m libkb.MetaContext, uv keybase1.UserVersion) (err error) {
defer m.Trace("Kex2Provisionee#saveConfig", func() error { return err })()
if e.eddsa == nil {
return errors.New("cacheKeys called, but eddsa key is nil")
}
if e.dh == nil {
return errors.New("cacheKeys called, but dh key is nil")
}
var deviceName string
if e.device.Description != nil {
deviceName = *e.device.Description
}
return m.SwitchUserNewConfigActiveDevice(uv, libkb.NewNormalizedUsername(e.username), e.salt, e.device.ID, e.eddsa, e.dh, deviceName)
} | [
"func",
"(",
"e",
"*",
"Kex2Provisionee",
")",
"saveConfig",
"(",
"m",
"libkb",
".",
"MetaContext",
",",
"uv",
"keybase1",
".",
"UserVersion",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n",
"if",
"e",
".",
"eddsa",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"e",
".",
"dh",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"deviceName",
"string",
"\n",
"if",
"e",
".",
"device",
".",
"Description",
"!=",
"nil",
"{",
"deviceName",
"=",
"*",
"e",
".",
"device",
".",
"Description",
"\n",
"}",
"\n\n",
"return",
"m",
".",
"SwitchUserNewConfigActiveDevice",
"(",
"uv",
",",
"libkb",
".",
"NewNormalizedUsername",
"(",
"e",
".",
"username",
")",
",",
"e",
".",
"salt",
",",
"e",
".",
"device",
".",
"ID",
",",
"e",
".",
"eddsa",
",",
"e",
".",
"dh",
",",
"deviceName",
")",
"\n",
"}"
] | // cacheKeys caches the device keys in the Account object. | [
"cacheKeys",
"caches",
"the",
"device",
"keys",
"in",
"the",
"Account",
"object",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/kex2_provisionee.go#L610-L625 |
159,728 | keybase/client | go/client/markup.go | Buffer | func (p *Paragraph) Buffer(b []byte) {
p.data = append(p.data, b...)
} | go | func (p *Paragraph) Buffer(b []byte) {
p.data = append(p.data, b...)
} | [
"func",
"(",
"p",
"*",
"Paragraph",
")",
"Buffer",
"(",
"b",
"[",
"]",
"byte",
")",
"{",
"p",
".",
"data",
"=",
"append",
"(",
"p",
".",
"data",
",",
"b",
"...",
")",
"\n",
"}"
] | // Buffer adds data to the internal paragraph buffer. | [
"Buffer",
"adds",
"data",
"to",
"the",
"internal",
"paragraph",
"buffer",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/markup.go#L30-L32 |
159,729 | keybase/client | go/client/markup.go | makePad | func makePad(l int) []byte {
ret := make([]byte, l)
for i := 0; i < l; i++ {
ret[i] = ' '
}
return ret
} | go | func makePad(l int) []byte {
ret := make([]byte, l)
for i := 0; i < l; i++ {
ret[i] = ' '
}
return ret
} | [
"func",
"makePad",
"(",
"l",
"int",
")",
"[",
"]",
"byte",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"l",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
"{",
"ret",
"[",
"i",
"]",
"=",
"' '",
"\n",
"}",
"\n",
"return",
"ret",
"\n",
"}"
] | // makePad makes a whitespace pad that is l bytes long. | [
"makePad",
"makes",
"a",
"whitespace",
"pad",
"that",
"is",
"l",
"bytes",
"long",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/markup.go#L40-L46 |
159,730 | keybase/client | go/client/markup.go | spacify | func spacify(s string) string {
v := spaceRE.Split(s, -1)
if len(v) > 0 && v[0] == "" {
v = v[1:]
}
l := len(v)
if l > 0 && v[l-1] == "" {
v = v[0:(l - 1)]
}
return strings.Join(v, " ")
} | go | func spacify(s string) string {
v := spaceRE.Split(s, -1)
if len(v) > 0 && v[0] == "" {
v = v[1:]
}
l := len(v)
if l > 0 && v[l-1] == "" {
v = v[0:(l - 1)]
}
return strings.Join(v, " ")
} | [
"func",
"spacify",
"(",
"s",
"string",
")",
"string",
"{",
"v",
":=",
"spaceRE",
".",
"Split",
"(",
"s",
",",
"-",
"1",
")",
"\n",
"if",
"len",
"(",
"v",
")",
">",
"0",
"&&",
"v",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"v",
"=",
"v",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"l",
":=",
"len",
"(",
"v",
")",
"\n",
"if",
"l",
">",
"0",
"&&",
"v",
"[",
"l",
"-",
"1",
"]",
"==",
"\"",
"\"",
"{",
"v",
"=",
"v",
"[",
"0",
":",
"(",
"l",
"-",
"1",
")",
"]",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"v",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // specify replaces arbitrary strings of whitespace with
// a single ' ' character. Also strips off leading and trailing
// whitespace. | [
"specify",
"replaces",
"arbitrary",
"strings",
"of",
"whitespace",
"with",
"a",
"single",
"character",
".",
"Also",
"strips",
"off",
"leading",
"and",
"trailing",
"whitespace",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/markup.go#L53-L63 |
159,731 | keybase/client | go/client/markup.go | Output | func (p Paragraph) Output(out io.Writer) {
s := []byte(spacify(string(p.data)))
if len(s) == 0 {
out.Write(nl)
return
}
indent := p.indent * INDENT
width := p.cols - indent - len(p.prefix)
wrapped := text.WrapBytes(s, width)
lines := bytes.Split(wrapped, nl)
gutter := makePad(indent)
pad := makePad(len(p.prefix))
for i, line := range lines {
out.Write(gutter)
if i == 0 {
out.Write([]byte(p.prefix))
} else {
out.Write(pad)
}
out.Write(line)
out.Write(nl)
}
} | go | func (p Paragraph) Output(out io.Writer) {
s := []byte(spacify(string(p.data)))
if len(s) == 0 {
out.Write(nl)
return
}
indent := p.indent * INDENT
width := p.cols - indent - len(p.prefix)
wrapped := text.WrapBytes(s, width)
lines := bytes.Split(wrapped, nl)
gutter := makePad(indent)
pad := makePad(len(p.prefix))
for i, line := range lines {
out.Write(gutter)
if i == 0 {
out.Write([]byte(p.prefix))
} else {
out.Write(pad)
}
out.Write(line)
out.Write(nl)
}
} | [
"func",
"(",
"p",
"Paragraph",
")",
"Output",
"(",
"out",
"io",
".",
"Writer",
")",
"{",
"s",
":=",
"[",
"]",
"byte",
"(",
"spacify",
"(",
"string",
"(",
"p",
".",
"data",
")",
")",
")",
"\n",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"out",
".",
"Write",
"(",
"nl",
")",
"\n",
"return",
"\n",
"}",
"\n",
"indent",
":=",
"p",
".",
"indent",
"*",
"INDENT",
"\n",
"width",
":=",
"p",
".",
"cols",
"-",
"indent",
"-",
"len",
"(",
"p",
".",
"prefix",
")",
"\n",
"wrapped",
":=",
"text",
".",
"WrapBytes",
"(",
"s",
",",
"width",
")",
"\n",
"lines",
":=",
"bytes",
".",
"Split",
"(",
"wrapped",
",",
"nl",
")",
"\n",
"gutter",
":=",
"makePad",
"(",
"indent",
")",
"\n",
"pad",
":=",
"makePad",
"(",
"len",
"(",
"p",
".",
"prefix",
")",
")",
"\n\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"out",
".",
"Write",
"(",
"gutter",
")",
"\n",
"if",
"i",
"==",
"0",
"{",
"out",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"p",
".",
"prefix",
")",
")",
"\n",
"}",
"else",
"{",
"out",
".",
"Write",
"(",
"pad",
")",
"\n",
"}",
"\n",
"out",
".",
"Write",
"(",
"line",
")",
"\n",
"out",
".",
"Write",
"(",
"nl",
")",
"\n",
"}",
"\n",
"}"
] | // Output a paragraph to the io.Writer, applying the proper
// formatting. | [
"Output",
"a",
"paragraph",
"to",
"the",
"io",
".",
"Writer",
"applying",
"the",
"proper",
"formatting",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/markup.go#L67-L90 |
159,732 | keybase/client | go/kbfs/libdokan/tlf_edit_history_file.go | NewTlfEditHistoryFile | func NewTlfEditHistoryFile(folder *Folder) *SpecialReadFile {
return &SpecialReadFile{
read: func(ctx context.Context) ([]byte, time.Time, error) {
return libfs.GetEncodedTlfEditHistory(
ctx, folder.fs.config, folder.getFolderBranch())
},
fs: folder.fs,
}
} | go | func NewTlfEditHistoryFile(folder *Folder) *SpecialReadFile {
return &SpecialReadFile{
read: func(ctx context.Context) ([]byte, time.Time, error) {
return libfs.GetEncodedTlfEditHistory(
ctx, folder.fs.config, folder.getFolderBranch())
},
fs: folder.fs,
}
} | [
"func",
"NewTlfEditHistoryFile",
"(",
"folder",
"*",
"Folder",
")",
"*",
"SpecialReadFile",
"{",
"return",
"&",
"SpecialReadFile",
"{",
"read",
":",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"byte",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"libfs",
".",
"GetEncodedTlfEditHistory",
"(",
"ctx",
",",
"folder",
".",
"fs",
".",
"config",
",",
"folder",
".",
"getFolderBranch",
"(",
")",
")",
"\n",
"}",
",",
"fs",
":",
"folder",
".",
"fs",
",",
"}",
"\n",
"}"
] | // NewTlfEditHistoryFile returns a special read file that contains a text
// representation of the file edit history for that TLF. | [
"NewTlfEditHistoryFile",
"returns",
"a",
"special",
"read",
"file",
"that",
"contains",
"a",
"text",
"representation",
"of",
"the",
"file",
"edit",
"history",
"for",
"that",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libdokan/tlf_edit_history_file.go#L16-L24 |
159,733 | keybase/client | go/client/chat_cli_flag_utils.go | annotateResolvingRequest | func annotateResolvingRequest(g *libkb.GlobalContext, req *chatConversationResolvingRequest) (err error) {
userOrTeamResult, err := CheckUserOrTeamName(context.TODO(), g, req.TlfName)
if err != nil {
return err
}
switch userOrTeamResult {
case keybase1.UserOrTeamResult_USER:
if g.Env.GetChatMemberType() == "impteam" {
req.MembersType = chat1.ConversationMembersType_IMPTEAMNATIVE
} else {
req.MembersType = chat1.ConversationMembersType_KBFS
}
case keybase1.UserOrTeamResult_TEAM:
req.MembersType = chat1.ConversationMembersType_TEAM
}
if req.TopicType == chat1.TopicType_CHAT && len(req.TopicName) != 0 &&
req.MembersType != chat1.ConversationMembersType_TEAM {
return errors.New("multiple topics only supported for teams and dev channels")
}
// Set the default topic name to #general if none is specified
if req.MembersType == chat1.ConversationMembersType_TEAM && len(req.TopicName) == 0 {
req.TopicName = globals.DefaultTeamTopic
}
return nil
} | go | func annotateResolvingRequest(g *libkb.GlobalContext, req *chatConversationResolvingRequest) (err error) {
userOrTeamResult, err := CheckUserOrTeamName(context.TODO(), g, req.TlfName)
if err != nil {
return err
}
switch userOrTeamResult {
case keybase1.UserOrTeamResult_USER:
if g.Env.GetChatMemberType() == "impteam" {
req.MembersType = chat1.ConversationMembersType_IMPTEAMNATIVE
} else {
req.MembersType = chat1.ConversationMembersType_KBFS
}
case keybase1.UserOrTeamResult_TEAM:
req.MembersType = chat1.ConversationMembersType_TEAM
}
if req.TopicType == chat1.TopicType_CHAT && len(req.TopicName) != 0 &&
req.MembersType != chat1.ConversationMembersType_TEAM {
return errors.New("multiple topics only supported for teams and dev channels")
}
// Set the default topic name to #general if none is specified
if req.MembersType == chat1.ConversationMembersType_TEAM && len(req.TopicName) == 0 {
req.TopicName = globals.DefaultTeamTopic
}
return nil
} | [
"func",
"annotateResolvingRequest",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"req",
"*",
"chatConversationResolvingRequest",
")",
"(",
"err",
"error",
")",
"{",
"userOrTeamResult",
",",
"err",
":=",
"CheckUserOrTeamName",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"g",
",",
"req",
".",
"TlfName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"switch",
"userOrTeamResult",
"{",
"case",
"keybase1",
".",
"UserOrTeamResult_USER",
":",
"if",
"g",
".",
"Env",
".",
"GetChatMemberType",
"(",
")",
"==",
"\"",
"\"",
"{",
"req",
".",
"MembersType",
"=",
"chat1",
".",
"ConversationMembersType_IMPTEAMNATIVE",
"\n",
"}",
"else",
"{",
"req",
".",
"MembersType",
"=",
"chat1",
".",
"ConversationMembersType_KBFS",
"\n",
"}",
"\n",
"case",
"keybase1",
".",
"UserOrTeamResult_TEAM",
":",
"req",
".",
"MembersType",
"=",
"chat1",
".",
"ConversationMembersType_TEAM",
"\n",
"}",
"\n",
"if",
"req",
".",
"TopicType",
"==",
"chat1",
".",
"TopicType_CHAT",
"&&",
"len",
"(",
"req",
".",
"TopicName",
")",
"!=",
"0",
"&&",
"req",
".",
"MembersType",
"!=",
"chat1",
".",
"ConversationMembersType_TEAM",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Set the default topic name to #general if none is specified",
"if",
"req",
".",
"MembersType",
"==",
"chat1",
".",
"ConversationMembersType_TEAM",
"&&",
"len",
"(",
"req",
".",
"TopicName",
")",
"==",
"0",
"{",
"req",
".",
"TopicName",
"=",
"globals",
".",
"DefaultTeamTopic",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // The purpose of this function is to provide more
// information in resolvingRequest, with the ability
// to use the socket, since this is not available
// at parse time. | [
"The",
"purpose",
"of",
"this",
"function",
"is",
"to",
"provide",
"more",
"information",
"in",
"resolvingRequest",
"with",
"the",
"ability",
"to",
"use",
"the",
"socket",
"since",
"this",
"is",
"not",
"available",
"at",
"parse",
"time",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/chat_cli_flag_utils.go#L210-L236 |
159,734 | keybase/client | go/client/cmd_chat_retention.go | showNonTeamConv | func (c *CmdChatSetRetention) showNonTeamConv(conv *chat1.ConversationLocal) {
dui := c.G().UI.GetDumbOutputUI()
if conv.TeamRetention != nil {
c.println(dui, "Unexpected team policy set on non-team conversation.\n")
}
policy := chat1.RetentionPolicy{}
if conv.ConvRetention != nil {
policy = *conv.ConvRetention
}
c.println(dui, policy.HumanSummary())
} | go | func (c *CmdChatSetRetention) showNonTeamConv(conv *chat1.ConversationLocal) {
dui := c.G().UI.GetDumbOutputUI()
if conv.TeamRetention != nil {
c.println(dui, "Unexpected team policy set on non-team conversation.\n")
}
policy := chat1.RetentionPolicy{}
if conv.ConvRetention != nil {
policy = *conv.ConvRetention
}
c.println(dui, policy.HumanSummary())
} | [
"func",
"(",
"c",
"*",
"CmdChatSetRetention",
")",
"showNonTeamConv",
"(",
"conv",
"*",
"chat1",
".",
"ConversationLocal",
")",
"{",
"dui",
":=",
"c",
".",
"G",
"(",
")",
".",
"UI",
".",
"GetDumbOutputUI",
"(",
")",
"\n",
"if",
"conv",
".",
"TeamRetention",
"!=",
"nil",
"{",
"c",
".",
"println",
"(",
"dui",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"policy",
":=",
"chat1",
".",
"RetentionPolicy",
"{",
"}",
"\n",
"if",
"conv",
".",
"ConvRetention",
"!=",
"nil",
"{",
"policy",
"=",
"*",
"conv",
".",
"ConvRetention",
"\n",
"}",
"\n",
"c",
".",
"println",
"(",
"dui",
",",
"policy",
".",
"HumanSummary",
"(",
")",
")",
"\n",
"}"
] | // Show a non-team conv policy | [
"Show",
"a",
"non",
"-",
"team",
"conv",
"policy"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/cmd_chat_retention.go#L228-L238 |
159,735 | keybase/client | go/client/cmd_chat_retention.go | showTeamChannelHTeam | func (c *CmdChatSetRetention) showTeamChannelHTeam(conv *chat1.ConversationLocal) {
dui := c.G().UI.GetDumbOutputUI()
policy := chat1.RetentionPolicy{}
if conv.TeamRetention != nil {
policy = *conv.TeamRetention
}
c.println(dui, "Team policy: %v", policy.HumanSummary())
} | go | func (c *CmdChatSetRetention) showTeamChannelHTeam(conv *chat1.ConversationLocal) {
dui := c.G().UI.GetDumbOutputUI()
policy := chat1.RetentionPolicy{}
if conv.TeamRetention != nil {
policy = *conv.TeamRetention
}
c.println(dui, "Team policy: %v", policy.HumanSummary())
} | [
"func",
"(",
"c",
"*",
"CmdChatSetRetention",
")",
"showTeamChannelHTeam",
"(",
"conv",
"*",
"chat1",
".",
"ConversationLocal",
")",
"{",
"dui",
":=",
"c",
".",
"G",
"(",
")",
".",
"UI",
".",
"GetDumbOutputUI",
"(",
")",
"\n",
"policy",
":=",
"chat1",
".",
"RetentionPolicy",
"{",
"}",
"\n",
"if",
"conv",
".",
"TeamRetention",
"!=",
"nil",
"{",
"policy",
"=",
"*",
"conv",
".",
"TeamRetention",
"\n",
"}",
"\n",
"c",
".",
"println",
"(",
"dui",
",",
"\"",
"\"",
",",
"policy",
".",
"HumanSummary",
"(",
")",
")",
"\n",
"}"
] | // Show the team policy | [
"Show",
"the",
"team",
"policy"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/cmd_chat_retention.go#L246-L253 |
159,736 | keybase/client | go/client/cmd_chat_retention.go | showTeamChannelHChannel | func (c *CmdChatSetRetention) showTeamChannelHChannel(conv *chat1.ConversationLocal) {
dui := c.G().UI.GetDumbOutputUI()
policy := chat1.RetentionPolicy{}
if conv.ConvRetention != nil {
policy = *conv.ConvRetention
}
typ, err := policy.Typ()
if err != nil {
c.println(dui, "unable to get retention type: %v", err)
return
}
var description string
switch typ {
case chat1.RetentionPolicyType_NONE, chat1.RetentionPolicyType_INHERIT:
description = "Uses the team policy"
default:
description = policy.HumanSummary()
}
c.println(dui, "#%v channel: %v", conv.Info.TopicName, description)
} | go | func (c *CmdChatSetRetention) showTeamChannelHChannel(conv *chat1.ConversationLocal) {
dui := c.G().UI.GetDumbOutputUI()
policy := chat1.RetentionPolicy{}
if conv.ConvRetention != nil {
policy = *conv.ConvRetention
}
typ, err := policy.Typ()
if err != nil {
c.println(dui, "unable to get retention type: %v", err)
return
}
var description string
switch typ {
case chat1.RetentionPolicyType_NONE, chat1.RetentionPolicyType_INHERIT:
description = "Uses the team policy"
default:
description = policy.HumanSummary()
}
c.println(dui, "#%v channel: %v", conv.Info.TopicName, description)
} | [
"func",
"(",
"c",
"*",
"CmdChatSetRetention",
")",
"showTeamChannelHChannel",
"(",
"conv",
"*",
"chat1",
".",
"ConversationLocal",
")",
"{",
"dui",
":=",
"c",
".",
"G",
"(",
")",
".",
"UI",
".",
"GetDumbOutputUI",
"(",
")",
"\n",
"policy",
":=",
"chat1",
".",
"RetentionPolicy",
"{",
"}",
"\n",
"if",
"conv",
".",
"ConvRetention",
"!=",
"nil",
"{",
"policy",
"=",
"*",
"conv",
".",
"ConvRetention",
"\n",
"}",
"\n",
"typ",
",",
"err",
":=",
"policy",
".",
"Typ",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"println",
"(",
"dui",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"var",
"description",
"string",
"\n",
"switch",
"typ",
"{",
"case",
"chat1",
".",
"RetentionPolicyType_NONE",
",",
"chat1",
".",
"RetentionPolicyType_INHERIT",
":",
"description",
"=",
"\"",
"\"",
"\n",
"default",
":",
"description",
"=",
"policy",
".",
"HumanSummary",
"(",
")",
"\n",
"}",
"\n",
"c",
".",
"println",
"(",
"dui",
",",
"\"",
"\"",
",",
"conv",
".",
"Info",
".",
"TopicName",
",",
"description",
")",
"\n",
"}"
] | // Show the channel's policy | [
"Show",
"the",
"channel",
"s",
"policy"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/cmd_chat_retention.go#L256-L275 |
159,737 | keybase/client | go/kbfs/data/bcache.go | GetWithLifetime | func (b *BlockCacheStandard) GetWithLifetime(ptr BlockPointer) (
Block, BlockCacheLifetime, error) {
if b.cleanTransient != nil {
if tmp, ok := b.cleanTransient.Get(ptr.ID); ok {
block, ok := tmp.(Block)
if !ok {
return nil, NoCacheEntry, BadDataError{ptr.ID}
}
return block, TransientEntry, nil
}
}
block := func() Block {
b.cleanLock.RLock()
defer b.cleanLock.RUnlock()
return b.cleanPermanent[ptr.ID]
}()
if block != nil {
return block, PermanentEntry, nil
}
return nil, NoCacheEntry, NoSuchBlockError{ptr.ID}
} | go | func (b *BlockCacheStandard) GetWithLifetime(ptr BlockPointer) (
Block, BlockCacheLifetime, error) {
if b.cleanTransient != nil {
if tmp, ok := b.cleanTransient.Get(ptr.ID); ok {
block, ok := tmp.(Block)
if !ok {
return nil, NoCacheEntry, BadDataError{ptr.ID}
}
return block, TransientEntry, nil
}
}
block := func() Block {
b.cleanLock.RLock()
defer b.cleanLock.RUnlock()
return b.cleanPermanent[ptr.ID]
}()
if block != nil {
return block, PermanentEntry, nil
}
return nil, NoCacheEntry, NoSuchBlockError{ptr.ID}
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"GetWithLifetime",
"(",
"ptr",
"BlockPointer",
")",
"(",
"Block",
",",
"BlockCacheLifetime",
",",
"error",
")",
"{",
"if",
"b",
".",
"cleanTransient",
"!=",
"nil",
"{",
"if",
"tmp",
",",
"ok",
":=",
"b",
".",
"cleanTransient",
".",
"Get",
"(",
"ptr",
".",
"ID",
")",
";",
"ok",
"{",
"block",
",",
"ok",
":=",
"tmp",
".",
"(",
"Block",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"NoCacheEntry",
",",
"BadDataError",
"{",
"ptr",
".",
"ID",
"}",
"\n",
"}",
"\n",
"return",
"block",
",",
"TransientEntry",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"block",
":=",
"func",
"(",
")",
"Block",
"{",
"b",
".",
"cleanLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"b",
".",
"cleanLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"b",
".",
"cleanPermanent",
"[",
"ptr",
".",
"ID",
"]",
"\n",
"}",
"(",
")",
"\n",
"if",
"block",
"!=",
"nil",
"{",
"return",
"block",
",",
"PermanentEntry",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"NoCacheEntry",
",",
"NoSuchBlockError",
"{",
"ptr",
".",
"ID",
"}",
"\n",
"}"
] | // GetWithLifetime implements the BlockCache interface for BlockCacheStandard. | [
"GetWithLifetime",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L72-L94 |
159,738 | keybase/client | go/kbfs/data/bcache.go | Get | func (b *BlockCacheStandard) Get(ptr BlockPointer) (Block, error) {
block, _, err := b.GetWithLifetime(ptr)
return block, err
} | go | func (b *BlockCacheStandard) Get(ptr BlockPointer) (Block, error) {
block, _, err := b.GetWithLifetime(ptr)
return block, err
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"Get",
"(",
"ptr",
"BlockPointer",
")",
"(",
"Block",
",",
"error",
")",
"{",
"block",
",",
"_",
",",
"err",
":=",
"b",
".",
"GetWithLifetime",
"(",
"ptr",
")",
"\n",
"return",
"block",
",",
"err",
"\n",
"}"
] | // Get implements the BlockCache interface for BlockCacheStandard. | [
"Get",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L97-L100 |
159,739 | keybase/client | go/kbfs/data/bcache.go | CheckForKnownPtr | func (b *BlockCacheStandard) CheckForKnownPtr(tlf tlf.ID, block *FileBlock) (
BlockPointer, error) {
if block.IsInd {
return BlockPointer{}, NotDirectFileBlockError{}
}
if b.ids == nil {
return BlockPointer{}, nil
}
key := idCacheKey{tlf, block.GetHash()}
tmp, ok := b.ids.Get(key)
if !ok {
return BlockPointer{}, nil
}
ptr, ok := tmp.(BlockPointer)
if !ok {
return BlockPointer{}, fmt.Errorf("Unexpected cached id: %v", tmp)
}
return ptr, nil
} | go | func (b *BlockCacheStandard) CheckForKnownPtr(tlf tlf.ID, block *FileBlock) (
BlockPointer, error) {
if block.IsInd {
return BlockPointer{}, NotDirectFileBlockError{}
}
if b.ids == nil {
return BlockPointer{}, nil
}
key := idCacheKey{tlf, block.GetHash()}
tmp, ok := b.ids.Get(key)
if !ok {
return BlockPointer{}, nil
}
ptr, ok := tmp.(BlockPointer)
if !ok {
return BlockPointer{}, fmt.Errorf("Unexpected cached id: %v", tmp)
}
return ptr, nil
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"CheckForKnownPtr",
"(",
"tlf",
"tlf",
".",
"ID",
",",
"block",
"*",
"FileBlock",
")",
"(",
"BlockPointer",
",",
"error",
")",
"{",
"if",
"block",
".",
"IsInd",
"{",
"return",
"BlockPointer",
"{",
"}",
",",
"NotDirectFileBlockError",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"b",
".",
"ids",
"==",
"nil",
"{",
"return",
"BlockPointer",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"key",
":=",
"idCacheKey",
"{",
"tlf",
",",
"block",
".",
"GetHash",
"(",
")",
"}",
"\n",
"tmp",
",",
"ok",
":=",
"b",
".",
"ids",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BlockPointer",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"ptr",
",",
"ok",
":=",
"tmp",
".",
"(",
"BlockPointer",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BlockPointer",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tmp",
")",
"\n",
"}",
"\n",
"return",
"ptr",
",",
"nil",
"\n",
"}"
] | // CheckForKnownPtr implements the BlockCache interface for BlockCacheStandard. | [
"CheckForKnownPtr",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L139-L160 |
159,740 | keybase/client | go/kbfs/data/bcache.go | SetCleanBytesCapacity | func (b *BlockCacheStandard) SetCleanBytesCapacity(capacity uint64) {
atomic.StoreUint64(&b.cleanBytesCapacity, capacity)
} | go | func (b *BlockCacheStandard) SetCleanBytesCapacity(capacity uint64) {
atomic.StoreUint64(&b.cleanBytesCapacity, capacity)
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"SetCleanBytesCapacity",
"(",
"capacity",
"uint64",
")",
"{",
"atomic",
".",
"StoreUint64",
"(",
"&",
"b",
".",
"cleanBytesCapacity",
",",
"capacity",
")",
"\n",
"}"
] | // SetCleanBytesCapacity implements the BlockCache interface for
// BlockCacheStandard. | [
"SetCleanBytesCapacity",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L164-L166 |
159,741 | keybase/client | go/kbfs/data/bcache.go | Put | func (b *BlockCacheStandard) Put(
ptr BlockPointer, tlf tlf.ID, block Block,
lifetime BlockCacheLifetime, hashBehavior BlockCacheHashBehavior) error {
// We first check if the block shouldn't be cached, since CommonBlocks can
// take this path.
if lifetime == NoCacheEntry {
return nil
}
// Just in case we tried to cache a block type that shouldn't be cached,
// return an error. This is an insurance check. That said, this got rid of
// a flake in TestSBSConflicts, so we should still look for the underlying
// error.
switch block.(type) {
case *DirBlock:
case *FileBlock:
case *CommonBlock:
return errors.New("attempted to Put a common block")
default:
return errors.Errorf("attempted to Put an unknown block type %T", block)
}
var wasInCache bool
switch lifetime {
case TransientEntry:
// If it's the right type of block, store the hash -> ID mapping.
if fBlock, isFileBlock := block.(*FileBlock); b.ids != nil &&
isFileBlock && !fBlock.IsInd && hashBehavior == DoCacheHash {
key := idCacheKey{tlf, fBlock.GetHash()}
// zero out the refnonce, it doesn't matter
ptr.RefNonce = kbfsblock.ZeroRefNonce
b.ids.Add(key, ptr)
}
if b.cleanTransient == nil {
return nil
}
// We could use `cleanTransient.Contains()`, but that wouldn't update
// the LRU time. By using `Get`, we make it less likely that another
// goroutine will evict this block before we can `Put` it again.
_, wasInCache = b.cleanTransient.Get(ptr.ID)
// Cache it later, once we know there's room
case PermanentEntry:
if hashBehavior != SkipCacheHash {
return errors.New("Must skip cache hash for permanent entries")
}
func() {
b.cleanLock.Lock()
defer b.cleanLock.Unlock()
_, wasInCache = b.cleanPermanent[ptr.ID]
b.cleanPermanent[ptr.ID] = block
}()
default:
return fmt.Errorf("Unknown lifetime %v", lifetime)
}
transientCacheHasRoom := true
// We must make room whether the cache is transient or permanent, but only
// if it wasn't already in the cache.
// TODO: This is racy, where another goroutine can evict or add this block
// between our check above and our attempt to make room. If the other
// goroutine evicts this block, we under-count its size as 0. If the other
// goroutine inserts this block, we double-count it.
if !wasInCache {
size := uint64(getCachedBlockSize(block))
transientCacheHasRoom = b.makeRoomForSize(size, lifetime)
}
if lifetime == TransientEntry {
if !transientCacheHasRoom {
return CachePutCacheFullError{ptr.ID}
}
b.cleanTransient.Add(ptr.ID, block)
}
return nil
} | go | func (b *BlockCacheStandard) Put(
ptr BlockPointer, tlf tlf.ID, block Block,
lifetime BlockCacheLifetime, hashBehavior BlockCacheHashBehavior) error {
// We first check if the block shouldn't be cached, since CommonBlocks can
// take this path.
if lifetime == NoCacheEntry {
return nil
}
// Just in case we tried to cache a block type that shouldn't be cached,
// return an error. This is an insurance check. That said, this got rid of
// a flake in TestSBSConflicts, so we should still look for the underlying
// error.
switch block.(type) {
case *DirBlock:
case *FileBlock:
case *CommonBlock:
return errors.New("attempted to Put a common block")
default:
return errors.Errorf("attempted to Put an unknown block type %T", block)
}
var wasInCache bool
switch lifetime {
case TransientEntry:
// If it's the right type of block, store the hash -> ID mapping.
if fBlock, isFileBlock := block.(*FileBlock); b.ids != nil &&
isFileBlock && !fBlock.IsInd && hashBehavior == DoCacheHash {
key := idCacheKey{tlf, fBlock.GetHash()}
// zero out the refnonce, it doesn't matter
ptr.RefNonce = kbfsblock.ZeroRefNonce
b.ids.Add(key, ptr)
}
if b.cleanTransient == nil {
return nil
}
// We could use `cleanTransient.Contains()`, but that wouldn't update
// the LRU time. By using `Get`, we make it less likely that another
// goroutine will evict this block before we can `Put` it again.
_, wasInCache = b.cleanTransient.Get(ptr.ID)
// Cache it later, once we know there's room
case PermanentEntry:
if hashBehavior != SkipCacheHash {
return errors.New("Must skip cache hash for permanent entries")
}
func() {
b.cleanLock.Lock()
defer b.cleanLock.Unlock()
_, wasInCache = b.cleanPermanent[ptr.ID]
b.cleanPermanent[ptr.ID] = block
}()
default:
return fmt.Errorf("Unknown lifetime %v", lifetime)
}
transientCacheHasRoom := true
// We must make room whether the cache is transient or permanent, but only
// if it wasn't already in the cache.
// TODO: This is racy, where another goroutine can evict or add this block
// between our check above and our attempt to make room. If the other
// goroutine evicts this block, we under-count its size as 0. If the other
// goroutine inserts this block, we double-count it.
if !wasInCache {
size := uint64(getCachedBlockSize(block))
transientCacheHasRoom = b.makeRoomForSize(size, lifetime)
}
if lifetime == TransientEntry {
if !transientCacheHasRoom {
return CachePutCacheFullError{ptr.ID}
}
b.cleanTransient.Add(ptr.ID, block)
}
return nil
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"Put",
"(",
"ptr",
"BlockPointer",
",",
"tlf",
"tlf",
".",
"ID",
",",
"block",
"Block",
",",
"lifetime",
"BlockCacheLifetime",
",",
"hashBehavior",
"BlockCacheHashBehavior",
")",
"error",
"{",
"// We first check if the block shouldn't be cached, since CommonBlocks can",
"// take this path.",
"if",
"lifetime",
"==",
"NoCacheEntry",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// Just in case we tried to cache a block type that shouldn't be cached,",
"// return an error. This is an insurance check. That said, this got rid of",
"// a flake in TestSBSConflicts, so we should still look for the underlying",
"// error.",
"switch",
"block",
".",
"(",
"type",
")",
"{",
"case",
"*",
"DirBlock",
":",
"case",
"*",
"FileBlock",
":",
"case",
"*",
"CommonBlock",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"block",
")",
"\n",
"}",
"\n\n",
"var",
"wasInCache",
"bool",
"\n\n",
"switch",
"lifetime",
"{",
"case",
"TransientEntry",
":",
"// If it's the right type of block, store the hash -> ID mapping.",
"if",
"fBlock",
",",
"isFileBlock",
":=",
"block",
".",
"(",
"*",
"FileBlock",
")",
";",
"b",
".",
"ids",
"!=",
"nil",
"&&",
"isFileBlock",
"&&",
"!",
"fBlock",
".",
"IsInd",
"&&",
"hashBehavior",
"==",
"DoCacheHash",
"{",
"key",
":=",
"idCacheKey",
"{",
"tlf",
",",
"fBlock",
".",
"GetHash",
"(",
")",
"}",
"\n",
"// zero out the refnonce, it doesn't matter",
"ptr",
".",
"RefNonce",
"=",
"kbfsblock",
".",
"ZeroRefNonce",
"\n",
"b",
".",
"ids",
".",
"Add",
"(",
"key",
",",
"ptr",
")",
"\n",
"}",
"\n",
"if",
"b",
".",
"cleanTransient",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// We could use `cleanTransient.Contains()`, but that wouldn't update",
"// the LRU time. By using `Get`, we make it less likely that another",
"// goroutine will evict this block before we can `Put` it again.",
"_",
",",
"wasInCache",
"=",
"b",
".",
"cleanTransient",
".",
"Get",
"(",
"ptr",
".",
"ID",
")",
"\n",
"// Cache it later, once we know there's room",
"case",
"PermanentEntry",
":",
"if",
"hashBehavior",
"!=",
"SkipCacheHash",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"func",
"(",
")",
"{",
"b",
".",
"cleanLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"cleanLock",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"wasInCache",
"=",
"b",
".",
"cleanPermanent",
"[",
"ptr",
".",
"ID",
"]",
"\n",
"b",
".",
"cleanPermanent",
"[",
"ptr",
".",
"ID",
"]",
"=",
"block",
"\n",
"}",
"(",
")",
"\n\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"lifetime",
")",
"\n",
"}",
"\n\n",
"transientCacheHasRoom",
":=",
"true",
"\n",
"// We must make room whether the cache is transient or permanent, but only",
"// if it wasn't already in the cache.",
"// TODO: This is racy, where another goroutine can evict or add this block",
"// between our check above and our attempt to make room. If the other",
"// goroutine evicts this block, we under-count its size as 0. If the other",
"// goroutine inserts this block, we double-count it.",
"if",
"!",
"wasInCache",
"{",
"size",
":=",
"uint64",
"(",
"getCachedBlockSize",
"(",
"block",
")",
")",
"\n",
"transientCacheHasRoom",
"=",
"b",
".",
"makeRoomForSize",
"(",
"size",
",",
"lifetime",
")",
"\n",
"}",
"\n",
"if",
"lifetime",
"==",
"TransientEntry",
"{",
"if",
"!",
"transientCacheHasRoom",
"{",
"return",
"CachePutCacheFullError",
"{",
"ptr",
".",
"ID",
"}",
"\n",
"}",
"\n",
"b",
".",
"cleanTransient",
".",
"Add",
"(",
"ptr",
".",
"ID",
",",
"block",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Put implements the BlockCache interface for BlockCacheStandard.
// This method is idempotent for a given ptr, but that invariant is
// not currently goroutine-safe, and it does not hold if a block size
// changes between Puts. That is, we assume that a cached block
// associated with a given pointer will never change its size, even
// when it gets Put into the cache again. | [
"Put",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
".",
"This",
"method",
"is",
"idempotent",
"for",
"a",
"given",
"ptr",
"but",
"that",
"invariant",
"is",
"not",
"currently",
"goroutine",
"-",
"safe",
"and",
"it",
"does",
"not",
"hold",
"if",
"a",
"block",
"size",
"changes",
"between",
"Puts",
".",
"That",
"is",
"we",
"assume",
"that",
"a",
"cached",
"block",
"associated",
"with",
"a",
"given",
"pointer",
"will",
"never",
"change",
"its",
"size",
"even",
"when",
"it",
"gets",
"Put",
"into",
"the",
"cache",
"again",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L234-L310 |
159,742 | keybase/client | go/kbfs/data/bcache.go | DeletePermanent | func (b *BlockCacheStandard) DeletePermanent(id kbfsblock.ID) error {
b.cleanLock.Lock()
defer b.cleanLock.Unlock()
block, ok := b.cleanPermanent[id]
if ok {
delete(b.cleanPermanent, id)
b.subtractBlockBytes(block)
}
return nil
} | go | func (b *BlockCacheStandard) DeletePermanent(id kbfsblock.ID) error {
b.cleanLock.Lock()
defer b.cleanLock.Unlock()
block, ok := b.cleanPermanent[id]
if ok {
delete(b.cleanPermanent, id)
b.subtractBlockBytes(block)
}
return nil
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"DeletePermanent",
"(",
"id",
"kbfsblock",
".",
"ID",
")",
"error",
"{",
"b",
".",
"cleanLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"cleanLock",
".",
"Unlock",
"(",
")",
"\n",
"block",
",",
"ok",
":=",
"b",
".",
"cleanPermanent",
"[",
"id",
"]",
"\n",
"if",
"ok",
"{",
"delete",
"(",
"b",
".",
"cleanPermanent",
",",
"id",
")",
"\n",
"b",
".",
"subtractBlockBytes",
"(",
"block",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // DeletePermanent implements the BlockCache interface for
// BlockCacheStandard. | [
"DeletePermanent",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L314-L323 |
159,743 | keybase/client | go/kbfs/data/bcache.go | DeleteTransient | func (b *BlockCacheStandard) DeleteTransient(
id kbfsblock.ID, tlf tlf.ID) error {
if b.cleanTransient == nil {
return nil
}
// If the block is cached and a file block, delete the known
// pointer as well.
if tmp, ok := b.cleanTransient.Get(id); ok {
block, ok := tmp.(Block)
if !ok {
return BadDataError{id}
}
// Remove the key if it exists
if fBlock, ok := block.(*FileBlock); b.ids != nil && ok &&
!fBlock.IsInd {
_, hash := kbfshash.DoRawDefaultHash(fBlock.Contents)
key := idCacheKey{tlf, hash}
b.ids.Remove(key)
}
b.cleanTransient.Remove(id)
}
return nil
} | go | func (b *BlockCacheStandard) DeleteTransient(
id kbfsblock.ID, tlf tlf.ID) error {
if b.cleanTransient == nil {
return nil
}
// If the block is cached and a file block, delete the known
// pointer as well.
if tmp, ok := b.cleanTransient.Get(id); ok {
block, ok := tmp.(Block)
if !ok {
return BadDataError{id}
}
// Remove the key if it exists
if fBlock, ok := block.(*FileBlock); b.ids != nil && ok &&
!fBlock.IsInd {
_, hash := kbfshash.DoRawDefaultHash(fBlock.Contents)
key := idCacheKey{tlf, hash}
b.ids.Remove(key)
}
b.cleanTransient.Remove(id)
}
return nil
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"DeleteTransient",
"(",
"id",
"kbfsblock",
".",
"ID",
",",
"tlf",
"tlf",
".",
"ID",
")",
"error",
"{",
"if",
"b",
".",
"cleanTransient",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// If the block is cached and a file block, delete the known",
"// pointer as well.",
"if",
"tmp",
",",
"ok",
":=",
"b",
".",
"cleanTransient",
".",
"Get",
"(",
"id",
")",
";",
"ok",
"{",
"block",
",",
"ok",
":=",
"tmp",
".",
"(",
"Block",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BadDataError",
"{",
"id",
"}",
"\n",
"}",
"\n\n",
"// Remove the key if it exists",
"if",
"fBlock",
",",
"ok",
":=",
"block",
".",
"(",
"*",
"FileBlock",
")",
";",
"b",
".",
"ids",
"!=",
"nil",
"&&",
"ok",
"&&",
"!",
"fBlock",
".",
"IsInd",
"{",
"_",
",",
"hash",
":=",
"kbfshash",
".",
"DoRawDefaultHash",
"(",
"fBlock",
".",
"Contents",
")",
"\n",
"key",
":=",
"idCacheKey",
"{",
"tlf",
",",
"hash",
"}",
"\n",
"b",
".",
"ids",
".",
"Remove",
"(",
"key",
")",
"\n",
"}",
"\n\n",
"b",
".",
"cleanTransient",
".",
"Remove",
"(",
"id",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // DeleteTransient implements the BlockCache interface for BlockCacheStandard. | [
"DeleteTransient",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L326-L351 |
159,744 | keybase/client | go/kbfs/data/bcache.go | DeleteKnownPtr | func (b *BlockCacheStandard) DeleteKnownPtr(tlf tlf.ID, block *FileBlock) error {
if block.IsInd {
return NotDirectFileBlockError{}
}
if b.ids == nil {
return nil
}
_, hash := kbfshash.DoRawDefaultHash(block.Contents)
key := idCacheKey{tlf, hash}
b.ids.Remove(key)
return nil
} | go | func (b *BlockCacheStandard) DeleteKnownPtr(tlf tlf.ID, block *FileBlock) error {
if block.IsInd {
return NotDirectFileBlockError{}
}
if b.ids == nil {
return nil
}
_, hash := kbfshash.DoRawDefaultHash(block.Contents)
key := idCacheKey{tlf, hash}
b.ids.Remove(key)
return nil
} | [
"func",
"(",
"b",
"*",
"BlockCacheStandard",
")",
"DeleteKnownPtr",
"(",
"tlf",
"tlf",
".",
"ID",
",",
"block",
"*",
"FileBlock",
")",
"error",
"{",
"if",
"block",
".",
"IsInd",
"{",
"return",
"NotDirectFileBlockError",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"b",
".",
"ids",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"_",
",",
"hash",
":=",
"kbfshash",
".",
"DoRawDefaultHash",
"(",
"block",
".",
"Contents",
")",
"\n",
"key",
":=",
"idCacheKey",
"{",
"tlf",
",",
"hash",
"}",
"\n",
"b",
".",
"ids",
".",
"Remove",
"(",
"key",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // DeleteKnownPtr implements the BlockCache interface for BlockCacheStandard. | [
"DeleteKnownPtr",
"implements",
"the",
"BlockCache",
"interface",
"for",
"BlockCacheStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/bcache.go#L354-L367 |
159,745 | keybase/client | go/engine/paperprovision.go | fetchLKS | func (e *PaperProvisionEngine) fetchLKS(m libkb.MetaContext, encKey libkb.GenericKey) error {
gen, clientLKS, err := fetchLKS(m, encKey)
if err != nil {
return err
}
e.lks = libkb.NewLKSecWithClientHalf(clientLKS, gen, e.User.GetUID())
return nil
} | go | func (e *PaperProvisionEngine) fetchLKS(m libkb.MetaContext, encKey libkb.GenericKey) error {
gen, clientLKS, err := fetchLKS(m, encKey)
if err != nil {
return err
}
e.lks = libkb.NewLKSecWithClientHalf(clientLKS, gen, e.User.GetUID())
return nil
} | [
"func",
"(",
"e",
"*",
"PaperProvisionEngine",
")",
"fetchLKS",
"(",
"m",
"libkb",
".",
"MetaContext",
",",
"encKey",
"libkb",
".",
"GenericKey",
")",
"error",
"{",
"gen",
",",
"clientLKS",
",",
"err",
":=",
"fetchLKS",
"(",
"m",
",",
"encKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"e",
".",
"lks",
"=",
"libkb",
".",
"NewLKSecWithClientHalf",
"(",
"clientLKS",
",",
"gen",
",",
"e",
".",
"User",
".",
"GetUID",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // copied from loginProvision | [
"copied",
"from",
"loginProvision"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/paperprovision.go#L173-L180 |
159,746 | keybase/client | go/engine/paperprovision.go | makeDeviceKeysWithSigner | func (e *PaperProvisionEngine) makeDeviceKeysWithSigner(m libkb.MetaContext, signer libkb.GenericKey) error {
args, err := e.makeDeviceWrapArgs(m)
if err != nil {
return err
}
args.Signer = signer
args.IsEldest = false // just to be explicit
args.EldestKID = e.User.GetEldestKID()
return e.makeDeviceKeys(m, args)
} | go | func (e *PaperProvisionEngine) makeDeviceKeysWithSigner(m libkb.MetaContext, signer libkb.GenericKey) error {
args, err := e.makeDeviceWrapArgs(m)
if err != nil {
return err
}
args.Signer = signer
args.IsEldest = false // just to be explicit
args.EldestKID = e.User.GetEldestKID()
return e.makeDeviceKeys(m, args)
} | [
"func",
"(",
"e",
"*",
"PaperProvisionEngine",
")",
"makeDeviceKeysWithSigner",
"(",
"m",
"libkb",
".",
"MetaContext",
",",
"signer",
"libkb",
".",
"GenericKey",
")",
"error",
"{",
"args",
",",
"err",
":=",
"e",
".",
"makeDeviceWrapArgs",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"args",
".",
"Signer",
"=",
"signer",
"\n",
"args",
".",
"IsEldest",
"=",
"false",
"// just to be explicit",
"\n",
"args",
".",
"EldestKID",
"=",
"e",
".",
"User",
".",
"GetEldestKID",
"(",
")",
"\n\n",
"return",
"e",
".",
"makeDeviceKeys",
"(",
"m",
",",
"args",
")",
"\n",
"}"
] | // copied from loginProvision
// makeDeviceKeysWithSigner creates device keys given a signing
// key. | [
"copied",
"from",
"loginProvision",
"makeDeviceKeysWithSigner",
"creates",
"device",
"keys",
"given",
"a",
"signing",
"key",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/paperprovision.go#L185-L195 |
159,747 | keybase/client | go/engine/paperprovision.go | makeDeviceWrapArgs | func (e *PaperProvisionEngine) makeDeviceWrapArgs(m libkb.MetaContext) (*DeviceWrapArgs, error) {
if err := e.ensureLKSec(m); err != nil {
return nil, err
}
return &DeviceWrapArgs{
Me: e.User,
DeviceName: e.DeviceName,
DeviceType: "desktop",
Lks: e.lks,
PerUserKeyring: e.perUserKeyring,
}, nil
} | go | func (e *PaperProvisionEngine) makeDeviceWrapArgs(m libkb.MetaContext) (*DeviceWrapArgs, error) {
if err := e.ensureLKSec(m); err != nil {
return nil, err
}
return &DeviceWrapArgs{
Me: e.User,
DeviceName: e.DeviceName,
DeviceType: "desktop",
Lks: e.lks,
PerUserKeyring: e.perUserKeyring,
}, nil
} | [
"func",
"(",
"e",
"*",
"PaperProvisionEngine",
")",
"makeDeviceWrapArgs",
"(",
"m",
"libkb",
".",
"MetaContext",
")",
"(",
"*",
"DeviceWrapArgs",
",",
"error",
")",
"{",
"if",
"err",
":=",
"e",
".",
"ensureLKSec",
"(",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"DeviceWrapArgs",
"{",
"Me",
":",
"e",
".",
"User",
",",
"DeviceName",
":",
"e",
".",
"DeviceName",
",",
"DeviceType",
":",
"\"",
"\"",
",",
"Lks",
":",
"e",
".",
"lks",
",",
"PerUserKeyring",
":",
"e",
".",
"perUserKeyring",
",",
"}",
",",
"nil",
"\n",
"}"
] | // copied from loginProvision
// makeDeviceWrapArgs creates a base set of args for DeviceWrap.
// It ensures that LKSec is created. It also gets a new device
// name for this device. | [
"copied",
"from",
"loginProvision",
"makeDeviceWrapArgs",
"creates",
"a",
"base",
"set",
"of",
"args",
"for",
"DeviceWrap",
".",
"It",
"ensures",
"that",
"LKSec",
"is",
"created",
".",
"It",
"also",
"gets",
"a",
"new",
"device",
"name",
"for",
"this",
"device",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/paperprovision.go#L201-L213 |
159,748 | keybase/client | go/engine/paperprovision.go | makeDeviceKeys | func (e *PaperProvisionEngine) makeDeviceKeys(m libkb.MetaContext, args *DeviceWrapArgs) error {
e.deviceWrapEng = NewDeviceWrap(m.G(), args)
return RunEngine2(m, e.deviceWrapEng)
} | go | func (e *PaperProvisionEngine) makeDeviceKeys(m libkb.MetaContext, args *DeviceWrapArgs) error {
e.deviceWrapEng = NewDeviceWrap(m.G(), args)
return RunEngine2(m, e.deviceWrapEng)
} | [
"func",
"(",
"e",
"*",
"PaperProvisionEngine",
")",
"makeDeviceKeys",
"(",
"m",
"libkb",
".",
"MetaContext",
",",
"args",
"*",
"DeviceWrapArgs",
")",
"error",
"{",
"e",
".",
"deviceWrapEng",
"=",
"NewDeviceWrap",
"(",
"m",
".",
"G",
"(",
")",
",",
"args",
")",
"\n",
"return",
"RunEngine2",
"(",
"m",
",",
"e",
".",
"deviceWrapEng",
")",
"\n",
"}"
] | // Copied from loginProvision. makeDeviceKeys uses DeviceWrap to
// generate device keys and sets active device. | [
"Copied",
"from",
"loginProvision",
".",
"makeDeviceKeys",
"uses",
"DeviceWrap",
"to",
"generate",
"device",
"keys",
"and",
"sets",
"active",
"device",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/paperprovision.go#L217-L220 |
159,749 | keybase/client | go/kbfs/kbfsgit/start.go | Start | func Start(ctx context.Context, options StartOptions,
kbCtx libkbfs.Context, defaultLogPath string,
input io.Reader, output io.Writer, errput io.Writer) *libfs.Error {
// Ideally we wouldn't print this if the verbosity is 0, but we
// don't know that until we start parsing options. TODO: get rid
// of this once we integrate with the kbfs daemon.
errput.Write([]byte("Initializing Keybase... "))
ctx, config, err := libgit.Init(
ctx, options.KbfsParams, kbCtx, nil, defaultLogPath,
kbCtx.GetVDebugSetting())
if err != nil {
return libfs.InitError(err.Error())
}
defer config.Shutdown(ctx)
config.MakeLogger("").CDebugf(
ctx, "Running Git remote helper: remote=%s, repo=%s, storageRoot=%s",
options.Remote, options.Repo, options.KbfsParams.StorageRoot)
errput.Write([]byte("done.\n"))
r, err := newRunner(
ctx, config, options.Remote, options.Repo, options.GitDir,
input, output, errput)
if err != nil {
return libfs.InitError(err.Error())
}
errCh := make(chan error, 1)
go func() {
errCh <- r.processCommands(ctx)
}()
select {
case err := <-errCh:
if err != nil {
return libfs.InitError(err.Error())
}
return nil
case <-ctx.Done():
return libfs.InitError(ctx.Err().Error())
}
} | go | func Start(ctx context.Context, options StartOptions,
kbCtx libkbfs.Context, defaultLogPath string,
input io.Reader, output io.Writer, errput io.Writer) *libfs.Error {
// Ideally we wouldn't print this if the verbosity is 0, but we
// don't know that until we start parsing options. TODO: get rid
// of this once we integrate with the kbfs daemon.
errput.Write([]byte("Initializing Keybase... "))
ctx, config, err := libgit.Init(
ctx, options.KbfsParams, kbCtx, nil, defaultLogPath,
kbCtx.GetVDebugSetting())
if err != nil {
return libfs.InitError(err.Error())
}
defer config.Shutdown(ctx)
config.MakeLogger("").CDebugf(
ctx, "Running Git remote helper: remote=%s, repo=%s, storageRoot=%s",
options.Remote, options.Repo, options.KbfsParams.StorageRoot)
errput.Write([]byte("done.\n"))
r, err := newRunner(
ctx, config, options.Remote, options.Repo, options.GitDir,
input, output, errput)
if err != nil {
return libfs.InitError(err.Error())
}
errCh := make(chan error, 1)
go func() {
errCh <- r.processCommands(ctx)
}()
select {
case err := <-errCh:
if err != nil {
return libfs.InitError(err.Error())
}
return nil
case <-ctx.Done():
return libfs.InitError(ctx.Err().Error())
}
} | [
"func",
"Start",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"StartOptions",
",",
"kbCtx",
"libkbfs",
".",
"Context",
",",
"defaultLogPath",
"string",
",",
"input",
"io",
".",
"Reader",
",",
"output",
"io",
".",
"Writer",
",",
"errput",
"io",
".",
"Writer",
")",
"*",
"libfs",
".",
"Error",
"{",
"// Ideally we wouldn't print this if the verbosity is 0, but we",
"// don't know that until we start parsing options. TODO: get rid",
"// of this once we integrate with the kbfs daemon.",
"errput",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"ctx",
",",
"config",
",",
"err",
":=",
"libgit",
".",
"Init",
"(",
"ctx",
",",
"options",
".",
"KbfsParams",
",",
"kbCtx",
",",
"nil",
",",
"defaultLogPath",
",",
"kbCtx",
".",
"GetVDebugSetting",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"libfs",
".",
"InitError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"defer",
"config",
".",
"Shutdown",
"(",
"ctx",
")",
"\n\n",
"config",
".",
"MakeLogger",
"(",
"\"",
"\"",
")",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"options",
".",
"Remote",
",",
"options",
".",
"Repo",
",",
"options",
".",
"KbfsParams",
".",
"StorageRoot",
")",
"\n",
"errput",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n\n",
"r",
",",
"err",
":=",
"newRunner",
"(",
"ctx",
",",
"config",
",",
"options",
".",
"Remote",
",",
"options",
".",
"Repo",
",",
"options",
".",
"GitDir",
",",
"input",
",",
"output",
",",
"errput",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"libfs",
".",
"InitError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"errCh",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"errCh",
"<-",
"r",
".",
"processCommands",
"(",
"ctx",
")",
"\n",
"}",
"(",
")",
"\n\n",
"select",
"{",
"case",
"err",
":=",
"<-",
"errCh",
":",
"if",
"err",
"!=",
"nil",
"{",
"return",
"libfs",
".",
"InitError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"libfs",
".",
"InitError",
"(",
"ctx",
".",
"Err",
"(",
")",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Start starts the kbfsgit logic, and begins listening for git
// commands from `input` and responding to them via `output`. | [
"Start",
"starts",
"the",
"kbfsgit",
"logic",
"and",
"begins",
"listening",
"for",
"git",
"commands",
"from",
"input",
"and",
"responding",
"to",
"them",
"via",
"output",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsgit/start.go#L32-L73 |
159,750 | keybase/client | go/kbfs/idutil/errors.go | Error | func (e TlfNameNotCanonical) Error() string {
return fmt.Sprintf("TLF name %s isn't canonical: try %s instead",
e.Name, e.NameToTry)
} | go | func (e TlfNameNotCanonical) Error() string {
return fmt.Sprintf("TLF name %s isn't canonical: try %s instead",
e.Name, e.NameToTry)
} | [
"func",
"(",
"e",
"TlfNameNotCanonical",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"Name",
",",
"e",
".",
"NameToTry",
")",
"\n",
"}"
] | // Error implements the error interface for TlfNameNotCanonical. | [
"Error",
"implements",
"the",
"error",
"interface",
"for",
"TlfNameNotCanonical",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/idutil/errors.go#L73-L76 |
159,751 | keybase/client | go/libkb/util.go | safeWriteToFileOnce | func safeWriteToFileOnce(g SafeWriteLogger, t SafeWriter, mode os.FileMode) (err error) {
fn := t.GetFilename()
g.Debug("+ SafeWriteToFile(%q)", fn)
defer func() {
g.Debug("- SafeWriteToFile(%q) -> %s", fn, ErrToOk(err))
}()
tmpfn, tmp, err := OpenTempFile(fn, "", mode)
if err != nil {
return err
}
g.Debug("| Temporary file generated: %s", tmpfn)
defer tmp.Close()
defer ShredFile(tmpfn)
g.Debug("| WriteTo %s", tmpfn)
n, err := t.WriteTo(tmp)
if err != nil {
g.Errorf("| Error writing temporary file %s: %s", tmpfn, err)
return err
}
if n != 0 {
// unfortunately, some implementations always return 0 for the number
// of bytes written, so not much info there, but will log it when
// it isn't 0.
g.Debug("| bytes written to temporary file %s: %d", tmpfn, n)
}
if err := tmp.Sync(); err != nil {
g.Errorf("| Error syncing temporary file %s: %s", tmpfn, err)
return err
}
if err := tmp.Close(); err != nil {
g.Errorf("| Error closing temporary file %s: %s", tmpfn, err)
return err
}
g.Debug("| Renaming temporary file %s -> permanent file %s", tmpfn, fn)
if err := os.Rename(tmpfn, fn); err != nil {
g.Errorf("| Error renaming temporary file %s -> permanent file %s: %s", tmpfn, fn, err)
return err
}
if runtime.GOOS == "android" {
g.Debug("| Android extra checks in safeWriteToFile")
info, err := os.Stat(fn)
if err != nil {
g.Errorf("| Error os.Stat(%s): %s", fn, err)
return err
}
g.Debug("| File info: name = %s", info.Name())
g.Debug("| File info: size = %d", info.Size())
g.Debug("| File info: mode = %s", info.Mode())
g.Debug("| File info: mod time = %s", info.ModTime())
g.Debug("| Android extra checks done")
}
g.Debug("| Done writing to file %s", fn)
return nil
} | go | func safeWriteToFileOnce(g SafeWriteLogger, t SafeWriter, mode os.FileMode) (err error) {
fn := t.GetFilename()
g.Debug("+ SafeWriteToFile(%q)", fn)
defer func() {
g.Debug("- SafeWriteToFile(%q) -> %s", fn, ErrToOk(err))
}()
tmpfn, tmp, err := OpenTempFile(fn, "", mode)
if err != nil {
return err
}
g.Debug("| Temporary file generated: %s", tmpfn)
defer tmp.Close()
defer ShredFile(tmpfn)
g.Debug("| WriteTo %s", tmpfn)
n, err := t.WriteTo(tmp)
if err != nil {
g.Errorf("| Error writing temporary file %s: %s", tmpfn, err)
return err
}
if n != 0 {
// unfortunately, some implementations always return 0 for the number
// of bytes written, so not much info there, but will log it when
// it isn't 0.
g.Debug("| bytes written to temporary file %s: %d", tmpfn, n)
}
if err := tmp.Sync(); err != nil {
g.Errorf("| Error syncing temporary file %s: %s", tmpfn, err)
return err
}
if err := tmp.Close(); err != nil {
g.Errorf("| Error closing temporary file %s: %s", tmpfn, err)
return err
}
g.Debug("| Renaming temporary file %s -> permanent file %s", tmpfn, fn)
if err := os.Rename(tmpfn, fn); err != nil {
g.Errorf("| Error renaming temporary file %s -> permanent file %s: %s", tmpfn, fn, err)
return err
}
if runtime.GOOS == "android" {
g.Debug("| Android extra checks in safeWriteToFile")
info, err := os.Stat(fn)
if err != nil {
g.Errorf("| Error os.Stat(%s): %s", fn, err)
return err
}
g.Debug("| File info: name = %s", info.Name())
g.Debug("| File info: size = %d", info.Size())
g.Debug("| File info: mode = %s", info.Mode())
g.Debug("| File info: mod time = %s", info.ModTime())
g.Debug("| Android extra checks done")
}
g.Debug("| Done writing to file %s", fn)
return nil
} | [
"func",
"safeWriteToFileOnce",
"(",
"g",
"SafeWriteLogger",
",",
"t",
"SafeWriter",
",",
"mode",
"os",
".",
"FileMode",
")",
"(",
"err",
"error",
")",
"{",
"fn",
":=",
"t",
".",
"GetFilename",
"(",
")",
"\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"fn",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"fn",
",",
"ErrToOk",
"(",
"err",
")",
")",
"\n",
"}",
"(",
")",
"\n\n",
"tmpfn",
",",
"tmp",
",",
"err",
":=",
"OpenTempFile",
"(",
"fn",
",",
"\"",
"\"",
",",
"mode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"tmpfn",
")",
"\n",
"defer",
"tmp",
".",
"Close",
"(",
")",
"\n",
"defer",
"ShredFile",
"(",
"tmpfn",
")",
"\n\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"tmpfn",
")",
"\n",
"n",
",",
"err",
":=",
"t",
".",
"WriteTo",
"(",
"tmp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"g",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tmpfn",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"0",
"{",
"// unfortunately, some implementations always return 0 for the number",
"// of bytes written, so not much info there, but will log it when",
"// it isn't 0.",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"tmpfn",
",",
"n",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tmp",
".",
"Sync",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"g",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tmpfn",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tmp",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"g",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tmpfn",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"tmpfn",
",",
"fn",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"Rename",
"(",
"tmpfn",
",",
"fn",
")",
";",
"err",
"!=",
"nil",
"{",
"g",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tmpfn",
",",
"fn",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"g",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"info",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"fn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"g",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fn",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"info",
".",
"Name",
"(",
")",
")",
"\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"info",
".",
"Size",
"(",
")",
")",
"\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"info",
".",
"Mode",
"(",
")",
")",
"\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"info",
".",
"ModTime",
"(",
")",
")",
"\n\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"g",
".",
"Debug",
"(",
"\"",
"\"",
",",
"fn",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SafeWriteToFile to safely write to a file. Use mode=0 for default permissions. | [
"SafeWriteToFile",
"to",
"safely",
"write",
"to",
"a",
"file",
".",
"Use",
"mode",
"=",
"0",
"for",
"default",
"permissions",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L186-L248 |
159,752 | keybase/client | go/libkb/util.go | Contains | func Contains(s string, list []string) bool {
return IsIn(s, list, false)
} | go | func Contains(s string, list []string) bool {
return IsIn(s, list, false)
} | [
"func",
"Contains",
"(",
"s",
"string",
",",
"list",
"[",
"]",
"string",
")",
"bool",
"{",
"return",
"IsIn",
"(",
"s",
",",
"list",
",",
"false",
")",
"\n",
"}"
] | // Contains returns true if string is contained in string slice | [
"Contains",
"returns",
"true",
"if",
"string",
"is",
"contained",
"in",
"string",
"slice"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L269-L271 |
159,753 | keybase/client | go/libkb/util.go | IsIn | func IsIn(needle string, haystack []string, ci bool) bool {
for _, h := range haystack {
if (ci && Cicmp(h, needle)) || (!ci && h == needle) {
return true
}
}
return false
} | go | func IsIn(needle string, haystack []string, ci bool) bool {
for _, h := range haystack {
if (ci && Cicmp(h, needle)) || (!ci && h == needle) {
return true
}
}
return false
} | [
"func",
"IsIn",
"(",
"needle",
"string",
",",
"haystack",
"[",
"]",
"string",
",",
"ci",
"bool",
")",
"bool",
"{",
"for",
"_",
",",
"h",
":=",
"range",
"haystack",
"{",
"if",
"(",
"ci",
"&&",
"Cicmp",
"(",
"h",
",",
"needle",
")",
")",
"||",
"(",
"!",
"ci",
"&&",
"h",
"==",
"needle",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsIn checks for needle in haystack, ci means case-insensitive. | [
"IsIn",
"checks",
"for",
"needle",
"in",
"haystack",
"ci",
"means",
"case",
"-",
"insensitive",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L274-L281 |
159,754 | keybase/client | go/libkb/util.go | IsPossiblePhoneNumber | func IsPossiblePhoneNumber(phone keybase1.PhoneNumber) error {
if !phoneRE.MatchString(string(phone)) {
return fmt.Errorf("Invalid phone number, expected +11234567890 format")
}
return nil
} | go | func IsPossiblePhoneNumber(phone keybase1.PhoneNumber) error {
if !phoneRE.MatchString(string(phone)) {
return fmt.Errorf("Invalid phone number, expected +11234567890 format")
}
return nil
} | [
"func",
"IsPossiblePhoneNumber",
"(",
"phone",
"keybase1",
".",
"PhoneNumber",
")",
"error",
"{",
"if",
"!",
"phoneRE",
".",
"MatchString",
"(",
"string",
"(",
"phone",
")",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // IsPossiblePhoneNumber checks if s is string of digits in phone number format | [
"IsPossiblePhoneNumber",
"checks",
"if",
"s",
"is",
"string",
"of",
"digits",
"in",
"phone",
"number",
"format"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L315-L320 |
159,755 | keybase/client | go/libkb/util.go | MakeURI | func MakeURI(prot string, host string) string {
if prot == "" {
return host
}
if prot[len(prot)-1] != ':' {
prot += ":"
}
return prot + "//" + host
} | go | func MakeURI(prot string, host string) string {
if prot == "" {
return host
}
if prot[len(prot)-1] != ':' {
prot += ":"
}
return prot + "//" + host
} | [
"func",
"MakeURI",
"(",
"prot",
"string",
",",
"host",
"string",
")",
"string",
"{",
"if",
"prot",
"==",
"\"",
"\"",
"{",
"return",
"host",
"\n",
"}",
"\n",
"if",
"prot",
"[",
"len",
"(",
"prot",
")",
"-",
"1",
"]",
"!=",
"':'",
"{",
"prot",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"prot",
"+",
"\"",
"\"",
"+",
"host",
"\n",
"}"
] | // MakeURI makes a URI string out of the given protocol and
// host strings, adding necessary punctuation in between. | [
"MakeURI",
"makes",
"a",
"URI",
"string",
"out",
"of",
"the",
"given",
"protocol",
"and",
"host",
"strings",
"adding",
"necessary",
"punctuation",
"in",
"between",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L406-L414 |
159,756 | keybase/client | go/libkb/util.go | RemoveNilErrors | func RemoveNilErrors(errs []error) []error {
var r []error
for _, err := range errs {
if err != nil {
r = append(r, err)
}
}
return r
} | go | func RemoveNilErrors(errs []error) []error {
var r []error
for _, err := range errs {
if err != nil {
r = append(r, err)
}
}
return r
} | [
"func",
"RemoveNilErrors",
"(",
"errs",
"[",
"]",
"error",
")",
"[",
"]",
"error",
"{",
"var",
"r",
"[",
"]",
"error",
"\n",
"for",
"_",
",",
"err",
":=",
"range",
"errs",
"{",
"if",
"err",
"!=",
"nil",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // RemoveNilErrors returns error slice with ni errors removed. | [
"RemoveNilErrors",
"returns",
"error",
"slice",
"with",
"ni",
"errors",
"removed",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L417-L425 |
159,757 | keybase/client | go/libkb/util.go | CombineErrors | func CombineErrors(errs ...error) error {
errs = RemoveNilErrors(errs)
if len(errs) == 0 {
return nil
} else if len(errs) == 1 {
return errs[0]
}
msgs := []string{}
for _, err := range errs {
msgs = append(msgs, err.Error())
}
return fmt.Errorf("There were multiple errors: %s", strings.Join(msgs, "; "))
} | go | func CombineErrors(errs ...error) error {
errs = RemoveNilErrors(errs)
if len(errs) == 0 {
return nil
} else if len(errs) == 1 {
return errs[0]
}
msgs := []string{}
for _, err := range errs {
msgs = append(msgs, err.Error())
}
return fmt.Errorf("There were multiple errors: %s", strings.Join(msgs, "; "))
} | [
"func",
"CombineErrors",
"(",
"errs",
"...",
"error",
")",
"error",
"{",
"errs",
"=",
"RemoveNilErrors",
"(",
"errs",
")",
"\n",
"if",
"len",
"(",
"errs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"len",
"(",
"errs",
")",
"==",
"1",
"{",
"return",
"errs",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"msgs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"err",
":=",
"range",
"errs",
"{",
"msgs",
"=",
"append",
"(",
"msgs",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"msgs",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // CombineErrors returns a single error for multiple errors, or nil if none. | [
"CombineErrors",
"returns",
"a",
"single",
"error",
"for",
"multiple",
"errors",
"or",
"nil",
"if",
"none",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L428-L441 |
159,758 | keybase/client | go/libkb/util.go | SplitByRunes | func SplitByRunes(s string, separators []rune) []string {
f := func(r rune) bool {
for _, s := range separators {
if r == s {
return true
}
}
return false
}
return strings.FieldsFunc(s, f)
} | go | func SplitByRunes(s string, separators []rune) []string {
f := func(r rune) bool {
for _, s := range separators {
if r == s {
return true
}
}
return false
}
return strings.FieldsFunc(s, f)
} | [
"func",
"SplitByRunes",
"(",
"s",
"string",
",",
"separators",
"[",
"]",
"rune",
")",
"[",
"]",
"string",
"{",
"f",
":=",
"func",
"(",
"r",
"rune",
")",
"bool",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"separators",
"{",
"if",
"r",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"return",
"strings",
".",
"FieldsFunc",
"(",
"s",
",",
"f",
")",
"\n",
"}"
] | // SplitByRunes splits string by runes | [
"SplitByRunes",
"splits",
"string",
"by",
"runes"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L608-L618 |
159,759 | keybase/client | go/libkb/util.go | DigestForFileAtPath | func DigestForFileAtPath(path string) (string, error) {
f, err := os.Open(path)
if err != nil {
return "", err
}
defer f.Close()
return Digest(f)
} | go | func DigestForFileAtPath(path string) (string, error) {
f, err := os.Open(path)
if err != nil {
return "", err
}
defer f.Close()
return Digest(f)
} | [
"func",
"DigestForFileAtPath",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"Digest",
"(",
"f",
")",
"\n",
"}"
] | // DigestForFileAtPath returns a SHA256 digest for file at specified path | [
"DigestForFileAtPath",
"returns",
"a",
"SHA256",
"digest",
"for",
"file",
"at",
"specified",
"path"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L642-L649 |
159,760 | keybase/client | go/libkb/util.go | Digest | func Digest(r io.Reader) (string, error) {
hasher := sha256.New()
if _, err := io.Copy(hasher, r); err != nil {
return "", err
}
digest := hex.EncodeToString(hasher.Sum(nil))
return digest, nil
} | go | func Digest(r io.Reader) (string, error) {
hasher := sha256.New()
if _, err := io.Copy(hasher, r); err != nil {
return "", err
}
digest := hex.EncodeToString(hasher.Sum(nil))
return digest, nil
} | [
"func",
"Digest",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"error",
")",
"{",
"hasher",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"hasher",
",",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"digest",
":=",
"hex",
".",
"EncodeToString",
"(",
"hasher",
".",
"Sum",
"(",
"nil",
")",
")",
"\n",
"return",
"digest",
",",
"nil",
"\n",
"}"
] | // Digest returns a SHA256 digest | [
"Digest",
"returns",
"a",
"SHA256",
"digest"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L652-L659 |
159,761 | keybase/client | go/libkb/util.go | JoinPredicate | func JoinPredicate(arr []string, delimeter string, f func(s string) bool) string {
arrNew := make([]string, 0, len(arr))
for _, s := range arr {
if f(s) {
arrNew = append(arrNew, s)
}
}
return strings.Join(arrNew, delimeter)
} | go | func JoinPredicate(arr []string, delimeter string, f func(s string) bool) string {
arrNew := make([]string, 0, len(arr))
for _, s := range arr {
if f(s) {
arrNew = append(arrNew, s)
}
}
return strings.Join(arrNew, delimeter)
} | [
"func",
"JoinPredicate",
"(",
"arr",
"[",
"]",
"string",
",",
"delimeter",
"string",
",",
"f",
"func",
"(",
"s",
"string",
")",
"bool",
")",
"string",
"{",
"arrNew",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"arr",
")",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"arr",
"{",
"if",
"f",
"(",
"s",
")",
"{",
"arrNew",
"=",
"append",
"(",
"arrNew",
",",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"arrNew",
",",
"delimeter",
")",
"\n",
"}"
] | // JoinPredicate joins strings with predicate | [
"JoinPredicate",
"joins",
"strings",
"with",
"predicate"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L687-L695 |
159,762 | keybase/client | go/libkb/util.go | LogTagsFromContext | func LogTagsFromContext(ctx context.Context) (map[interface{}]string, bool) {
tags, ok := logger.LogTagsFromContext(ctx)
return map[interface{}]string(tags), ok
} | go | func LogTagsFromContext(ctx context.Context) (map[interface{}]string, bool) {
tags, ok := logger.LogTagsFromContext(ctx)
return map[interface{}]string(tags), ok
} | [
"func",
"LogTagsFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"string",
",",
"bool",
")",
"{",
"tags",
",",
"ok",
":=",
"logger",
".",
"LogTagsFromContext",
"(",
"ctx",
")",
"\n",
"return",
"map",
"[",
"interface",
"{",
"}",
"]",
"string",
"(",
"tags",
")",
",",
"ok",
"\n",
"}"
] | // LogTagsFromContext is a wrapper around logger.LogTagsFromContext
// that simply casts the result to the type expected by
// rpc.Connection. | [
"LogTagsFromContext",
"is",
"a",
"wrapper",
"around",
"logger",
".",
"LogTagsFromContext",
"that",
"simply",
"casts",
"the",
"result",
"to",
"the",
"type",
"expected",
"by",
"rpc",
".",
"Connection",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L700-L703 |
159,763 | keybase/client | go/libkb/util.go | MobilePermissionDeniedCheck | func MobilePermissionDeniedCheck(g *GlobalContext, err error, msg string) {
if !os.IsPermission(err) {
return
}
if g.GetAppType() != MobileAppType {
return
}
g.Log.Warning("file open permission denied on mobile (%s): %s", msg, err)
os.Exit(4)
} | go | func MobilePermissionDeniedCheck(g *GlobalContext, err error, msg string) {
if !os.IsPermission(err) {
return
}
if g.GetAppType() != MobileAppType {
return
}
g.Log.Warning("file open permission denied on mobile (%s): %s", msg, err)
os.Exit(4)
} | [
"func",
"MobilePermissionDeniedCheck",
"(",
"g",
"*",
"GlobalContext",
",",
"err",
"error",
",",
"msg",
"string",
")",
"{",
"if",
"!",
"os",
".",
"IsPermission",
"(",
"err",
")",
"{",
"return",
"\n",
"}",
"\n",
"if",
"g",
".",
"GetAppType",
"(",
")",
"!=",
"MobileAppType",
"{",
"return",
"\n",
"}",
"\n",
"g",
".",
"Log",
".",
"Warning",
"(",
"\"",
"\"",
",",
"msg",
",",
"err",
")",
"\n",
"os",
".",
"Exit",
"(",
"4",
")",
"\n",
"}"
] | // MobilePermissionDeniedCheck panics if err is a permission denied error
// and if app is a mobile app. This has caused issues opening config.json
// and secretkeys files, where it seems to be stuck in a permission
// denied state and force-killing the app is the only option. | [
"MobilePermissionDeniedCheck",
"panics",
"if",
"err",
"is",
"a",
"permission",
"denied",
"error",
"and",
"if",
"app",
"is",
"a",
"mobile",
"app",
".",
"This",
"has",
"caused",
"issues",
"opening",
"config",
".",
"json",
"and",
"secretkeys",
"files",
"where",
"it",
"seems",
"to",
"be",
"stuck",
"in",
"a",
"permission",
"denied",
"state",
"and",
"force",
"-",
"killing",
"the",
"app",
"is",
"the",
"only",
"option",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L816-L825 |
159,764 | keybase/client | go/libkb/util.go | IsNoSpaceOnDeviceError | func IsNoSpaceOnDeviceError(err error) bool {
if err == nil {
return false
}
switch err := err.(type) {
case NoSpaceOnDeviceError:
return true
case *os.PathError:
return err.Err == syscall.ENOSPC
case *os.LinkError:
return err.Err == syscall.ENOSPC
case *os.SyscallError:
return err.Err == syscall.ENOSPC
}
return false
} | go | func IsNoSpaceOnDeviceError(err error) bool {
if err == nil {
return false
}
switch err := err.(type) {
case NoSpaceOnDeviceError:
return true
case *os.PathError:
return err.Err == syscall.ENOSPC
case *os.LinkError:
return err.Err == syscall.ENOSPC
case *os.SyscallError:
return err.Err == syscall.ENOSPC
}
return false
} | [
"func",
"IsNoSpaceOnDeviceError",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"NoSpaceOnDeviceError",
":",
"return",
"true",
"\n",
"case",
"*",
"os",
".",
"PathError",
":",
"return",
"err",
".",
"Err",
"==",
"syscall",
".",
"ENOSPC",
"\n",
"case",
"*",
"os",
".",
"LinkError",
":",
"return",
"err",
".",
"Err",
"==",
"syscall",
".",
"ENOSPC",
"\n",
"case",
"*",
"os",
".",
"SyscallError",
":",
"return",
"err",
".",
"Err",
"==",
"syscall",
".",
"ENOSPC",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IsNoSpaceOnDeviceError will return true if err is an `os` error
// for "no space left on device". | [
"IsNoSpaceOnDeviceError",
"will",
"return",
"true",
"if",
"err",
"is",
"an",
"os",
"error",
"for",
"no",
"space",
"left",
"on",
"device",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L829-L845 |
159,765 | keybase/client | go/libkb/util.go | AcquireWithTimeout | func AcquireWithTimeout(lock sync.Locker, timeout time.Duration) (err error) {
ctx2, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return AcquireWithContext(ctx2, lock)
} | go | func AcquireWithTimeout(lock sync.Locker, timeout time.Duration) (err error) {
ctx2, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return AcquireWithContext(ctx2, lock)
} | [
"func",
"AcquireWithTimeout",
"(",
"lock",
"sync",
".",
"Locker",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"err",
"error",
")",
"{",
"ctx2",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"context",
".",
"Background",
"(",
")",
",",
"timeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"AcquireWithContext",
"(",
"ctx2",
",",
"lock",
")",
"\n",
"}"
] | // AcquireWithTimeout attempts to acquire a lock with a timeout.
// Convenience wrapper around AcquireWithContext.
// Returns nil if the lock was acquired.
// Returns context.DeadlineExceeded if it was not. | [
"AcquireWithTimeout",
"attempts",
"to",
"acquire",
"a",
"lock",
"with",
"a",
"timeout",
".",
"Convenience",
"wrapper",
"around",
"AcquireWithContext",
".",
"Returns",
"nil",
"if",
"the",
"lock",
"was",
"acquired",
".",
"Returns",
"context",
".",
"DeadlineExceeded",
"if",
"it",
"was",
"not",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L979-L983 |
159,766 | keybase/client | go/libkb/util.go | DirSize | func DirSize(dirPath string) (size uint64, numFiles int, err error) {
err = filepath.Walk(dirPath, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += uint64(info.Size())
numFiles++
}
return nil
})
return size, numFiles, err
} | go | func DirSize(dirPath string) (size uint64, numFiles int, err error) {
err = filepath.Walk(dirPath, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += uint64(info.Size())
numFiles++
}
return nil
})
return size, numFiles, err
} | [
"func",
"DirSize",
"(",
"dirPath",
"string",
")",
"(",
"size",
"uint64",
",",
"numFiles",
"int",
",",
"err",
"error",
")",
"{",
"err",
"=",
"filepath",
".",
"Walk",
"(",
"dirPath",
",",
"func",
"(",
"_",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"info",
".",
"IsDir",
"(",
")",
"{",
"size",
"+=",
"uint64",
"(",
"info",
".",
"Size",
"(",
")",
")",
"\n",
"numFiles",
"++",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"size",
",",
"numFiles",
",",
"err",
"\n",
"}"
] | // DirSize walks the file tree the size of the given directory | [
"DirSize",
"walks",
"the",
"file",
"tree",
"the",
"size",
"of",
"the",
"given",
"directory"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util.go#L1016-L1028 |
159,767 | keybase/client | go/pvl/interp.go | NewProofInfo | func NewProofInfo(link libkb.RemoteProofChainLink, h libkb.SigHint) ProofInfo {
return ProofInfo{
ArmoredSig: link.GetArmoredSig(),
RemoteUsername: link.GetRemoteUsername(),
Username: link.GetUsername(),
Hostname: link.GetHostname(),
Protocol: link.GetProtocol(),
APIURL: h.GetAPIURL(),
}
} | go | func NewProofInfo(link libkb.RemoteProofChainLink, h libkb.SigHint) ProofInfo {
return ProofInfo{
ArmoredSig: link.GetArmoredSig(),
RemoteUsername: link.GetRemoteUsername(),
Username: link.GetUsername(),
Hostname: link.GetHostname(),
Protocol: link.GetProtocol(),
APIURL: h.GetAPIURL(),
}
} | [
"func",
"NewProofInfo",
"(",
"link",
"libkb",
".",
"RemoteProofChainLink",
",",
"h",
"libkb",
".",
"SigHint",
")",
"ProofInfo",
"{",
"return",
"ProofInfo",
"{",
"ArmoredSig",
":",
"link",
".",
"GetArmoredSig",
"(",
")",
",",
"RemoteUsername",
":",
"link",
".",
"GetRemoteUsername",
"(",
")",
",",
"Username",
":",
"link",
".",
"GetUsername",
"(",
")",
",",
"Hostname",
":",
"link",
".",
"GetHostname",
"(",
")",
",",
"Protocol",
":",
"link",
".",
"GetProtocol",
"(",
")",
",",
"APIURL",
":",
"h",
".",
"GetAPIURL",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewProofInfo creates a new ProofInfo | [
"NewProofInfo",
"creates",
"a",
"new",
"ProofInfo"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L95-L104 |
159,768 | keybase/client | go/pvl/interp.go | CheckProof | func CheckProof(m libkb.MetaContext, pvlS string, service keybase1.ProofType, info ProofInfo) libkb.ProofError {
m1 := newMetaContext(m, info.stubDNS)
perr := checkProofInner(m1, pvlS, service, info)
if perr != nil {
debug(m1, "CheckProof failed: %v", perr)
}
if perr != nil && perr.GetProofStatus() == keybase1.ProofStatus_INVALID_PVL {
return libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Invalid proof verification instructions! Let us know at https://github.com/keybase/keybase-issues/new")
}
return perr
} | go | func CheckProof(m libkb.MetaContext, pvlS string, service keybase1.ProofType, info ProofInfo) libkb.ProofError {
m1 := newMetaContext(m, info.stubDNS)
perr := checkProofInner(m1, pvlS, service, info)
if perr != nil {
debug(m1, "CheckProof failed: %v", perr)
}
if perr != nil && perr.GetProofStatus() == keybase1.ProofStatus_INVALID_PVL {
return libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Invalid proof verification instructions! Let us know at https://github.com/keybase/keybase-issues/new")
}
return perr
} | [
"func",
"CheckProof",
"(",
"m",
"libkb",
".",
"MetaContext",
",",
"pvlS",
"string",
",",
"service",
"keybase1",
".",
"ProofType",
",",
"info",
"ProofInfo",
")",
"libkb",
".",
"ProofError",
"{",
"m1",
":=",
"newMetaContext",
"(",
"m",
",",
"info",
".",
"stubDNS",
")",
"\n",
"perr",
":=",
"checkProofInner",
"(",
"m1",
",",
"pvlS",
",",
"service",
",",
"info",
")",
"\n",
"if",
"perr",
"!=",
"nil",
"{",
"debug",
"(",
"m1",
",",
"\"",
"\"",
",",
"perr",
")",
"\n",
"}",
"\n",
"if",
"perr",
"!=",
"nil",
"&&",
"perr",
".",
"GetProofStatus",
"(",
")",
"==",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
"{",
"return",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"perr",
"\n",
"}"
] | // CheckProof verifies one proof by running the pvl on the provided proof information. | [
"CheckProof",
"verifies",
"one",
"proof",
"by",
"running",
"the",
"pvl",
"on",
"the",
"provided",
"proof",
"information",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L107-L118 |
159,769 | keybase/client | go/pvl/interp.go | chunkGetScripts | func chunkGetScripts(pvl *pvlT, service keybase1.ProofType) ([]scriptT, libkb.ProofError) {
scripts, ok := pvl.Services.Map[service]
if !ok {
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"No entry for service: %v", service)
}
return scripts, nil
} | go | func chunkGetScripts(pvl *pvlT, service keybase1.ProofType) ([]scriptT, libkb.ProofError) {
scripts, ok := pvl.Services.Map[service]
if !ok {
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"No entry for service: %v", service)
}
return scripts, nil
} | [
"func",
"chunkGetScripts",
"(",
"pvl",
"*",
"pvlT",
",",
"service",
"keybase1",
".",
"ProofType",
")",
"(",
"[",
"]",
"scriptT",
",",
"libkb",
".",
"ProofError",
")",
"{",
"scripts",
",",
"ok",
":=",
"pvl",
".",
"Services",
".",
"Map",
"[",
"service",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
",",
"service",
")",
"\n",
"}",
"\n",
"return",
"scripts",
",",
"nil",
"\n",
"}"
] | // Get the list of scripts for a given service. | [
"Get",
"the",
"list",
"of",
"scripts",
"for",
"a",
"given",
"service",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L282-L289 |
159,770 | keybase/client | go/pvl/interp.go | validateChunk | func validateChunk(m metaContext, pvl *pvlT, service keybase1.ProofType) libkb.ProofError {
if pvl.PvlVersion != SupportedVersion {
return libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"PVL is for the wrong version %v != %v", pvl.PvlVersion, SupportedVersion)
}
debug(m, "valid version:%v revision:%v", pvl.PvlVersion, pvl.Revision)
scripts, perr := chunkGetScripts(pvl, service)
if perr != nil {
return perr
}
if len(scripts) == 0 {
return libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Empty scripts list for service: %v", service)
}
// Scan all the scripts (for this service) for errors. Report the first error.
var errs []libkb.ProofError
for whichscript, script := range scripts {
perr = validateScript(m, &script, service, whichscript)
errs = append(errs, perr)
}
return errs[0]
} | go | func validateChunk(m metaContext, pvl *pvlT, service keybase1.ProofType) libkb.ProofError {
if pvl.PvlVersion != SupportedVersion {
return libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"PVL is for the wrong version %v != %v", pvl.PvlVersion, SupportedVersion)
}
debug(m, "valid version:%v revision:%v", pvl.PvlVersion, pvl.Revision)
scripts, perr := chunkGetScripts(pvl, service)
if perr != nil {
return perr
}
if len(scripts) == 0 {
return libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Empty scripts list for service: %v", service)
}
// Scan all the scripts (for this service) for errors. Report the first error.
var errs []libkb.ProofError
for whichscript, script := range scripts {
perr = validateScript(m, &script, service, whichscript)
errs = append(errs, perr)
}
return errs[0]
} | [
"func",
"validateChunk",
"(",
"m",
"metaContext",
",",
"pvl",
"*",
"pvlT",
",",
"service",
"keybase1",
".",
"ProofType",
")",
"libkb",
".",
"ProofError",
"{",
"if",
"pvl",
".",
"PvlVersion",
"!=",
"SupportedVersion",
"{",
"return",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
",",
"pvl",
".",
"PvlVersion",
",",
"SupportedVersion",
")",
"\n",
"}",
"\n\n",
"debug",
"(",
"m",
",",
"\"",
"\"",
",",
"pvl",
".",
"PvlVersion",
",",
"pvl",
".",
"Revision",
")",
"\n\n",
"scripts",
",",
"perr",
":=",
"chunkGetScripts",
"(",
"pvl",
",",
"service",
")",
"\n",
"if",
"perr",
"!=",
"nil",
"{",
"return",
"perr",
"\n",
"}",
"\n",
"if",
"len",
"(",
"scripts",
")",
"==",
"0",
"{",
"return",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
",",
"service",
")",
"\n",
"}",
"\n\n",
"// Scan all the scripts (for this service) for errors. Report the first error.",
"var",
"errs",
"[",
"]",
"libkb",
".",
"ProofError",
"\n",
"for",
"whichscript",
",",
"script",
":=",
"range",
"scripts",
"{",
"perr",
"=",
"validateScript",
"(",
"m",
",",
"&",
"script",
",",
"service",
",",
"whichscript",
")",
"\n",
"errs",
"=",
"append",
"(",
"errs",
",",
"perr",
")",
"\n",
"}",
"\n",
"return",
"errs",
"[",
"0",
"]",
"\n",
"}"
] | // Check that a chunk of PVL is valid code.
// Will always accept valid code, but may not always notice invalidities. | [
"Check",
"that",
"a",
"chunk",
"of",
"PVL",
"is",
"valid",
"code",
".",
"Will",
"always",
"accept",
"valid",
"code",
"but",
"may",
"not",
"always",
"notice",
"invalidities",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L293-L317 |
159,771 | keybase/client | go/pvl/interp.go | runDNS | func runDNS(m metaContext, userdomain string, scripts []scriptT, mknewstate stateMaker, sigIDMedium string) libkb.ProofError {
domains := []string{userdomain, "_keybase." + userdomain}
var errs []libkb.ProofError
for _, d := range domains {
debug(m, "Trying DNS for domain: %v", d)
err := runDNSOne(m, d, scripts, mknewstate, sigIDMedium)
if err != nil {
errs = append(errs, err)
} else {
return nil
}
}
// Return only the error for the first domain error
if len(errs) == 0 {
return nil
}
var descs []string
for _, err := range errs {
descs = append(descs, err.GetDesc())
}
// Use the code from the first error
return libkb.NewProofError(errs[0].GetProofStatus(), strings.Join(descs, "; "))
} | go | func runDNS(m metaContext, userdomain string, scripts []scriptT, mknewstate stateMaker, sigIDMedium string) libkb.ProofError {
domains := []string{userdomain, "_keybase." + userdomain}
var errs []libkb.ProofError
for _, d := range domains {
debug(m, "Trying DNS for domain: %v", d)
err := runDNSOne(m, d, scripts, mknewstate, sigIDMedium)
if err != nil {
errs = append(errs, err)
} else {
return nil
}
}
// Return only the error for the first domain error
if len(errs) == 0 {
return nil
}
var descs []string
for _, err := range errs {
descs = append(descs, err.GetDesc())
}
// Use the code from the first error
return libkb.NewProofError(errs[0].GetProofStatus(), strings.Join(descs, "; "))
} | [
"func",
"runDNS",
"(",
"m",
"metaContext",
",",
"userdomain",
"string",
",",
"scripts",
"[",
"]",
"scriptT",
",",
"mknewstate",
"stateMaker",
",",
"sigIDMedium",
"string",
")",
"libkb",
".",
"ProofError",
"{",
"domains",
":=",
"[",
"]",
"string",
"{",
"userdomain",
",",
"\"",
"\"",
"+",
"userdomain",
"}",
"\n",
"var",
"errs",
"[",
"]",
"libkb",
".",
"ProofError",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"domains",
"{",
"debug",
"(",
"m",
",",
"\"",
"\"",
",",
"d",
")",
"\n\n",
"err",
":=",
"runDNSOne",
"(",
"m",
",",
"d",
",",
"scripts",
",",
"mknewstate",
",",
"sigIDMedium",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Return only the error for the first domain error",
"if",
"len",
"(",
"errs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"descs",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"err",
":=",
"range",
"errs",
"{",
"descs",
"=",
"append",
"(",
"descs",
",",
"err",
".",
"GetDesc",
"(",
")",
")",
"\n",
"}",
"\n",
"// Use the code from the first error",
"return",
"libkb",
".",
"NewProofError",
"(",
"errs",
"[",
"0",
"]",
".",
"GetProofStatus",
"(",
")",
",",
"strings",
".",
"Join",
"(",
"descs",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // Run each script on each TXT record of each domain.
// Succeed if any succeed. | [
"Run",
"each",
"script",
"on",
"each",
"TXT",
"record",
"of",
"each",
"domain",
".",
"Succeed",
"if",
"any",
"succeed",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L415-L439 |
159,772 | keybase/client | go/pvl/interp.go | runDNSOne | func runDNSOne(m metaContext, domain string, scripts []scriptT, mknewstate stateMaker, sigIDMedium string) libkb.ProofError {
// Fetch TXT records
var txts []string
var err error
if m.getStubDNS() == nil {
txts, err = runDNSTXTQuery(m, domain)
} else {
txts, err = m.getStubDNS().LookupTXT(domain)
}
if err != nil {
return libkb.NewProofError(keybase1.ProofStatus_DNS_ERROR,
"DNS failure for %s: %s", domain, err)
}
for _, record := range txts {
debug(m, "For DNS domain '%s' got TXT record: '%s'", domain, record)
// Try all scripts.
for i, script := range scripts {
state, err := mknewstate(i)
if err != nil {
return err
}
if err = state.Regs.Set("txt", record); err != nil {
return err
}
if err = runScript(m, &script, state); err == nil {
return nil
}
// Discard error, it has already been reported by stepInstruction.
}
}
return libkb.NewProofError(keybase1.ProofStatus_NOT_FOUND,
"Checked %d TXT entries of %s, but didn't find signature keybase-site-verification=%s",
len(txts), domain, sigIDMedium)
} | go | func runDNSOne(m metaContext, domain string, scripts []scriptT, mknewstate stateMaker, sigIDMedium string) libkb.ProofError {
// Fetch TXT records
var txts []string
var err error
if m.getStubDNS() == nil {
txts, err = runDNSTXTQuery(m, domain)
} else {
txts, err = m.getStubDNS().LookupTXT(domain)
}
if err != nil {
return libkb.NewProofError(keybase1.ProofStatus_DNS_ERROR,
"DNS failure for %s: %s", domain, err)
}
for _, record := range txts {
debug(m, "For DNS domain '%s' got TXT record: '%s'", domain, record)
// Try all scripts.
for i, script := range scripts {
state, err := mknewstate(i)
if err != nil {
return err
}
if err = state.Regs.Set("txt", record); err != nil {
return err
}
if err = runScript(m, &script, state); err == nil {
return nil
}
// Discard error, it has already been reported by stepInstruction.
}
}
return libkb.NewProofError(keybase1.ProofStatus_NOT_FOUND,
"Checked %d TXT entries of %s, but didn't find signature keybase-site-verification=%s",
len(txts), domain, sigIDMedium)
} | [
"func",
"runDNSOne",
"(",
"m",
"metaContext",
",",
"domain",
"string",
",",
"scripts",
"[",
"]",
"scriptT",
",",
"mknewstate",
"stateMaker",
",",
"sigIDMedium",
"string",
")",
"libkb",
".",
"ProofError",
"{",
"// Fetch TXT records",
"var",
"txts",
"[",
"]",
"string",
"\n",
"var",
"err",
"error",
"\n",
"if",
"m",
".",
"getStubDNS",
"(",
")",
"==",
"nil",
"{",
"txts",
",",
"err",
"=",
"runDNSTXTQuery",
"(",
"m",
",",
"domain",
")",
"\n",
"}",
"else",
"{",
"txts",
",",
"err",
"=",
"m",
".",
"getStubDNS",
"(",
")",
".",
"LookupTXT",
"(",
"domain",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_DNS_ERROR",
",",
"\"",
"\"",
",",
"domain",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"record",
":=",
"range",
"txts",
"{",
"debug",
"(",
"m",
",",
"\"",
"\"",
",",
"domain",
",",
"record",
")",
"\n\n",
"// Try all scripts.",
"for",
"i",
",",
"script",
":=",
"range",
"scripts",
"{",
"state",
",",
"err",
":=",
"mknewstate",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"state",
".",
"Regs",
".",
"Set",
"(",
"\"",
"\"",
",",
"record",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"runScript",
"(",
"m",
",",
"&",
"script",
",",
"state",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Discard error, it has already been reported by stepInstruction.",
"}",
"\n",
"}",
"\n\n",
"return",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_NOT_FOUND",
",",
"\"",
"\"",
",",
"len",
"(",
"txts",
")",
",",
"domain",
",",
"sigIDMedium",
")",
"\n",
"}"
] | // Run each script on each TXT record of the domain. | [
"Run",
"each",
"script",
"on",
"each",
"TXT",
"record",
"of",
"the",
"domain",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L505-L545 |
159,773 | keybase/client | go/pvl/interp.go | stepInstruction | func stepInstruction(m metaContext, ins instructionT, state scriptState) (scriptState, libkb.ProofError) {
debugWithState(m, state, "Running instruction %v: %v", ins.Name(), ins)
var newState scriptState
var stepErr libkb.ProofError
var customErrSpec *errorT
switch {
case ins.AssertRegexMatch != nil:
newState, stepErr = stepAssertRegexMatch(m, *ins.AssertRegexMatch, state)
customErrSpec = ins.AssertRegexMatch.Error
case ins.AssertFindBase64 != nil:
newState, stepErr = stepAssertFindBase64(m, *ins.AssertFindBase64, state)
customErrSpec = ins.AssertFindBase64.Error
case ins.AssertCompare != nil:
newState, stepErr = stepAssertCompare(m, *ins.AssertCompare, state)
customErrSpec = ins.AssertCompare.Error
case ins.WhitespaceNormalize != nil:
newState, stepErr = stepWhitespaceNormalize(m, *ins.WhitespaceNormalize, state)
customErrSpec = ins.WhitespaceNormalize.Error
case ins.RegexCapture != nil:
newState, stepErr = stepRegexCapture(m, *ins.RegexCapture, state)
customErrSpec = ins.RegexCapture.Error
case ins.ReplaceAll != nil:
newState, stepErr = stepReplaceAll(m, *ins.ReplaceAll, state)
customErrSpec = ins.ReplaceAll.Error
case ins.ParseURL != nil:
newState, stepErr = stepParseURL(m, *ins.ParseURL, state)
customErrSpec = ins.ParseURL.Error
case ins.Fetch != nil:
newState, stepErr = stepFetch(m, *ins.Fetch, state)
customErrSpec = ins.Fetch.Error
case ins.ParseHTML != nil:
newState, stepErr = stepParseHTML(m, *ins.ParseHTML, state)
customErrSpec = ins.ParseHTML.Error
case ins.SelectorJSON != nil:
newState, stepErr = stepSelectorJSON(m, *ins.SelectorJSON, state)
customErrSpec = ins.SelectorJSON.Error
case ins.SelectorCSS != nil:
newState, stepErr = stepSelectorCSS(m, *ins.SelectorCSS, state)
customErrSpec = ins.SelectorCSS.Error
case ins.Fill != nil:
newState, stepErr = stepFill(m, *ins.Fill, state)
customErrSpec = ins.Fill.Error
default:
newState = state
stepErr = libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Invalid instruction: %v", ins)
}
if stepErr != nil {
debugWithStateError(m, state, stepErr)
stepErr = replaceCustomError(m, state, customErrSpec, stepErr)
}
return newState, stepErr
} | go | func stepInstruction(m metaContext, ins instructionT, state scriptState) (scriptState, libkb.ProofError) {
debugWithState(m, state, "Running instruction %v: %v", ins.Name(), ins)
var newState scriptState
var stepErr libkb.ProofError
var customErrSpec *errorT
switch {
case ins.AssertRegexMatch != nil:
newState, stepErr = stepAssertRegexMatch(m, *ins.AssertRegexMatch, state)
customErrSpec = ins.AssertRegexMatch.Error
case ins.AssertFindBase64 != nil:
newState, stepErr = stepAssertFindBase64(m, *ins.AssertFindBase64, state)
customErrSpec = ins.AssertFindBase64.Error
case ins.AssertCompare != nil:
newState, stepErr = stepAssertCompare(m, *ins.AssertCompare, state)
customErrSpec = ins.AssertCompare.Error
case ins.WhitespaceNormalize != nil:
newState, stepErr = stepWhitespaceNormalize(m, *ins.WhitespaceNormalize, state)
customErrSpec = ins.WhitespaceNormalize.Error
case ins.RegexCapture != nil:
newState, stepErr = stepRegexCapture(m, *ins.RegexCapture, state)
customErrSpec = ins.RegexCapture.Error
case ins.ReplaceAll != nil:
newState, stepErr = stepReplaceAll(m, *ins.ReplaceAll, state)
customErrSpec = ins.ReplaceAll.Error
case ins.ParseURL != nil:
newState, stepErr = stepParseURL(m, *ins.ParseURL, state)
customErrSpec = ins.ParseURL.Error
case ins.Fetch != nil:
newState, stepErr = stepFetch(m, *ins.Fetch, state)
customErrSpec = ins.Fetch.Error
case ins.ParseHTML != nil:
newState, stepErr = stepParseHTML(m, *ins.ParseHTML, state)
customErrSpec = ins.ParseHTML.Error
case ins.SelectorJSON != nil:
newState, stepErr = stepSelectorJSON(m, *ins.SelectorJSON, state)
customErrSpec = ins.SelectorJSON.Error
case ins.SelectorCSS != nil:
newState, stepErr = stepSelectorCSS(m, *ins.SelectorCSS, state)
customErrSpec = ins.SelectorCSS.Error
case ins.Fill != nil:
newState, stepErr = stepFill(m, *ins.Fill, state)
customErrSpec = ins.Fill.Error
default:
newState = state
stepErr = libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Invalid instruction: %v", ins)
}
if stepErr != nil {
debugWithStateError(m, state, stepErr)
stepErr = replaceCustomError(m, state, customErrSpec, stepErr)
}
return newState, stepErr
} | [
"func",
"stepInstruction",
"(",
"m",
"metaContext",
",",
"ins",
"instructionT",
",",
"state",
"scriptState",
")",
"(",
"scriptState",
",",
"libkb",
".",
"ProofError",
")",
"{",
"debugWithState",
"(",
"m",
",",
"state",
",",
"\"",
"\"",
",",
"ins",
".",
"Name",
"(",
")",
",",
"ins",
")",
"\n\n",
"var",
"newState",
"scriptState",
"\n",
"var",
"stepErr",
"libkb",
".",
"ProofError",
"\n",
"var",
"customErrSpec",
"*",
"errorT",
"\n",
"switch",
"{",
"case",
"ins",
".",
"AssertRegexMatch",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepAssertRegexMatch",
"(",
"m",
",",
"*",
"ins",
".",
"AssertRegexMatch",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"AssertRegexMatch",
".",
"Error",
"\n",
"case",
"ins",
".",
"AssertFindBase64",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepAssertFindBase64",
"(",
"m",
",",
"*",
"ins",
".",
"AssertFindBase64",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"AssertFindBase64",
".",
"Error",
"\n",
"case",
"ins",
".",
"AssertCompare",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepAssertCompare",
"(",
"m",
",",
"*",
"ins",
".",
"AssertCompare",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"AssertCompare",
".",
"Error",
"\n",
"case",
"ins",
".",
"WhitespaceNormalize",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepWhitespaceNormalize",
"(",
"m",
",",
"*",
"ins",
".",
"WhitespaceNormalize",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"WhitespaceNormalize",
".",
"Error",
"\n",
"case",
"ins",
".",
"RegexCapture",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepRegexCapture",
"(",
"m",
",",
"*",
"ins",
".",
"RegexCapture",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"RegexCapture",
".",
"Error",
"\n",
"case",
"ins",
".",
"ReplaceAll",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepReplaceAll",
"(",
"m",
",",
"*",
"ins",
".",
"ReplaceAll",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"ReplaceAll",
".",
"Error",
"\n",
"case",
"ins",
".",
"ParseURL",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepParseURL",
"(",
"m",
",",
"*",
"ins",
".",
"ParseURL",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"ParseURL",
".",
"Error",
"\n",
"case",
"ins",
".",
"Fetch",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepFetch",
"(",
"m",
",",
"*",
"ins",
".",
"Fetch",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"Fetch",
".",
"Error",
"\n",
"case",
"ins",
".",
"ParseHTML",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepParseHTML",
"(",
"m",
",",
"*",
"ins",
".",
"ParseHTML",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"ParseHTML",
".",
"Error",
"\n",
"case",
"ins",
".",
"SelectorJSON",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepSelectorJSON",
"(",
"m",
",",
"*",
"ins",
".",
"SelectorJSON",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"SelectorJSON",
".",
"Error",
"\n",
"case",
"ins",
".",
"SelectorCSS",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepSelectorCSS",
"(",
"m",
",",
"*",
"ins",
".",
"SelectorCSS",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"SelectorCSS",
".",
"Error",
"\n",
"case",
"ins",
".",
"Fill",
"!=",
"nil",
":",
"newState",
",",
"stepErr",
"=",
"stepFill",
"(",
"m",
",",
"*",
"ins",
".",
"Fill",
",",
"state",
")",
"\n",
"customErrSpec",
"=",
"ins",
".",
"Fill",
".",
"Error",
"\n",
"default",
":",
"newState",
"=",
"state",
"\n",
"stepErr",
"=",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
",",
"ins",
")",
"\n",
"}",
"\n\n",
"if",
"stepErr",
"!=",
"nil",
"{",
"debugWithStateError",
"(",
"m",
",",
"state",
",",
"stepErr",
")",
"\n",
"stepErr",
"=",
"replaceCustomError",
"(",
"m",
",",
"state",
",",
"customErrSpec",
",",
"stepErr",
")",
"\n",
"}",
"\n",
"return",
"newState",
",",
"stepErr",
"\n\n",
"}"
] | // stepInstruction decides which instruction to run. | [
"stepInstruction",
"decides",
"which",
"instruction",
"to",
"run",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L577-L632 |
159,774 | keybase/client | go/pvl/interp.go | interpretRegex | func interpretRegex(m metaContext, state scriptState, rdesc regexDescriptor) (*regexp.Regexp, libkb.ProofError) {
// Check that regex is bounded by "^" and "$".
if !strings.HasPrefix(rdesc.Template, "^") {
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Could not build regex: %v (%v)", "must start with '^'", rdesc.Template)
}
if !strings.HasSuffix(rdesc.Template, "$") {
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Could not build regex: %v (%v)", "must end with '$'", rdesc.Template)
}
var optstring = ""
if rdesc.CaseInsensitive {
optstring += "i"
}
if rdesc.MultiLine {
optstring += "m"
}
var prefix = ""
if len(optstring) > 0 {
prefix = "(?" + optstring + ")"
}
// Do variable interpolation.
prepattern, perr := substituteReEscape(rdesc.Template, state)
if perr != nil {
return nil, perr
}
pattern := prefix + prepattern
// Build the regex.
re, err := regexp.Compile(pattern)
if err != nil {
debugWithState(m, state, "Could not compile regex: %v\n %v\n %v", err, rdesc.Template, pattern)
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Could not compile regex: %v (%v)", err, rdesc.Template)
}
return re, nil
} | go | func interpretRegex(m metaContext, state scriptState, rdesc regexDescriptor) (*regexp.Regexp, libkb.ProofError) {
// Check that regex is bounded by "^" and "$".
if !strings.HasPrefix(rdesc.Template, "^") {
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Could not build regex: %v (%v)", "must start with '^'", rdesc.Template)
}
if !strings.HasSuffix(rdesc.Template, "$") {
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Could not build regex: %v (%v)", "must end with '$'", rdesc.Template)
}
var optstring = ""
if rdesc.CaseInsensitive {
optstring += "i"
}
if rdesc.MultiLine {
optstring += "m"
}
var prefix = ""
if len(optstring) > 0 {
prefix = "(?" + optstring + ")"
}
// Do variable interpolation.
prepattern, perr := substituteReEscape(rdesc.Template, state)
if perr != nil {
return nil, perr
}
pattern := prefix + prepattern
// Build the regex.
re, err := regexp.Compile(pattern)
if err != nil {
debugWithState(m, state, "Could not compile regex: %v\n %v\n %v", err, rdesc.Template, pattern)
return nil, libkb.NewProofError(keybase1.ProofStatus_INVALID_PVL,
"Could not compile regex: %v (%v)", err, rdesc.Template)
}
return re, nil
} | [
"func",
"interpretRegex",
"(",
"m",
"metaContext",
",",
"state",
"scriptState",
",",
"rdesc",
"regexDescriptor",
")",
"(",
"*",
"regexp",
".",
"Regexp",
",",
"libkb",
".",
"ProofError",
")",
"{",
"// Check that regex is bounded by \"^\" and \"$\".",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"rdesc",
".",
"Template",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"rdesc",
".",
"Template",
")",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"rdesc",
".",
"Template",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"rdesc",
".",
"Template",
")",
"\n",
"}",
"\n\n",
"var",
"optstring",
"=",
"\"",
"\"",
"\n",
"if",
"rdesc",
".",
"CaseInsensitive",
"{",
"optstring",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"rdesc",
".",
"MultiLine",
"{",
"optstring",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"var",
"prefix",
"=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"optstring",
")",
">",
"0",
"{",
"prefix",
"=",
"\"",
"\"",
"+",
"optstring",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Do variable interpolation.",
"prepattern",
",",
"perr",
":=",
"substituteReEscape",
"(",
"rdesc",
".",
"Template",
",",
"state",
")",
"\n",
"if",
"perr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"perr",
"\n",
"}",
"\n",
"pattern",
":=",
"prefix",
"+",
"prepattern",
"\n\n",
"// Build the regex.",
"re",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"pattern",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"debugWithState",
"(",
"m",
",",
"state",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
",",
"rdesc",
".",
"Template",
",",
"pattern",
")",
"\n",
"return",
"nil",
",",
"libkb",
".",
"NewProofError",
"(",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
",",
"\"",
"\"",
",",
"err",
",",
"rdesc",
".",
"Template",
")",
"\n",
"}",
"\n",
"return",
"re",
",",
"nil",
"\n",
"}"
] | // Take a regex descriptor, do variable substitution, and build a regex. | [
"Take",
"a",
"regex",
"descriptor",
"do",
"variable",
"substitution",
"and",
"build",
"a",
"regex",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L1034-L1073 |
159,775 | keybase/client | go/pvl/interp.go | replaceCustomError | func replaceCustomError(m metaContext, state scriptState, spec *errorT, err1 libkb.ProofError) libkb.ProofError {
if err1 == nil {
return err1
}
// Don't rewrite invalid_pvl errors
if err1.GetProofStatus() == keybase1.ProofStatus_INVALID_PVL {
return err1
}
if spec == nil {
return err1
}
if (spec.Status != err1.GetProofStatus()) || (spec.Description != err1.GetDesc()) {
newDesc := spec.Description
subbedDesc, subErr := substituteExact(spec.Description, state)
if subErr == nil {
newDesc = subbedDesc
}
err2 := libkb.NewProofError(spec.Status, newDesc)
debugWithState(m, state, "Replacing error with custom error")
debugWithStateError(m, state, err2)
return err2
}
return err1
} | go | func replaceCustomError(m metaContext, state scriptState, spec *errorT, err1 libkb.ProofError) libkb.ProofError {
if err1 == nil {
return err1
}
// Don't rewrite invalid_pvl errors
if err1.GetProofStatus() == keybase1.ProofStatus_INVALID_PVL {
return err1
}
if spec == nil {
return err1
}
if (spec.Status != err1.GetProofStatus()) || (spec.Description != err1.GetDesc()) {
newDesc := spec.Description
subbedDesc, subErr := substituteExact(spec.Description, state)
if subErr == nil {
newDesc = subbedDesc
}
err2 := libkb.NewProofError(spec.Status, newDesc)
debugWithState(m, state, "Replacing error with custom error")
debugWithStateError(m, state, err2)
return err2
}
return err1
} | [
"func",
"replaceCustomError",
"(",
"m",
"metaContext",
",",
"state",
"scriptState",
",",
"spec",
"*",
"errorT",
",",
"err1",
"libkb",
".",
"ProofError",
")",
"libkb",
".",
"ProofError",
"{",
"if",
"err1",
"==",
"nil",
"{",
"return",
"err1",
"\n",
"}",
"\n\n",
"// Don't rewrite invalid_pvl errors",
"if",
"err1",
".",
"GetProofStatus",
"(",
")",
"==",
"keybase1",
".",
"ProofStatus_INVALID_PVL",
"{",
"return",
"err1",
"\n",
"}",
"\n\n",
"if",
"spec",
"==",
"nil",
"{",
"return",
"err1",
"\n",
"}",
"\n\n",
"if",
"(",
"spec",
".",
"Status",
"!=",
"err1",
".",
"GetProofStatus",
"(",
")",
")",
"||",
"(",
"spec",
".",
"Description",
"!=",
"err1",
".",
"GetDesc",
"(",
")",
")",
"{",
"newDesc",
":=",
"spec",
".",
"Description",
"\n",
"subbedDesc",
",",
"subErr",
":=",
"substituteExact",
"(",
"spec",
".",
"Description",
",",
"state",
")",
"\n",
"if",
"subErr",
"==",
"nil",
"{",
"newDesc",
"=",
"subbedDesc",
"\n",
"}",
"\n",
"err2",
":=",
"libkb",
".",
"NewProofError",
"(",
"spec",
".",
"Status",
",",
"newDesc",
")",
"\n",
"debugWithState",
"(",
"m",
",",
"state",
",",
"\"",
"\"",
")",
"\n",
"debugWithStateError",
"(",
"m",
",",
"state",
",",
"err2",
")",
"\n\n",
"return",
"err2",
"\n",
"}",
"\n",
"return",
"err1",
"\n",
"}"
] | // Use a custom error spec to derive an error.
// spec can be none
// Copies over the error code if none is specified. | [
"Use",
"a",
"custom",
"error",
"spec",
"to",
"derive",
"an",
"error",
".",
"spec",
"can",
"be",
"none",
"Copies",
"over",
"the",
"error",
"code",
"if",
"none",
"is",
"specified",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/interp.go#L1078-L1105 |
159,776 | keybase/client | go/kbfs/libfuse/reclaim_quota_file.go | Write | func (f *ReclaimQuotaFile) Write(ctx context.Context, req *fuse.WriteRequest,
resp *fuse.WriteResponse) (err error) {
f.folder.fs.log.CDebugf(ctx, "ReclaimQuotaFile Write")
defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }()
if len(req.Data) == 0 {
return nil
}
err = libkbfs.ForceQuotaReclamationForTesting(
f.folder.fs.config, f.folder.getFolderBranch())
if err != nil {
return err
}
resp.Size = len(req.Data)
return nil
} | go | func (f *ReclaimQuotaFile) Write(ctx context.Context, req *fuse.WriteRequest,
resp *fuse.WriteResponse) (err error) {
f.folder.fs.log.CDebugf(ctx, "ReclaimQuotaFile Write")
defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }()
if len(req.Data) == 0 {
return nil
}
err = libkbfs.ForceQuotaReclamationForTesting(
f.folder.fs.config, f.folder.getFolderBranch())
if err != nil {
return err
}
resp.Size = len(req.Data)
return nil
} | [
"func",
"(",
"f",
"*",
"ReclaimQuotaFile",
")",
"Write",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"WriteRequest",
",",
"resp",
"*",
"fuse",
".",
"WriteResponse",
")",
"(",
"err",
"error",
")",
"{",
"f",
".",
"folder",
".",
"fs",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"err",
"=",
"f",
".",
"folder",
".",
"processError",
"(",
"ctx",
",",
"libkbfs",
".",
"WriteMode",
",",
"err",
")",
"}",
"(",
")",
"\n",
"if",
"len",
"(",
"req",
".",
"Data",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"err",
"=",
"libkbfs",
".",
"ForceQuotaReclamationForTesting",
"(",
"f",
".",
"folder",
".",
"fs",
".",
"config",
",",
"f",
".",
"folder",
".",
"getFolderBranch",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"resp",
".",
"Size",
"=",
"len",
"(",
"req",
".",
"Data",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Write implements the fs.HandleWriter interface for
// ReclaimQuotaFile. Note a write triggers quota reclamation, but
// does not wait for it to finish. If you want to wait, write to
// SyncFromServerFileName. | [
"Write",
"implements",
"the",
"fs",
".",
"HandleWriter",
"interface",
"for",
"ReclaimQuotaFile",
".",
"Note",
"a",
"write",
"triggers",
"quota",
"reclamation",
"but",
"does",
"not",
"wait",
"for",
"it",
"to",
"finish",
".",
"If",
"you",
"want",
"to",
"wait",
"write",
"to",
"SyncFromServerFileName",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/reclaim_quota_file.go#L39-L53 |
159,777 | keybase/client | go/engine/list_trackers.go | NewListTrackers | func NewListTrackers(g *libkb.GlobalContext, uid keybase1.UID) *ListTrackersEngine {
return &ListTrackersEngine{
uid: uid,
Contextified: libkb.NewContextified(g),
}
} | go | func NewListTrackers(g *libkb.GlobalContext, uid keybase1.UID) *ListTrackersEngine {
return &ListTrackersEngine{
uid: uid,
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewListTrackers",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"uid",
"keybase1",
".",
"UID",
")",
"*",
"ListTrackersEngine",
"{",
"return",
"&",
"ListTrackersEngine",
"{",
"uid",
":",
"uid",
",",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewListTrackers creates a TrackerList engine for uid. | [
"NewListTrackers",
"creates",
"a",
"TrackerList",
"engine",
"for",
"uid",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/list_trackers.go#L21-L26 |
159,778 | keybase/client | go/engine/list_trackers.go | List | func (e *ListTrackersEngine) List() []libkb.Tracker {
if e.trackers == nil {
return []libkb.Tracker{}
}
return e.trackers.Trackers
} | go | func (e *ListTrackersEngine) List() []libkb.Tracker {
if e.trackers == nil {
return []libkb.Tracker{}
}
return e.trackers.Trackers
} | [
"func",
"(",
"e",
"*",
"ListTrackersEngine",
")",
"List",
"(",
")",
"[",
"]",
"libkb",
".",
"Tracker",
"{",
"if",
"e",
".",
"trackers",
"==",
"nil",
"{",
"return",
"[",
"]",
"libkb",
".",
"Tracker",
"{",
"}",
"\n",
"}",
"\n",
"return",
"e",
".",
"trackers",
".",
"Trackers",
"\n",
"}"
] | // List returns the array of trackers for this user. | [
"List",
"returns",
"the",
"array",
"of",
"trackers",
"for",
"this",
"user",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/list_trackers.go#L76-L81 |
159,779 | keybase/client | go/engine/device_add.go | NewDeviceAdd | func NewDeviceAdd(g *libkb.GlobalContext) *DeviceAdd {
return &DeviceAdd{
Contextified: libkb.NewContextified(g),
}
} | go | func NewDeviceAdd(g *libkb.GlobalContext) *DeviceAdd {
return &DeviceAdd{
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewDeviceAdd",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"*",
"DeviceAdd",
"{",
"return",
"&",
"DeviceAdd",
"{",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewDeviceAdd creates a DeviceAdd engine. | [
"NewDeviceAdd",
"creates",
"a",
"DeviceAdd",
"engine",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/device_add.go#L20-L24 |
159,780 | keybase/client | go/kbfs/libkbfs/keybase_service_util.go | EnableAdminFeature | func EnableAdminFeature(ctx context.Context, runMode kbconst.RunMode, config Config) bool {
if runMode == kbconst.DevelRunMode {
// All users in devel mode are admins.
return true
}
const sessionID = 0
session, err := config.KeybaseService().CurrentSession(ctx, sessionID)
if err != nil {
return false
}
return libkb.IsKeybaseAdmin(session.UID)
} | go | func EnableAdminFeature(ctx context.Context, runMode kbconst.RunMode, config Config) bool {
if runMode == kbconst.DevelRunMode {
// All users in devel mode are admins.
return true
}
const sessionID = 0
session, err := config.KeybaseService().CurrentSession(ctx, sessionID)
if err != nil {
return false
}
return libkb.IsKeybaseAdmin(session.UID)
} | [
"func",
"EnableAdminFeature",
"(",
"ctx",
"context",
".",
"Context",
",",
"runMode",
"kbconst",
".",
"RunMode",
",",
"config",
"Config",
")",
"bool",
"{",
"if",
"runMode",
"==",
"kbconst",
".",
"DevelRunMode",
"{",
"// All users in devel mode are admins.",
"return",
"true",
"\n",
"}",
"\n",
"const",
"sessionID",
"=",
"0",
"\n",
"session",
",",
"err",
":=",
"config",
".",
"KeybaseService",
"(",
")",
".",
"CurrentSession",
"(",
"ctx",
",",
"sessionID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"libkb",
".",
"IsKeybaseAdmin",
"(",
"session",
".",
"UID",
")",
"\n",
"}"
] | // EnableAdminFeature returns true if admin features should be enabled
// for the currently-logged-in user. | [
"EnableAdminFeature",
"returns",
"true",
"if",
"admin",
"features",
"should",
"be",
"enabled",
"for",
"the",
"currently",
"-",
"logged",
"-",
"in",
"user",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/keybase_service_util.go#L19-L30 |
159,781 | keybase/client | go/kbfs/libkbfs/keybase_service_util.go | setHomeTlfIdsForDbcAndFavorites | func setHomeTlfIdsForDbcAndFavorites(ctx context.Context, config Config, username string) {
if config.DiskBlockCache() == nil {
return
}
log := config.MakeLogger("")
publicHandle, err := getHandleFromFolderName(ctx,
config.KBPKI(), config.MDOps(), config, username, true)
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to fetch TLF ID for "+
"user's public TLF: %+v", err)
} else if publicHandle.TlfID() != tlf.NullID {
err = config.DiskBlockCache().AddHomeTLF(ctx, publicHandle.TlfID())
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to set home TLF "+
"for disk block cache: %+v", err)
}
}
privateHandle, err := getHandleFromFolderName(
ctx, config.KBPKI(), config.MDOps(), config, username, false)
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to fetch TLF ID for "+
"user's private TLF: %+v", err)
} else if privateHandle.TlfID() != tlf.NullID {
err = config.DiskBlockCache().AddHomeTLF(ctx, privateHandle.TlfID())
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to set home TLF "+
"for disk block cache: %+v", err)
}
}
// Send to Favorites cache
info := homeTLFInfo{}
if publicHandle != nil {
teamID := publicHandle.ToFavToAdd(false).Data.TeamID
if teamID != nil {
info.PublicTeamID = *teamID
}
}
if privateHandle != nil {
teamID := privateHandle.ToFavToAdd(false).Data.TeamID
if teamID != nil {
info.PrivateTeamID = *teamID
}
}
config.KBFSOps().SetFavoritesHomeTLFInfo(ctx, info)
} | go | func setHomeTlfIdsForDbcAndFavorites(ctx context.Context, config Config, username string) {
if config.DiskBlockCache() == nil {
return
}
log := config.MakeLogger("")
publicHandle, err := getHandleFromFolderName(ctx,
config.KBPKI(), config.MDOps(), config, username, true)
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to fetch TLF ID for "+
"user's public TLF: %+v", err)
} else if publicHandle.TlfID() != tlf.NullID {
err = config.DiskBlockCache().AddHomeTLF(ctx, publicHandle.TlfID())
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to set home TLF "+
"for disk block cache: %+v", err)
}
}
privateHandle, err := getHandleFromFolderName(
ctx, config.KBPKI(), config.MDOps(), config, username, false)
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to fetch TLF ID for "+
"user's private TLF: %+v", err)
} else if privateHandle.TlfID() != tlf.NullID {
err = config.DiskBlockCache().AddHomeTLF(ctx, privateHandle.TlfID())
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to set home TLF "+
"for disk block cache: %+v", err)
}
}
// Send to Favorites cache
info := homeTLFInfo{}
if publicHandle != nil {
teamID := publicHandle.ToFavToAdd(false).Data.TeamID
if teamID != nil {
info.PublicTeamID = *teamID
}
}
if privateHandle != nil {
teamID := privateHandle.ToFavToAdd(false).Data.TeamID
if teamID != nil {
info.PrivateTeamID = *teamID
}
}
config.KBFSOps().SetFavoritesHomeTLFInfo(ctx, info)
} | [
"func",
"setHomeTlfIdsForDbcAndFavorites",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"Config",
",",
"username",
"string",
")",
"{",
"if",
"config",
".",
"DiskBlockCache",
"(",
")",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"log",
":=",
"config",
".",
"MakeLogger",
"(",
"\"",
"\"",
")",
"\n",
"publicHandle",
",",
"err",
":=",
"getHandleFromFolderName",
"(",
"ctx",
",",
"config",
".",
"KBPKI",
"(",
")",
",",
"config",
".",
"MDOps",
"(",
")",
",",
"config",
",",
"username",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"CWarningf",
"(",
"ctx",
",",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"publicHandle",
".",
"TlfID",
"(",
")",
"!=",
"tlf",
".",
"NullID",
"{",
"err",
"=",
"config",
".",
"DiskBlockCache",
"(",
")",
".",
"AddHomeTLF",
"(",
"ctx",
",",
"publicHandle",
".",
"TlfID",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"CWarningf",
"(",
"ctx",
",",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"privateHandle",
",",
"err",
":=",
"getHandleFromFolderName",
"(",
"ctx",
",",
"config",
".",
"KBPKI",
"(",
")",
",",
"config",
".",
"MDOps",
"(",
")",
",",
"config",
",",
"username",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"CWarningf",
"(",
"ctx",
",",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"privateHandle",
".",
"TlfID",
"(",
")",
"!=",
"tlf",
".",
"NullID",
"{",
"err",
"=",
"config",
".",
"DiskBlockCache",
"(",
")",
".",
"AddHomeTLF",
"(",
"ctx",
",",
"privateHandle",
".",
"TlfID",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"CWarningf",
"(",
"ctx",
",",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Send to Favorites cache",
"info",
":=",
"homeTLFInfo",
"{",
"}",
"\n",
"if",
"publicHandle",
"!=",
"nil",
"{",
"teamID",
":=",
"publicHandle",
".",
"ToFavToAdd",
"(",
"false",
")",
".",
"Data",
".",
"TeamID",
"\n",
"if",
"teamID",
"!=",
"nil",
"{",
"info",
".",
"PublicTeamID",
"=",
"*",
"teamID",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"privateHandle",
"!=",
"nil",
"{",
"teamID",
":=",
"privateHandle",
".",
"ToFavToAdd",
"(",
"false",
")",
".",
"Data",
".",
"TeamID",
"\n",
"if",
"teamID",
"!=",
"nil",
"{",
"info",
".",
"PrivateTeamID",
"=",
"*",
"teamID",
"\n",
"}",
"\n",
"}",
"\n",
"config",
".",
"KBFSOps",
"(",
")",
".",
"SetFavoritesHomeTLFInfo",
"(",
"ctx",
",",
"info",
")",
"\n",
"}"
] | // setHomeTlfIdsForDbcAndFavorites sets the user's home TLFs on the disk
// block cache and the favorites cache. | [
"setHomeTlfIdsForDbcAndFavorites",
"sets",
"the",
"user",
"s",
"home",
"TLFs",
"on",
"the",
"disk",
"block",
"cache",
"and",
"the",
"favorites",
"cache",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/keybase_service_util.go#L34-L80 |
159,782 | keybase/client | go/kbfs/libkbfs/keybase_service_util.go | serviceLoggedIn | func serviceLoggedIn(ctx context.Context, config Config, session idutil.SessionInfo,
bws TLFJournalBackgroundWorkStatus) (wg *sync.WaitGroup) {
wg = &sync.WaitGroup{} // To avoid returning a nil pointer.
log := config.MakeLogger("")
if jManager, err := GetJournalManager(config); err == nil {
err := jManager.EnableExistingJournals(
ctx, session.UID, session.VerifyingKey, bws)
if err != nil {
log.CWarningf(ctx,
"Failed to enable existing journals: %v", err)
} else {
// Initializing the FBOs uses the mdserver, and this
// function might be called as part of MDServer.OnConnect,
// so be safe and initialize them in the background to
// avoid deadlocks.
newCtx := CtxWithRandomIDReplayable(context.Background(),
CtxKeybaseServiceIDKey, CtxKeybaseServiceOpID, log)
log.CDebugf(ctx, "Making FBOs in background: %s=%v",
CtxKeybaseServiceOpID, newCtx.Value(CtxKeybaseServiceIDKey))
wg = jManager.MakeFBOsForExistingJournals(newCtx)
}
}
err := config.MakeDiskBlockCacheIfNotExists()
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to enable disk cache: "+
"%+v", err)
}
// Asynchronously set the TLF IDs for the home folders on the disk block
// cache.
go setHomeTlfIdsForDbcAndFavorites(context.Background(), config, session.Name.String())
// Launch auth refreshes in the background, in case we are
// currently disconnected from one of these servers.
mdServer := config.MDServer()
if mdServer != nil {
go mdServer.RefreshAuthToken(context.Background())
}
bServer := config.BlockServer()
if bServer != nil {
go bServer.RefreshAuthToken(context.Background())
}
config.KBFSOps().RefreshCachedFavorites(ctx)
config.KBFSOps().PushStatusChange()
return wg
} | go | func serviceLoggedIn(ctx context.Context, config Config, session idutil.SessionInfo,
bws TLFJournalBackgroundWorkStatus) (wg *sync.WaitGroup) {
wg = &sync.WaitGroup{} // To avoid returning a nil pointer.
log := config.MakeLogger("")
if jManager, err := GetJournalManager(config); err == nil {
err := jManager.EnableExistingJournals(
ctx, session.UID, session.VerifyingKey, bws)
if err != nil {
log.CWarningf(ctx,
"Failed to enable existing journals: %v", err)
} else {
// Initializing the FBOs uses the mdserver, and this
// function might be called as part of MDServer.OnConnect,
// so be safe and initialize them in the background to
// avoid deadlocks.
newCtx := CtxWithRandomIDReplayable(context.Background(),
CtxKeybaseServiceIDKey, CtxKeybaseServiceOpID, log)
log.CDebugf(ctx, "Making FBOs in background: %s=%v",
CtxKeybaseServiceOpID, newCtx.Value(CtxKeybaseServiceIDKey))
wg = jManager.MakeFBOsForExistingJournals(newCtx)
}
}
err := config.MakeDiskBlockCacheIfNotExists()
if err != nil {
log.CWarningf(ctx, "serviceLoggedIn: Failed to enable disk cache: "+
"%+v", err)
}
// Asynchronously set the TLF IDs for the home folders on the disk block
// cache.
go setHomeTlfIdsForDbcAndFavorites(context.Background(), config, session.Name.String())
// Launch auth refreshes in the background, in case we are
// currently disconnected from one of these servers.
mdServer := config.MDServer()
if mdServer != nil {
go mdServer.RefreshAuthToken(context.Background())
}
bServer := config.BlockServer()
if bServer != nil {
go bServer.RefreshAuthToken(context.Background())
}
config.KBFSOps().RefreshCachedFavorites(ctx)
config.KBFSOps().PushStatusChange()
return wg
} | [
"func",
"serviceLoggedIn",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"Config",
",",
"session",
"idutil",
".",
"SessionInfo",
",",
"bws",
"TLFJournalBackgroundWorkStatus",
")",
"(",
"wg",
"*",
"sync",
".",
"WaitGroup",
")",
"{",
"wg",
"=",
"&",
"sync",
".",
"WaitGroup",
"{",
"}",
"// To avoid returning a nil pointer.",
"\n",
"log",
":=",
"config",
".",
"MakeLogger",
"(",
"\"",
"\"",
")",
"\n",
"if",
"jManager",
",",
"err",
":=",
"GetJournalManager",
"(",
"config",
")",
";",
"err",
"==",
"nil",
"{",
"err",
":=",
"jManager",
".",
"EnableExistingJournals",
"(",
"ctx",
",",
"session",
".",
"UID",
",",
"session",
".",
"VerifyingKey",
",",
"bws",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"CWarningf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"// Initializing the FBOs uses the mdserver, and this",
"// function might be called as part of MDServer.OnConnect,",
"// so be safe and initialize them in the background to",
"// avoid deadlocks.",
"newCtx",
":=",
"CtxWithRandomIDReplayable",
"(",
"context",
".",
"Background",
"(",
")",
",",
"CtxKeybaseServiceIDKey",
",",
"CtxKeybaseServiceOpID",
",",
"log",
")",
"\n",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"CtxKeybaseServiceOpID",
",",
"newCtx",
".",
"Value",
"(",
"CtxKeybaseServiceIDKey",
")",
")",
"\n",
"wg",
"=",
"jManager",
".",
"MakeFBOsForExistingJournals",
"(",
"newCtx",
")",
"\n",
"}",
"\n",
"}",
"\n",
"err",
":=",
"config",
".",
"MakeDiskBlockCacheIfNotExists",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"CWarningf",
"(",
"ctx",
",",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// Asynchronously set the TLF IDs for the home folders on the disk block",
"// cache.",
"go",
"setHomeTlfIdsForDbcAndFavorites",
"(",
"context",
".",
"Background",
"(",
")",
",",
"config",
",",
"session",
".",
"Name",
".",
"String",
"(",
")",
")",
"\n\n",
"// Launch auth refreshes in the background, in case we are",
"// currently disconnected from one of these servers.",
"mdServer",
":=",
"config",
".",
"MDServer",
"(",
")",
"\n",
"if",
"mdServer",
"!=",
"nil",
"{",
"go",
"mdServer",
".",
"RefreshAuthToken",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"}",
"\n",
"bServer",
":=",
"config",
".",
"BlockServer",
"(",
")",
"\n",
"if",
"bServer",
"!=",
"nil",
"{",
"go",
"bServer",
".",
"RefreshAuthToken",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"}",
"\n\n",
"config",
".",
"KBFSOps",
"(",
")",
".",
"RefreshCachedFavorites",
"(",
"ctx",
")",
"\n",
"config",
".",
"KBFSOps",
"(",
")",
".",
"PushStatusChange",
"(",
")",
"\n",
"return",
"wg",
"\n",
"}"
] | // serviceLoggedIn should be called when a new user logs in. It
// shouldn't be called again until after serviceLoggedOut is called. | [
"serviceLoggedIn",
"should",
"be",
"called",
"when",
"a",
"new",
"user",
"logs",
"in",
".",
"It",
"shouldn",
"t",
"be",
"called",
"again",
"until",
"after",
"serviceLoggedOut",
"is",
"called",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/keybase_service_util.go#L84-L129 |
159,783 | keybase/client | go/kbfs/libkbfs/keybase_service_util.go | serviceLoggedOut | func serviceLoggedOut(ctx context.Context, config Config) {
if jManager, err := GetJournalManager(config); err == nil {
jManager.shutdownExistingJournals(ctx)
}
config.ResetCaches()
config.UserHistory().Clear()
config.Chat().ClearCache()
mdServer := config.MDServer()
if mdServer != nil {
mdServer.RefreshAuthToken(ctx)
}
bServer := config.BlockServer()
if bServer != nil {
bServer.RefreshAuthToken(ctx)
}
config.KBFSOps().ClearCachedFavorites(ctx)
config.KBFSOps().PushStatusChange()
// Clear any cached MD for all private TLFs, as they shouldn't be
// readable by a logged out user. We assume that a logged-out
// call always comes before a logged-in call.
config.KBFSOps().ClearPrivateFolderMD(ctx)
} | go | func serviceLoggedOut(ctx context.Context, config Config) {
if jManager, err := GetJournalManager(config); err == nil {
jManager.shutdownExistingJournals(ctx)
}
config.ResetCaches()
config.UserHistory().Clear()
config.Chat().ClearCache()
mdServer := config.MDServer()
if mdServer != nil {
mdServer.RefreshAuthToken(ctx)
}
bServer := config.BlockServer()
if bServer != nil {
bServer.RefreshAuthToken(ctx)
}
config.KBFSOps().ClearCachedFavorites(ctx)
config.KBFSOps().PushStatusChange()
// Clear any cached MD for all private TLFs, as they shouldn't be
// readable by a logged out user. We assume that a logged-out
// call always comes before a logged-in call.
config.KBFSOps().ClearPrivateFolderMD(ctx)
} | [
"func",
"serviceLoggedOut",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"Config",
")",
"{",
"if",
"jManager",
",",
"err",
":=",
"GetJournalManager",
"(",
"config",
")",
";",
"err",
"==",
"nil",
"{",
"jManager",
".",
"shutdownExistingJournals",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"config",
".",
"ResetCaches",
"(",
")",
"\n",
"config",
".",
"UserHistory",
"(",
")",
".",
"Clear",
"(",
")",
"\n",
"config",
".",
"Chat",
"(",
")",
".",
"ClearCache",
"(",
")",
"\n",
"mdServer",
":=",
"config",
".",
"MDServer",
"(",
")",
"\n",
"if",
"mdServer",
"!=",
"nil",
"{",
"mdServer",
".",
"RefreshAuthToken",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"bServer",
":=",
"config",
".",
"BlockServer",
"(",
")",
"\n",
"if",
"bServer",
"!=",
"nil",
"{",
"bServer",
".",
"RefreshAuthToken",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"config",
".",
"KBFSOps",
"(",
")",
".",
"ClearCachedFavorites",
"(",
"ctx",
")",
"\n",
"config",
".",
"KBFSOps",
"(",
")",
".",
"PushStatusChange",
"(",
")",
"\n\n",
"// Clear any cached MD for all private TLFs, as they shouldn't be",
"// readable by a logged out user. We assume that a logged-out",
"// call always comes before a logged-in call.",
"config",
".",
"KBFSOps",
"(",
")",
".",
"ClearPrivateFolderMD",
"(",
"ctx",
")",
"\n",
"}"
] | // serviceLoggedOut should be called when the current user logs out. | [
"serviceLoggedOut",
"should",
"be",
"called",
"when",
"the",
"current",
"user",
"logs",
"out",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/keybase_service_util.go#L132-L154 |
159,784 | keybase/client | go/kbfs/libkey/key_server_measured.go | NewKeyServerMeasured | func NewKeyServerMeasured(delegate KeyServer, r metrics.Registry) KeyServerMeasured {
getTimer := metrics.GetOrRegisterTimer("KeyServer.GetTLFCryptKeyServerHalf", r)
putTimer := metrics.GetOrRegisterTimer("KeyServer.PutTLFCryptKeyServerHalves", r)
deleteTimer := metrics.GetOrRegisterTimer("KeyServer.DeleteTLFCryptKeyServerHalf", r)
return KeyServerMeasured{
delegate: delegate,
getTimer: getTimer,
putTimer: putTimer,
deleteTimer: deleteTimer,
}
} | go | func NewKeyServerMeasured(delegate KeyServer, r metrics.Registry) KeyServerMeasured {
getTimer := metrics.GetOrRegisterTimer("KeyServer.GetTLFCryptKeyServerHalf", r)
putTimer := metrics.GetOrRegisterTimer("KeyServer.PutTLFCryptKeyServerHalves", r)
deleteTimer := metrics.GetOrRegisterTimer("KeyServer.DeleteTLFCryptKeyServerHalf", r)
return KeyServerMeasured{
delegate: delegate,
getTimer: getTimer,
putTimer: putTimer,
deleteTimer: deleteTimer,
}
} | [
"func",
"NewKeyServerMeasured",
"(",
"delegate",
"KeyServer",
",",
"r",
"metrics",
".",
"Registry",
")",
"KeyServerMeasured",
"{",
"getTimer",
":=",
"metrics",
".",
"GetOrRegisterTimer",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"putTimer",
":=",
"metrics",
".",
"GetOrRegisterTimer",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"deleteTimer",
":=",
"metrics",
".",
"GetOrRegisterTimer",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"return",
"KeyServerMeasured",
"{",
"delegate",
":",
"delegate",
",",
"getTimer",
":",
"getTimer",
",",
"putTimer",
":",
"putTimer",
",",
"deleteTimer",
":",
"deleteTimer",
",",
"}",
"\n",
"}"
] | // NewKeyServerMeasured creates and returns a new KeyServerMeasured
// instance with the given delegate and registry. | [
"NewKeyServerMeasured",
"creates",
"and",
"returns",
"a",
"new",
"KeyServerMeasured",
"instance",
"with",
"the",
"given",
"delegate",
"and",
"registry",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_server_measured.go#L28-L38 |
159,785 | keybase/client | go/kbfs/libkey/key_server_measured.go | GetTLFCryptKeyServerHalf | func (b KeyServerMeasured) GetTLFCryptKeyServerHalf(ctx context.Context,
serverHalfID kbfscrypto.TLFCryptKeyServerHalfID, key kbfscrypto.CryptPublicKey) (
serverHalf kbfscrypto.TLFCryptKeyServerHalf, err error) {
b.getTimer.Time(func() {
serverHalf, err = b.delegate.GetTLFCryptKeyServerHalf(ctx, serverHalfID, key)
})
return serverHalf, err
} | go | func (b KeyServerMeasured) GetTLFCryptKeyServerHalf(ctx context.Context,
serverHalfID kbfscrypto.TLFCryptKeyServerHalfID, key kbfscrypto.CryptPublicKey) (
serverHalf kbfscrypto.TLFCryptKeyServerHalf, err error) {
b.getTimer.Time(func() {
serverHalf, err = b.delegate.GetTLFCryptKeyServerHalf(ctx, serverHalfID, key)
})
return serverHalf, err
} | [
"func",
"(",
"b",
"KeyServerMeasured",
")",
"GetTLFCryptKeyServerHalf",
"(",
"ctx",
"context",
".",
"Context",
",",
"serverHalfID",
"kbfscrypto",
".",
"TLFCryptKeyServerHalfID",
",",
"key",
"kbfscrypto",
".",
"CryptPublicKey",
")",
"(",
"serverHalf",
"kbfscrypto",
".",
"TLFCryptKeyServerHalf",
",",
"err",
"error",
")",
"{",
"b",
".",
"getTimer",
".",
"Time",
"(",
"func",
"(",
")",
"{",
"serverHalf",
",",
"err",
"=",
"b",
".",
"delegate",
".",
"GetTLFCryptKeyServerHalf",
"(",
"ctx",
",",
"serverHalfID",
",",
"key",
")",
"\n",
"}",
")",
"\n",
"return",
"serverHalf",
",",
"err",
"\n",
"}"
] | // GetTLFCryptKeyServerHalf implements the KeyServer interface for
// KeyServerMeasured. | [
"GetTLFCryptKeyServerHalf",
"implements",
"the",
"KeyServer",
"interface",
"for",
"KeyServerMeasured",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_server_measured.go#L42-L49 |
159,786 | keybase/client | go/kbfs/libkey/key_server_measured.go | PutTLFCryptKeyServerHalves | func (b KeyServerMeasured) PutTLFCryptKeyServerHalves(ctx context.Context,
keyServerHalves kbfsmd.UserDeviceKeyServerHalves) (err error) {
b.putTimer.Time(func() {
err = b.delegate.PutTLFCryptKeyServerHalves(ctx, keyServerHalves)
})
return err
} | go | func (b KeyServerMeasured) PutTLFCryptKeyServerHalves(ctx context.Context,
keyServerHalves kbfsmd.UserDeviceKeyServerHalves) (err error) {
b.putTimer.Time(func() {
err = b.delegate.PutTLFCryptKeyServerHalves(ctx, keyServerHalves)
})
return err
} | [
"func",
"(",
"b",
"KeyServerMeasured",
")",
"PutTLFCryptKeyServerHalves",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyServerHalves",
"kbfsmd",
".",
"UserDeviceKeyServerHalves",
")",
"(",
"err",
"error",
")",
"{",
"b",
".",
"putTimer",
".",
"Time",
"(",
"func",
"(",
")",
"{",
"err",
"=",
"b",
".",
"delegate",
".",
"PutTLFCryptKeyServerHalves",
"(",
"ctx",
",",
"keyServerHalves",
")",
"\n",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // PutTLFCryptKeyServerHalves implements the KeyServer interface for
// KeyServerMeasured. | [
"PutTLFCryptKeyServerHalves",
"implements",
"the",
"KeyServer",
"interface",
"for",
"KeyServerMeasured",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_server_measured.go#L53-L59 |
159,787 | keybase/client | go/kbfs/libkey/key_server_measured.go | DeleteTLFCryptKeyServerHalf | func (b KeyServerMeasured) DeleteTLFCryptKeyServerHalf(ctx context.Context,
uid keybase1.UID, key kbfscrypto.CryptPublicKey,
serverHalfID kbfscrypto.TLFCryptKeyServerHalfID) (err error) {
b.deleteTimer.Time(func() {
err = b.delegate.DeleteTLFCryptKeyServerHalf(
ctx, uid, key, serverHalfID)
})
return err
} | go | func (b KeyServerMeasured) DeleteTLFCryptKeyServerHalf(ctx context.Context,
uid keybase1.UID, key kbfscrypto.CryptPublicKey,
serverHalfID kbfscrypto.TLFCryptKeyServerHalfID) (err error) {
b.deleteTimer.Time(func() {
err = b.delegate.DeleteTLFCryptKeyServerHalf(
ctx, uid, key, serverHalfID)
})
return err
} | [
"func",
"(",
"b",
"KeyServerMeasured",
")",
"DeleteTLFCryptKeyServerHalf",
"(",
"ctx",
"context",
".",
"Context",
",",
"uid",
"keybase1",
".",
"UID",
",",
"key",
"kbfscrypto",
".",
"CryptPublicKey",
",",
"serverHalfID",
"kbfscrypto",
".",
"TLFCryptKeyServerHalfID",
")",
"(",
"err",
"error",
")",
"{",
"b",
".",
"deleteTimer",
".",
"Time",
"(",
"func",
"(",
")",
"{",
"err",
"=",
"b",
".",
"delegate",
".",
"DeleteTLFCryptKeyServerHalf",
"(",
"ctx",
",",
"uid",
",",
"key",
",",
"serverHalfID",
")",
"\n",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // DeleteTLFCryptKeyServerHalf implements the KeyServer interface for
// KeyServerMeasured. | [
"DeleteTLFCryptKeyServerHalf",
"implements",
"the",
"KeyServer",
"interface",
"for",
"KeyServerMeasured",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_server_measured.go#L63-L71 |
159,788 | keybase/client | go/kex2/transport.go | Eq | func (d DeviceID) Eq(d2 DeviceID) bool {
return hmac.Equal(d[:], d2[:])
} | go | func (d DeviceID) Eq(d2 DeviceID) bool {
return hmac.Equal(d[:], d2[:])
} | [
"func",
"(",
"d",
"DeviceID",
")",
"Eq",
"(",
"d2",
"DeviceID",
")",
"bool",
"{",
"return",
"hmac",
".",
"Equal",
"(",
"d",
"[",
":",
"]",
",",
"d2",
"[",
":",
"]",
")",
"\n",
"}"
] | // Eq returns true if the two device IDs are equal | [
"Eq",
"returns",
"true",
"if",
"the",
"two",
"device",
"IDs",
"are",
"equal"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kex2/transport.go#L40-L42 |
159,789 | keybase/client | go/kex2/transport.go | Eq | func (s SessionID) Eq(s2 SessionID) bool {
return hmac.Equal(s[:], s2[:])
} | go | func (s SessionID) Eq(s2 SessionID) bool {
return hmac.Equal(s[:], s2[:])
} | [
"func",
"(",
"s",
"SessionID",
")",
"Eq",
"(",
"s2",
"SessionID",
")",
"bool",
"{",
"return",
"hmac",
".",
"Equal",
"(",
"s",
"[",
":",
"]",
",",
"s2",
"[",
":",
"]",
")",
"\n",
"}"
] | // Eq returns true if the two session IDs are equal | [
"Eq",
"returns",
"true",
"if",
"the",
"two",
"session",
"IDs",
"are",
"equal"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kex2/transport.go#L45-L47 |
159,790 | keybase/client | go/kex2/transport.go | NewConn | func NewConn(ctx context.Context, lctx LogContext, r MessageRouter, s Secret, d DeviceID, readTimeout time.Duration) (con net.Conn, err error) {
mac := hmac.New(sha256.New, []byte(s[:]))
mac.Write([]byte(sessionIDText))
tmp := mac.Sum(nil)
var sessionID SessionID
copy(sessionID[:], tmp)
ret := &Conn{
router: r,
secret: s,
sessionID: sessionID,
deviceID: d,
readSeqno: 0,
readTimeout: readTimeout,
writeSeqno: 0,
ctx: ctx,
lctx: lctx,
}
return ret, nil
} | go | func NewConn(ctx context.Context, lctx LogContext, r MessageRouter, s Secret, d DeviceID, readTimeout time.Duration) (con net.Conn, err error) {
mac := hmac.New(sha256.New, []byte(s[:]))
mac.Write([]byte(sessionIDText))
tmp := mac.Sum(nil)
var sessionID SessionID
copy(sessionID[:], tmp)
ret := &Conn{
router: r,
secret: s,
sessionID: sessionID,
deviceID: d,
readSeqno: 0,
readTimeout: readTimeout,
writeSeqno: 0,
ctx: ctx,
lctx: lctx,
}
return ret, nil
} | [
"func",
"NewConn",
"(",
"ctx",
"context",
".",
"Context",
",",
"lctx",
"LogContext",
",",
"r",
"MessageRouter",
",",
"s",
"Secret",
",",
"d",
"DeviceID",
",",
"readTimeout",
"time",
".",
"Duration",
")",
"(",
"con",
"net",
".",
"Conn",
",",
"err",
"error",
")",
"{",
"mac",
":=",
"hmac",
".",
"New",
"(",
"sha256",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"s",
"[",
":",
"]",
")",
")",
"\n",
"mac",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"sessionIDText",
")",
")",
"\n",
"tmp",
":=",
"mac",
".",
"Sum",
"(",
"nil",
")",
"\n",
"var",
"sessionID",
"SessionID",
"\n",
"copy",
"(",
"sessionID",
"[",
":",
"]",
",",
"tmp",
")",
"\n",
"ret",
":=",
"&",
"Conn",
"{",
"router",
":",
"r",
",",
"secret",
":",
"s",
",",
"sessionID",
":",
"sessionID",
",",
"deviceID",
":",
"d",
",",
"readSeqno",
":",
"0",
",",
"readTimeout",
":",
"readTimeout",
",",
"writeSeqno",
":",
"0",
",",
"ctx",
":",
"ctx",
",",
"lctx",
":",
"lctx",
",",
"}",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // NewConn establishes a Kex session based on the given secret. Will work for
// both ends of the connection, regardless of which order the two started
// their connection. Will communicate with the other end via the given message router.
// You can specify an optional timeout to cancel any reads longer than that timeout. | [
"NewConn",
"establishes",
"a",
"Kex",
"session",
"based",
"on",
"the",
"given",
"secret",
".",
"Will",
"work",
"for",
"both",
"ends",
"of",
"the",
"connection",
"regardless",
"of",
"which",
"order",
"the",
"two",
"started",
"their",
"connection",
".",
"Will",
"communicate",
"with",
"the",
"other",
"end",
"via",
"the",
"given",
"message",
"router",
".",
"You",
"can",
"specify",
"an",
"optional",
"timeout",
"to",
"cancel",
"any",
"reads",
"longer",
"than",
"that",
"timeout",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kex2/transport.go#L109-L127 |
159,791 | keybase/client | go/kex2/transport.go | Read | func (c *Conn) Read(out []byte) (n int, err error) {
c.readMutex.Lock()
defer c.readMutex.Unlock()
// The first error kills the whole stream
if err = c.getErrorForRead(); err != nil {
return 0, err
}
// First see if there's anything buffered, and read that
// out now.
if n, err = c.readBufferedMsgsIntoBytes(out); err != nil {
return 0, c.setReadError(err)
}
if n > 0 {
return n, nil
}
var poll time.Duration
if !c.readDeadline.IsZero() {
poll = c.readDeadline.Sub(time.Now())
if poll.Nanoseconds() < 0 {
return 0, c.setReadError(ErrTimedOut)
}
} else {
poll = c.readTimeout
}
var msgs [][]byte
msgs, err = c.pollLoop(poll)
if err != nil {
return 0, c.setReadError(err)
}
if _, err = c.decryptIncomingMessages(msgs); err != nil {
return 0, c.setReadError(err)
}
if n, err = c.readBufferedMsgsIntoBytes(out); err != nil {
return 0, c.setReadError(err)
}
if n == 0 {
switch {
case c.getClosed():
c.lctx.Debug("conn#Read: EOF since connection was closed")
err = io.EOF
case poll > 0:
err = ErrTimedOut
default:
err = ErrAgain
}
}
return n, err
} | go | func (c *Conn) Read(out []byte) (n int, err error) {
c.readMutex.Lock()
defer c.readMutex.Unlock()
// The first error kills the whole stream
if err = c.getErrorForRead(); err != nil {
return 0, err
}
// First see if there's anything buffered, and read that
// out now.
if n, err = c.readBufferedMsgsIntoBytes(out); err != nil {
return 0, c.setReadError(err)
}
if n > 0 {
return n, nil
}
var poll time.Duration
if !c.readDeadline.IsZero() {
poll = c.readDeadline.Sub(time.Now())
if poll.Nanoseconds() < 0 {
return 0, c.setReadError(ErrTimedOut)
}
} else {
poll = c.readTimeout
}
var msgs [][]byte
msgs, err = c.pollLoop(poll)
if err != nil {
return 0, c.setReadError(err)
}
if _, err = c.decryptIncomingMessages(msgs); err != nil {
return 0, c.setReadError(err)
}
if n, err = c.readBufferedMsgsIntoBytes(out); err != nil {
return 0, c.setReadError(err)
}
if n == 0 {
switch {
case c.getClosed():
c.lctx.Debug("conn#Read: EOF since connection was closed")
err = io.EOF
case poll > 0:
err = ErrTimedOut
default:
err = ErrAgain
}
}
return n, err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Read",
"(",
"out",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"c",
".",
"readMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"readMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// The first error kills the whole stream",
"if",
"err",
"=",
"c",
".",
"getErrorForRead",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"// First see if there's anything buffered, and read that",
"// out now.",
"if",
"n",
",",
"err",
"=",
"c",
".",
"readBufferedMsgsIntoBytes",
"(",
"out",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"c",
".",
"setReadError",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"n",
">",
"0",
"{",
"return",
"n",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"poll",
"time",
".",
"Duration",
"\n",
"if",
"!",
"c",
".",
"readDeadline",
".",
"IsZero",
"(",
")",
"{",
"poll",
"=",
"c",
".",
"readDeadline",
".",
"Sub",
"(",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"if",
"poll",
".",
"Nanoseconds",
"(",
")",
"<",
"0",
"{",
"return",
"0",
",",
"c",
".",
"setReadError",
"(",
"ErrTimedOut",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"poll",
"=",
"c",
".",
"readTimeout",
"\n",
"}",
"\n\n",
"var",
"msgs",
"[",
"]",
"[",
"]",
"byte",
"\n",
"msgs",
",",
"err",
"=",
"c",
".",
"pollLoop",
"(",
"poll",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"c",
".",
"setReadError",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
"=",
"c",
".",
"decryptIncomingMessages",
"(",
"msgs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"c",
".",
"setReadError",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"n",
",",
"err",
"=",
"c",
".",
"readBufferedMsgsIntoBytes",
"(",
"out",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"c",
".",
"setReadError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"n",
"==",
"0",
"{",
"switch",
"{",
"case",
"c",
".",
"getClosed",
"(",
")",
":",
"c",
".",
"lctx",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"io",
".",
"EOF",
"\n",
"case",
"poll",
">",
"0",
":",
"err",
"=",
"ErrTimedOut",
"\n",
"default",
":",
"err",
"=",
"ErrAgain",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"n",
",",
"err",
"\n",
"}"
] | // Read data from the connection, returning plaintext data if all
// cryptographic checks passed. Obeys the `net.Conn` interface.
// Returns the number of bytes read into the output buffer. | [
"Read",
"data",
"from",
"the",
"connection",
"returning",
"plaintext",
"data",
"if",
"all",
"cryptographic",
"checks",
"passed",
".",
"Obeys",
"the",
"net",
".",
"Conn",
"interface",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"read",
"into",
"the",
"output",
"buffer",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kex2/transport.go#L412-L466 |
159,792 | keybase/client | go/kex2/transport.go | Write | func (c *Conn) Write(buf []byte) (n int, err error) {
c.writeMutex.Lock()
defer c.writeMutex.Unlock()
// Our protocol specifies that writing an empty buffer means "close"
// the connection. We don't want callers of `Write` to do this by
// accident, we want them to call `Close()` explicitly. So short-circuit
// the write operation here for empty buffers.
if len(buf) == 0 {
return 0, nil
}
return c.writeWithLock(buf)
} | go | func (c *Conn) Write(buf []byte) (n int, err error) {
c.writeMutex.Lock()
defer c.writeMutex.Unlock()
// Our protocol specifies that writing an empty buffer means "close"
// the connection. We don't want callers of `Write` to do this by
// accident, we want them to call `Close()` explicitly. So short-circuit
// the write operation here for empty buffers.
if len(buf) == 0 {
return 0, nil
}
return c.writeWithLock(buf)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Write",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"c",
".",
"writeMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"writeMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Our protocol specifies that writing an empty buffer means \"close\"",
"// the connection. We don't want callers of `Write` to do this by",
"// accident, we want them to call `Close()` explicitly. So short-circuit",
"// the write operation here for empty buffers.",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"writeWithLock",
"(",
"buf",
")",
"\n",
"}"
] | // Write data to the connection, encrypting and MAC'ing along the way.
// Obeys the `net.Conn` interface | [
"Write",
"data",
"to",
"the",
"connection",
"encrypting",
"and",
"MAC",
"ing",
"along",
"the",
"way",
".",
"Obeys",
"the",
"net",
".",
"Conn",
"interface"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kex2/transport.go#L512-L526 |
159,793 | keybase/client | go/kex2/transport.go | Close | func (c *Conn) Close() error {
c.writeMutex.Lock()
defer c.writeMutex.Unlock()
c.lctx.Debug("Conn#Close: all subsequent writes are EOFs")
// set closed so that the read loop will bail out above
c.setClosed()
// Write an empty buffer to signal EOF
if _, err := c.writeWithLock([]byte{}); err != nil {
return err
}
// All subsequent writes should fail.
c.setWriteError(io.EOF)
return nil
} | go | func (c *Conn) Close() error {
c.writeMutex.Lock()
defer c.writeMutex.Unlock()
c.lctx.Debug("Conn#Close: all subsequent writes are EOFs")
// set closed so that the read loop will bail out above
c.setClosed()
// Write an empty buffer to signal EOF
if _, err := c.writeWithLock([]byte{}); err != nil {
return err
}
// All subsequent writes should fail.
c.setWriteError(io.EOF)
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Close",
"(",
")",
"error",
"{",
"c",
".",
"writeMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"writeMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"c",
".",
"lctx",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// set closed so that the read loop will bail out above",
"c",
".",
"setClosed",
"(",
")",
"\n\n",
"// Write an empty buffer to signal EOF",
"if",
"_",
",",
"err",
":=",
"c",
".",
"writeWithLock",
"(",
"[",
"]",
"byte",
"{",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// All subsequent writes should fail.",
"c",
".",
"setWriteError",
"(",
"io",
".",
"EOF",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close the connection to the server, sending an empty buffer via POST
// through the `MessageRouter`. Fulfills the `net.Conn` interface | [
"Close",
"the",
"connection",
"to",
"the",
"server",
"sending",
"an",
"empty",
"buffer",
"via",
"POST",
"through",
"the",
"MessageRouter",
".",
"Fulfills",
"the",
"net",
".",
"Conn",
"interface"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kex2/transport.go#L552-L571 |
159,794 | keybase/client | go/kex2/transport.go | SetReadDeadline | func (c *Conn) SetReadDeadline(t time.Time) error {
c.readMutex.Lock()
c.readDeadline = t
c.readMutex.Unlock()
return nil
} | go | func (c *Conn) SetReadDeadline(t time.Time) error {
c.readMutex.Lock()
c.readDeadline = t
c.readMutex.Unlock()
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetReadDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"c",
".",
"readMutex",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"readDeadline",
"=",
"t",
"\n",
"c",
".",
"readMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetReadDeadline sets the deadline for future Read calls.
// A zero value for t means Read will not time out. | [
"SetReadDeadline",
"sets",
"the",
"deadline",
"for",
"future",
"Read",
"calls",
".",
"A",
"zero",
"value",
"for",
"t",
"means",
"Read",
"will",
"not",
"time",
"out",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kex2/transport.go#L602-L607 |
159,795 | keybase/client | go/engine/hasserverkeys.go | NewHasServerKeys | func NewHasServerKeys(g *libkb.GlobalContext) *HasServerKeys {
return &HasServerKeys{
Contextified: libkb.NewContextified(g),
}
} | go | func NewHasServerKeys(g *libkb.GlobalContext) *HasServerKeys {
return &HasServerKeys{
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewHasServerKeys",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"*",
"HasServerKeys",
"{",
"return",
"&",
"HasServerKeys",
"{",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewHasServerKeys creates a HasServerKeys engine. | [
"NewHasServerKeys",
"creates",
"a",
"HasServerKeys",
"engine",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/hasserverkeys.go#L18-L22 |
159,796 | keybase/client | go/service/session.go | NewSessionHandler | func NewSessionHandler(xp rpc.Transporter, g *libkb.GlobalContext) *SessionHandler {
return &SessionHandler{
BaseHandler: NewBaseHandler(g, xp),
Contextified: libkb.NewContextified(g),
}
} | go | func NewSessionHandler(xp rpc.Transporter, g *libkb.GlobalContext) *SessionHandler {
return &SessionHandler{
BaseHandler: NewBaseHandler(g, xp),
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewSessionHandler",
"(",
"xp",
"rpc",
".",
"Transporter",
",",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"*",
"SessionHandler",
"{",
"return",
"&",
"SessionHandler",
"{",
"BaseHandler",
":",
"NewBaseHandler",
"(",
"g",
",",
"xp",
")",
",",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewSessionHandler creates a SessionHandler for the xp transport. | [
"NewSessionHandler",
"creates",
"a",
"SessionHandler",
"for",
"the",
"xp",
"transport",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/session.go#L21-L26 |
159,797 | keybase/client | go/service/session.go | CurrentSession | func (h *SessionHandler) CurrentSession(ctx context.Context, sessionID int) (keybase1.Session, error) {
var s keybase1.Session
nist, uid, _, err := h.G().ActiveDevice.NISTAndUIDDeviceID(ctx)
if nist == nil {
return s, libkb.NoSessionError{}
}
if err != nil {
return s, err
}
un, err := h.G().GetUPAKLoader().LookupUsername(ctx, uid)
if err != nil {
return s, err
}
sibkey, err := h.G().ActiveDevice.SigningKey()
if err != nil {
return s, err
}
subkey, err := h.G().ActiveDevice.EncryptionKey()
if err != nil {
return s, err
}
s.Uid = uid
s.Username = un.String()
s.Token = nist.Token().String()
s.DeviceSubkeyKid = subkey.GetKID()
s.DeviceSibkeyKid = sibkey.GetKID()
return s, nil
} | go | func (h *SessionHandler) CurrentSession(ctx context.Context, sessionID int) (keybase1.Session, error) {
var s keybase1.Session
nist, uid, _, err := h.G().ActiveDevice.NISTAndUIDDeviceID(ctx)
if nist == nil {
return s, libkb.NoSessionError{}
}
if err != nil {
return s, err
}
un, err := h.G().GetUPAKLoader().LookupUsername(ctx, uid)
if err != nil {
return s, err
}
sibkey, err := h.G().ActiveDevice.SigningKey()
if err != nil {
return s, err
}
subkey, err := h.G().ActiveDevice.EncryptionKey()
if err != nil {
return s, err
}
s.Uid = uid
s.Username = un.String()
s.Token = nist.Token().String()
s.DeviceSubkeyKid = subkey.GetKID()
s.DeviceSibkeyKid = sibkey.GetKID()
return s, nil
} | [
"func",
"(",
"h",
"*",
"SessionHandler",
")",
"CurrentSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"sessionID",
"int",
")",
"(",
"keybase1",
".",
"Session",
",",
"error",
")",
"{",
"var",
"s",
"keybase1",
".",
"Session",
"\n\n",
"nist",
",",
"uid",
",",
"_",
",",
"err",
":=",
"h",
".",
"G",
"(",
")",
".",
"ActiveDevice",
".",
"NISTAndUIDDeviceID",
"(",
"ctx",
")",
"\n",
"if",
"nist",
"==",
"nil",
"{",
"return",
"s",
",",
"libkb",
".",
"NoSessionError",
"{",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"s",
",",
"err",
"\n",
"}",
"\n\n",
"un",
",",
"err",
":=",
"h",
".",
"G",
"(",
")",
".",
"GetUPAKLoader",
"(",
")",
".",
"LookupUsername",
"(",
"ctx",
",",
"uid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"s",
",",
"err",
"\n",
"}",
"\n",
"sibkey",
",",
"err",
":=",
"h",
".",
"G",
"(",
")",
".",
"ActiveDevice",
".",
"SigningKey",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"s",
",",
"err",
"\n",
"}",
"\n",
"subkey",
",",
"err",
":=",
"h",
".",
"G",
"(",
")",
".",
"ActiveDevice",
".",
"EncryptionKey",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"s",
",",
"err",
"\n",
"}",
"\n\n",
"s",
".",
"Uid",
"=",
"uid",
"\n",
"s",
".",
"Username",
"=",
"un",
".",
"String",
"(",
")",
"\n",
"s",
".",
"Token",
"=",
"nist",
".",
"Token",
"(",
")",
".",
"String",
"(",
")",
"\n",
"s",
".",
"DeviceSubkeyKid",
"=",
"subkey",
".",
"GetKID",
"(",
")",
"\n",
"s",
".",
"DeviceSibkeyKid",
"=",
"sibkey",
".",
"GetKID",
"(",
")",
"\n\n",
"return",
"s",
",",
"nil",
"\n",
"}"
] | // CurrentSession uses the global session to find the session. If
// the user isn't logged in, it returns libkb.NoSessionError.
//
// This function was modified to use cached information instead
// of loading the full self user.
//
// This does do a full call to sesscheck and ensures that the
// session token is valid. | [
"CurrentSession",
"uses",
"the",
"global",
"session",
"to",
"find",
"the",
"session",
".",
"If",
"the",
"user",
"isn",
"t",
"logged",
"in",
"it",
"returns",
"libkb",
".",
"NoSessionError",
".",
"This",
"function",
"was",
"modified",
"to",
"use",
"cached",
"information",
"instead",
"of",
"loading",
"the",
"full",
"self",
"user",
".",
"This",
"does",
"do",
"a",
"full",
"call",
"to",
"sesscheck",
"and",
"ensures",
"that",
"the",
"session",
"token",
"is",
"valid",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/session.go#L36-L67 |
159,798 | keybase/client | go/stellar/seqno.go | NewClaimSeqnoProvider | func NewClaimSeqnoProvider(mctx libkb.MetaContext, walletState *WalletState) (seqnoProvider *ClaimSeqnoProvider, unlock func()) {
walletState.SeqnoLock()
return &ClaimSeqnoProvider{
mctx: mctx,
walletState: walletState,
}, walletState.SeqnoUnlock
} | go | func NewClaimSeqnoProvider(mctx libkb.MetaContext, walletState *WalletState) (seqnoProvider *ClaimSeqnoProvider, unlock func()) {
walletState.SeqnoLock()
return &ClaimSeqnoProvider{
mctx: mctx,
walletState: walletState,
}, walletState.SeqnoUnlock
} | [
"func",
"NewClaimSeqnoProvider",
"(",
"mctx",
"libkb",
".",
"MetaContext",
",",
"walletState",
"*",
"WalletState",
")",
"(",
"seqnoProvider",
"*",
"ClaimSeqnoProvider",
",",
"unlock",
"func",
"(",
")",
")",
"{",
"walletState",
".",
"SeqnoLock",
"(",
")",
"\n",
"return",
"&",
"ClaimSeqnoProvider",
"{",
"mctx",
":",
"mctx",
",",
"walletState",
":",
"walletState",
",",
"}",
",",
"walletState",
".",
"SeqnoUnlock",
"\n",
"}"
] | // NewClaimSeqnoProvider creates a ClaimSeqnoProvider for use in relay claims. | [
"NewClaimSeqnoProvider",
"creates",
"a",
"ClaimSeqnoProvider",
"for",
"use",
"in",
"relay",
"claims",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/seqno.go#L67-L73 |
159,799 | keybase/client | go/teams/loader.go | Load | func Load(ctx context.Context, g *libkb.GlobalContext, lArg keybase1.LoadTeamArg) (*Team, error) {
teamData, err := g.GetTeamLoader().Load(ctx, lArg)
if err != nil {
return nil, err
}
ret := NewTeam(ctx, g, teamData)
if lArg.RefreshUIDMapper {
// If we just loaded the group, then inform the UIDMapper of any UID->EldestSeqno
// mappings, so that we're guaranteed they aren't stale.
ret.refreshUIDMapper(ctx, g)
}
return ret, nil
} | go | func Load(ctx context.Context, g *libkb.GlobalContext, lArg keybase1.LoadTeamArg) (*Team, error) {
teamData, err := g.GetTeamLoader().Load(ctx, lArg)
if err != nil {
return nil, err
}
ret := NewTeam(ctx, g, teamData)
if lArg.RefreshUIDMapper {
// If we just loaded the group, then inform the UIDMapper of any UID->EldestSeqno
// mappings, so that we're guaranteed they aren't stale.
ret.refreshUIDMapper(ctx, g)
}
return ret, nil
} | [
"func",
"Load",
"(",
"ctx",
"context",
".",
"Context",
",",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"lArg",
"keybase1",
".",
"LoadTeamArg",
")",
"(",
"*",
"Team",
",",
"error",
")",
"{",
"teamData",
",",
"err",
":=",
"g",
".",
"GetTeamLoader",
"(",
")",
".",
"Load",
"(",
"ctx",
",",
"lArg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ret",
":=",
"NewTeam",
"(",
"ctx",
",",
"g",
",",
"teamData",
")",
"\n\n",
"if",
"lArg",
".",
"RefreshUIDMapper",
"{",
"// If we just loaded the group, then inform the UIDMapper of any UID->EldestSeqno",
"// mappings, so that we're guaranteed they aren't stale.",
"ret",
".",
"refreshUIDMapper",
"(",
"ctx",
",",
"g",
")",
"\n",
"}",
"\n\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // Load a Team from the TeamLoader.
// Can be called from inside the teams package. | [
"Load",
"a",
"Team",
"from",
"the",
"TeamLoader",
".",
"Can",
"be",
"called",
"from",
"inside",
"the",
"teams",
"package",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/loader.go#L40-L54 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.