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
|
---|---|---|---|---|---|---|---|---|---|---|---|
158,800 | keybase/client | go/mounter/mounter_nix.go | ForceUnmount | func ForceUnmount(dir string, log Log) error {
switch runtime.GOOS {
case "darwin":
log.Info("Force unmounting with diskutil")
out, err := exec.Command("/usr/sbin/diskutil", "unmountDisk", "force", dir).CombinedOutput()
log.Debug("Output: %s", string(out))
return err
case "linux":
log.Info("Force unmounting with umount -l")
out, err := exec.Command("umount", "-l", dir).CombinedOutput()
log.Debug("Output: %s", string(out))
return err
default:
return errors.New("Forced unmount is not supported on this platform yet")
}
} | go | func ForceUnmount(dir string, log Log) error {
switch runtime.GOOS {
case "darwin":
log.Info("Force unmounting with diskutil")
out, err := exec.Command("/usr/sbin/diskutil", "unmountDisk", "force", dir).CombinedOutput()
log.Debug("Output: %s", string(out))
return err
case "linux":
log.Info("Force unmounting with umount -l")
out, err := exec.Command("umount", "-l", dir).CombinedOutput()
log.Debug("Output: %s", string(out))
return err
default:
return errors.New("Forced unmount is not supported on this platform yet")
}
} | [
"func",
"ForceUnmount",
"(",
"dir",
"string",
",",
"log",
"Log",
")",
"error",
"{",
"switch",
"runtime",
".",
"GOOS",
"{",
"case",
"\"",
"\"",
":",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"dir",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"string",
"(",
"out",
")",
")",
"\n",
"return",
"err",
"\n",
"case",
"\"",
"\"",
":",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"dir",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"string",
"(",
"out",
")",
")",
"\n",
"return",
"err",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // ForceUnmount tries to forcibly unmount a directory | [
"ForceUnmount",
"tries",
"to",
"forcibly",
"unmount",
"a",
"directory"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/mounter/mounter_nix.go#L43-L58 |
158,801 | keybase/client | go/kbfs/libfs/file.go | Write | func (f *File) Write(p []byte) (n int, err error) {
if f.readOnly {
return 0, errors.New("Trying to write a read-only file")
}
origOffset := atomic.LoadInt64(&f.offset)
err = f.fs.config.KBFSOps().Write(f.fs.ctx, f.node, p, origOffset)
if err != nil {
return 0, err
}
f.updateOffset(origOffset, int64(len(p)))
return len(p), nil
} | go | func (f *File) Write(p []byte) (n int, err error) {
if f.readOnly {
return 0, errors.New("Trying to write a read-only file")
}
origOffset := atomic.LoadInt64(&f.offset)
err = f.fs.config.KBFSOps().Write(f.fs.ctx, f.node, p, origOffset)
if err != nil {
return 0, err
}
f.updateOffset(origOffset, int64(len(p)))
return len(p), nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"f",
".",
"readOnly",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"origOffset",
":=",
"atomic",
".",
"LoadInt64",
"(",
"&",
"f",
".",
"offset",
")",
"\n",
"err",
"=",
"f",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Write",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"node",
",",
"p",
",",
"origOffset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"f",
".",
"updateOffset",
"(",
"origOffset",
",",
"int64",
"(",
"len",
"(",
"p",
")",
")",
")",
"\n",
"return",
"len",
"(",
"p",
")",
",",
"nil",
"\n",
"}"
] | // Write implements the billy.File interface for File. | [
"Write",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L51-L64 |
158,802 | keybase/client | go/kbfs/libfs/file.go | Read | func (f *File) Read(p []byte) (n int, err error) {
origOffset := atomic.LoadInt64(&f.offset)
readBytes, err := f.fs.config.KBFSOps().Read(
f.fs.ctx, f.node, p, origOffset)
if err != nil {
return 0, err
}
if readBytes == 0 {
return 0, io.EOF
}
f.updateOffset(origOffset, readBytes)
return int(readBytes), nil
} | go | func (f *File) Read(p []byte) (n int, err error) {
origOffset := atomic.LoadInt64(&f.offset)
readBytes, err := f.fs.config.KBFSOps().Read(
f.fs.ctx, f.node, p, origOffset)
if err != nil {
return 0, err
}
if readBytes == 0 {
return 0, io.EOF
}
f.updateOffset(origOffset, readBytes)
return int(readBytes), nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"origOffset",
":=",
"atomic",
".",
"LoadInt64",
"(",
"&",
"f",
".",
"offset",
")",
"\n",
"readBytes",
",",
"err",
":=",
"f",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Read",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"node",
",",
"p",
",",
"origOffset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"readBytes",
"==",
"0",
"{",
"return",
"0",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n\n",
"f",
".",
"updateOffset",
"(",
"origOffset",
",",
"readBytes",
")",
"\n",
"return",
"int",
"(",
"readBytes",
")",
",",
"nil",
"\n",
"}"
] | // Read implements the billy.File interface for File. | [
"Read",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L67-L81 |
158,803 | keybase/client | go/kbfs/libfs/file.go | ReadAt | func (f *File) ReadAt(p []byte, off int64) (n int, err error) {
// ReadAt doesn't affect the underlying offset.
readBytes, err := f.fs.config.KBFSOps().Read(f.fs.ctx, f.node, p, off)
if err != nil {
return 0, err
}
if int(readBytes) < len(p) {
// ReadAt is more strict than Read.
return 0, errors.Errorf("Could only read %d bytes", readBytes)
}
return int(readBytes), nil
} | go | func (f *File) ReadAt(p []byte, off int64) (n int, err error) {
// ReadAt doesn't affect the underlying offset.
readBytes, err := f.fs.config.KBFSOps().Read(f.fs.ctx, f.node, p, off)
if err != nil {
return 0, err
}
if int(readBytes) < len(p) {
// ReadAt is more strict than Read.
return 0, errors.Errorf("Could only read %d bytes", readBytes)
}
return int(readBytes), nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"ReadAt",
"(",
"p",
"[",
"]",
"byte",
",",
"off",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"// ReadAt doesn't affect the underlying offset.",
"readBytes",
",",
"err",
":=",
"f",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Read",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"node",
",",
"p",
",",
"off",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"int",
"(",
"readBytes",
")",
"<",
"len",
"(",
"p",
")",
"{",
"// ReadAt is more strict than Read.",
"return",
"0",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"readBytes",
")",
"\n",
"}",
"\n\n",
"return",
"int",
"(",
"readBytes",
")",
",",
"nil",
"\n",
"}"
] | // ReadAt implements the billy.File interface for File. | [
"ReadAt",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L84-L96 |
158,804 | keybase/client | go/kbfs/libfs/file.go | Seek | func (f *File) Seek(offset int64, whence int) (n int64, err error) {
newOffset := offset
switch whence {
case io.SeekStart:
case io.SeekCurrent:
origOffset := atomic.LoadInt64(&f.offset)
newOffset = origOffset + offset
case io.SeekEnd:
ei, err := f.fs.config.KBFSOps().Stat(f.fs.ctx, f.node)
if err != nil {
return 0, err
}
newOffset = int64(ei.Size) + offset
}
if newOffset < 0 {
return 0, errors.Errorf("Cannot seek to offset %d", newOffset)
}
_ = atomic.SwapInt64(&f.offset, newOffset)
return newOffset, nil
} | go | func (f *File) Seek(offset int64, whence int) (n int64, err error) {
newOffset := offset
switch whence {
case io.SeekStart:
case io.SeekCurrent:
origOffset := atomic.LoadInt64(&f.offset)
newOffset = origOffset + offset
case io.SeekEnd:
ei, err := f.fs.config.KBFSOps().Stat(f.fs.ctx, f.node)
if err != nil {
return 0, err
}
newOffset = int64(ei.Size) + offset
}
if newOffset < 0 {
return 0, errors.Errorf("Cannot seek to offset %d", newOffset)
}
_ = atomic.SwapInt64(&f.offset, newOffset)
return newOffset, nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"n",
"int64",
",",
"err",
"error",
")",
"{",
"newOffset",
":=",
"offset",
"\n",
"switch",
"whence",
"{",
"case",
"io",
".",
"SeekStart",
":",
"case",
"io",
".",
"SeekCurrent",
":",
"origOffset",
":=",
"atomic",
".",
"LoadInt64",
"(",
"&",
"f",
".",
"offset",
")",
"\n",
"newOffset",
"=",
"origOffset",
"+",
"offset",
"\n",
"case",
"io",
".",
"SeekEnd",
":",
"ei",
",",
"err",
":=",
"f",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Stat",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"node",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"newOffset",
"=",
"int64",
"(",
"ei",
".",
"Size",
")",
"+",
"offset",
"\n",
"}",
"\n",
"if",
"newOffset",
"<",
"0",
"{",
"return",
"0",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"newOffset",
")",
"\n",
"}",
"\n\n",
"_",
"=",
"atomic",
".",
"SwapInt64",
"(",
"&",
"f",
".",
"offset",
",",
"newOffset",
")",
"\n",
"return",
"newOffset",
",",
"nil",
"\n",
"}"
] | // Seek implements the billy.File interface for File. | [
"Seek",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L99-L119 |
158,805 | keybase/client | go/kbfs/libfs/file.go | Close | func (f *File) Close() error {
err := f.Unlock()
if err != nil {
return err
}
f.node = nil
return nil
} | go | func (f *File) Close() error {
err := f.Unlock()
if err != nil {
return err
}
f.node = nil
return nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Close",
"(",
")",
"error",
"{",
"err",
":=",
"f",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"f",
".",
"node",
"=",
"nil",
"\n",
"return",
"nil",
"\n",
"}"
] | // Close implements the billy.File interface for File. | [
"Close",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L122-L129 |
158,806 | keybase/client | go/kbfs/libfs/file.go | Lock | func (f *File) Lock() (err error) {
done := make(chan struct{})
f.fs.sendEvents(FSEvent{
EventType: FSEventLock,
File: f,
Done: done,
})
defer close(done)
f.lockedLock.Lock()
defer f.lockedLock.Unlock()
if f.locked {
return nil
}
defer func() {
if err == nil {
f.locked = true
}
}()
// First, sync all and ask journal to flush all existing writes.
err = f.fs.SyncAll()
if err != nil {
return err
}
jManager, err := libkbfs.GetJournalManager(f.fs.config)
if err != nil {
return err
}
if err = jManager.FinishSingleOp(f.fs.ctx,
f.fs.root.GetFolderBranch().Tlf, nil, f.fs.priority); err != nil {
return err
}
// Now, sync up with the server, while making sure a lock is held by us. If
// lock taking fails, RPC layer retries automatically.
lockID := f.getLockID()
return f.fs.config.KBFSOps().SyncFromServer(f.fs.ctx,
f.fs.root.GetFolderBranch(), &lockID)
} | go | func (f *File) Lock() (err error) {
done := make(chan struct{})
f.fs.sendEvents(FSEvent{
EventType: FSEventLock,
File: f,
Done: done,
})
defer close(done)
f.lockedLock.Lock()
defer f.lockedLock.Unlock()
if f.locked {
return nil
}
defer func() {
if err == nil {
f.locked = true
}
}()
// First, sync all and ask journal to flush all existing writes.
err = f.fs.SyncAll()
if err != nil {
return err
}
jManager, err := libkbfs.GetJournalManager(f.fs.config)
if err != nil {
return err
}
if err = jManager.FinishSingleOp(f.fs.ctx,
f.fs.root.GetFolderBranch().Tlf, nil, f.fs.priority); err != nil {
return err
}
// Now, sync up with the server, while making sure a lock is held by us. If
// lock taking fails, RPC layer retries automatically.
lockID := f.getLockID()
return f.fs.config.KBFSOps().SyncFromServer(f.fs.ctx,
f.fs.root.GetFolderBranch(), &lockID)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Lock",
"(",
")",
"(",
"err",
"error",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"f",
".",
"fs",
".",
"sendEvents",
"(",
"FSEvent",
"{",
"EventType",
":",
"FSEventLock",
",",
"File",
":",
"f",
",",
"Done",
":",
"done",
",",
"}",
")",
"\n",
"defer",
"close",
"(",
"done",
")",
"\n",
"f",
".",
"lockedLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"lockedLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"f",
".",
"locked",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"f",
".",
"locked",
"=",
"true",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// First, sync all and ask journal to flush all existing writes.",
"err",
"=",
"f",
".",
"fs",
".",
"SyncAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"jManager",
",",
"err",
":=",
"libkbfs",
".",
"GetJournalManager",
"(",
"f",
".",
"fs",
".",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"jManager",
".",
"FinishSingleOp",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"fs",
".",
"root",
".",
"GetFolderBranch",
"(",
")",
".",
"Tlf",
",",
"nil",
",",
"f",
".",
"fs",
".",
"priority",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Now, sync up with the server, while making sure a lock is held by us. If",
"// lock taking fails, RPC layer retries automatically.",
"lockID",
":=",
"f",
".",
"getLockID",
"(",
")",
"\n",
"return",
"f",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"SyncFromServer",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"fs",
".",
"root",
".",
"GetFolderBranch",
"(",
")",
",",
"&",
"lockID",
")",
"\n",
"}"
] | // Lock implements the billy.File interface for File. | [
"Lock",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L142-L180 |
158,807 | keybase/client | go/kbfs/libfs/file.go | Unlock | func (f *File) Unlock() (err error) {
f.lockedLock.Lock()
defer f.lockedLock.Unlock()
if !f.locked {
return nil
}
// Send the event only if f.locked == true.
done := make(chan struct{})
f.fs.sendEvents(FSEvent{
EventType: FSEventUnlock,
File: f,
Done: done,
})
defer close(done)
defer func() {
if err == nil {
f.locked = false
}
}()
err = f.fs.SyncAll()
if err != nil {
return err
}
jManager, err := libkbfs.GetJournalManager(f.fs.config)
if err != nil {
return err
}
jStatus, _ := jManager.JournalStatus(f.fs.root.GetFolderBranch().Tlf)
if jStatus.RevisionStart == kbfsmd.RevisionUninitialized {
// Journal MDs are all flushed and we haven't made any more writes.
// Calling FinishSingleOp won't make it to the server, so we make a
// naked request to server just to release the lock.
return f.fs.config.MDServer().ReleaseLock(f.fs.ctx,
f.fs.root.GetFolderBranch().Tlf, f.getLockID())
}
if f.fs.config.Mode().Type() == libkbfs.InitSingleOp {
err = jManager.FinishSingleOp(f.fs.ctx,
f.fs.root.GetFolderBranch().Tlf, &keybase1.LockContext{
RequireLockID: f.getLockID(),
ReleaseAfterSuccess: true,
}, f.fs.priority)
if err != nil {
return err
}
} else {
err = jManager.WaitForCompleteFlush(
f.fs.ctx, f.fs.root.GetFolderBranch().Tlf)
if err != nil {
return err
}
f.fs.log.CDebugf(f.fs.ctx, "Releasing the lock")
// Need to explicitly release the lock from the server. If
// single-op mode isn't enabled, then the journal will be
// flushing on its own without waiting for the call to
// `FinishSingleOp`. That means the journal can already be
// completely flushed by the time `FinishSingleOp` is called,
// and it will be a no-op. It won't have made any call to the
// server to release the lock, so we have to do it explicitly
// here.
err = f.fs.config.MDServer().ReleaseLock(
f.fs.ctx, f.fs.root.GetFolderBranch().Tlf, f.getLockID())
if err != nil {
return err
}
}
return nil
} | go | func (f *File) Unlock() (err error) {
f.lockedLock.Lock()
defer f.lockedLock.Unlock()
if !f.locked {
return nil
}
// Send the event only if f.locked == true.
done := make(chan struct{})
f.fs.sendEvents(FSEvent{
EventType: FSEventUnlock,
File: f,
Done: done,
})
defer close(done)
defer func() {
if err == nil {
f.locked = false
}
}()
err = f.fs.SyncAll()
if err != nil {
return err
}
jManager, err := libkbfs.GetJournalManager(f.fs.config)
if err != nil {
return err
}
jStatus, _ := jManager.JournalStatus(f.fs.root.GetFolderBranch().Tlf)
if jStatus.RevisionStart == kbfsmd.RevisionUninitialized {
// Journal MDs are all flushed and we haven't made any more writes.
// Calling FinishSingleOp won't make it to the server, so we make a
// naked request to server just to release the lock.
return f.fs.config.MDServer().ReleaseLock(f.fs.ctx,
f.fs.root.GetFolderBranch().Tlf, f.getLockID())
}
if f.fs.config.Mode().Type() == libkbfs.InitSingleOp {
err = jManager.FinishSingleOp(f.fs.ctx,
f.fs.root.GetFolderBranch().Tlf, &keybase1.LockContext{
RequireLockID: f.getLockID(),
ReleaseAfterSuccess: true,
}, f.fs.priority)
if err != nil {
return err
}
} else {
err = jManager.WaitForCompleteFlush(
f.fs.ctx, f.fs.root.GetFolderBranch().Tlf)
if err != nil {
return err
}
f.fs.log.CDebugf(f.fs.ctx, "Releasing the lock")
// Need to explicitly release the lock from the server. If
// single-op mode isn't enabled, then the journal will be
// flushing on its own without waiting for the call to
// `FinishSingleOp`. That means the journal can already be
// completely flushed by the time `FinishSingleOp` is called,
// and it will be a no-op. It won't have made any call to the
// server to release the lock, so we have to do it explicitly
// here.
err = f.fs.config.MDServer().ReleaseLock(
f.fs.ctx, f.fs.root.GetFolderBranch().Tlf, f.getLockID())
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Unlock",
"(",
")",
"(",
"err",
"error",
")",
"{",
"f",
".",
"lockedLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"lockedLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"f",
".",
"locked",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Send the event only if f.locked == true.",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"f",
".",
"fs",
".",
"sendEvents",
"(",
"FSEvent",
"{",
"EventType",
":",
"FSEventUnlock",
",",
"File",
":",
"f",
",",
"Done",
":",
"done",
",",
"}",
")",
"\n",
"defer",
"close",
"(",
"done",
")",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"f",
".",
"locked",
"=",
"false",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"f",
".",
"fs",
".",
"SyncAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"jManager",
",",
"err",
":=",
"libkbfs",
".",
"GetJournalManager",
"(",
"f",
".",
"fs",
".",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"jStatus",
",",
"_",
":=",
"jManager",
".",
"JournalStatus",
"(",
"f",
".",
"fs",
".",
"root",
".",
"GetFolderBranch",
"(",
")",
".",
"Tlf",
")",
"\n",
"if",
"jStatus",
".",
"RevisionStart",
"==",
"kbfsmd",
".",
"RevisionUninitialized",
"{",
"// Journal MDs are all flushed and we haven't made any more writes.",
"// Calling FinishSingleOp won't make it to the server, so we make a",
"// naked request to server just to release the lock.",
"return",
"f",
".",
"fs",
".",
"config",
".",
"MDServer",
"(",
")",
".",
"ReleaseLock",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"fs",
".",
"root",
".",
"GetFolderBranch",
"(",
")",
".",
"Tlf",
",",
"f",
".",
"getLockID",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"f",
".",
"fs",
".",
"config",
".",
"Mode",
"(",
")",
".",
"Type",
"(",
")",
"==",
"libkbfs",
".",
"InitSingleOp",
"{",
"err",
"=",
"jManager",
".",
"FinishSingleOp",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"fs",
".",
"root",
".",
"GetFolderBranch",
"(",
")",
".",
"Tlf",
",",
"&",
"keybase1",
".",
"LockContext",
"{",
"RequireLockID",
":",
"f",
".",
"getLockID",
"(",
")",
",",
"ReleaseAfterSuccess",
":",
"true",
",",
"}",
",",
"f",
".",
"fs",
".",
"priority",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"err",
"=",
"jManager",
".",
"WaitForCompleteFlush",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"fs",
".",
"root",
".",
"GetFolderBranch",
"(",
")",
".",
"Tlf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"f",
".",
"fs",
".",
"log",
".",
"CDebugf",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"// Need to explicitly release the lock from the server. If",
"// single-op mode isn't enabled, then the journal will be",
"// flushing on its own without waiting for the call to",
"// `FinishSingleOp`. That means the journal can already be",
"// completely flushed by the time `FinishSingleOp` is called,",
"// and it will be a no-op. It won't have made any call to the",
"// server to release the lock, so we have to do it explicitly",
"// here.",
"err",
"=",
"f",
".",
"fs",
".",
"config",
".",
"MDServer",
"(",
")",
".",
"ReleaseLock",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"fs",
".",
"root",
".",
"GetFolderBranch",
"(",
")",
".",
"Tlf",
",",
"f",
".",
"getLockID",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Unlock implements the billy.File interface for File. | [
"Unlock",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L183-L255 |
158,808 | keybase/client | go/kbfs/libfs/file.go | Truncate | func (f *File) Truncate(size int64) error {
return f.fs.config.KBFSOps().Truncate(f.fs.ctx, f.node, uint64(size))
} | go | func (f *File) Truncate(size int64) error {
return f.fs.config.KBFSOps().Truncate(f.fs.ctx, f.node, uint64(size))
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Truncate",
"(",
"size",
"int64",
")",
"error",
"{",
"return",
"f",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Truncate",
"(",
"f",
".",
"fs",
".",
"ctx",
",",
"f",
".",
"node",
",",
"uint64",
"(",
"size",
")",
")",
"\n",
"}"
] | // Truncate implements the billy.File interface for File. | [
"Truncate",
"implements",
"the",
"billy",
".",
"File",
"interface",
"for",
"File",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/file.go#L258-L260 |
158,809 | keybase/client | go/libkb/id_table.go | ParseWebServiceBinding | func ParseWebServiceBinding(base GenericChainLink) (ret RemoteProofChainLink, err error) {
jw := base.UnmarshalPayloadJSON().AtKey("body").AtKey("service")
sptf := base.unpacked.proofText
if jw.IsNil() {
ret, err = ParseSelfSigChainLink(base)
if err != nil {
return nil, err
}
} else if sb, err := ParseServiceBlock(jw, keybase1.ProofType_NONE); err != nil {
err = fmt.Errorf("%s @%s", err, base.ToDebugString())
return nil, err
} else if sb.social {
ret = NewSocialProofChainLink(base, sb.typ, sb.id, sptf)
} else {
ret = NewWebProofChainLink(base, sb.typ, sb.id, sptf)
}
return ret, nil
} | go | func ParseWebServiceBinding(base GenericChainLink) (ret RemoteProofChainLink, err error) {
jw := base.UnmarshalPayloadJSON().AtKey("body").AtKey("service")
sptf := base.unpacked.proofText
if jw.IsNil() {
ret, err = ParseSelfSigChainLink(base)
if err != nil {
return nil, err
}
} else if sb, err := ParseServiceBlock(jw, keybase1.ProofType_NONE); err != nil {
err = fmt.Errorf("%s @%s", err, base.ToDebugString())
return nil, err
} else if sb.social {
ret = NewSocialProofChainLink(base, sb.typ, sb.id, sptf)
} else {
ret = NewWebProofChainLink(base, sb.typ, sb.id, sptf)
}
return ret, nil
} | [
"func",
"ParseWebServiceBinding",
"(",
"base",
"GenericChainLink",
")",
"(",
"ret",
"RemoteProofChainLink",
",",
"err",
"error",
")",
"{",
"jw",
":=",
"base",
".",
"UnmarshalPayloadJSON",
"(",
")",
".",
"AtKey",
"(",
"\"",
"\"",
")",
".",
"AtKey",
"(",
"\"",
"\"",
")",
"\n",
"sptf",
":=",
"base",
".",
"unpacked",
".",
"proofText",
"\n\n",
"if",
"jw",
".",
"IsNil",
"(",
")",
"{",
"ret",
",",
"err",
"=",
"ParseSelfSigChainLink",
"(",
"base",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"sb",
",",
"err",
":=",
"ParseServiceBlock",
"(",
"jw",
",",
"keybase1",
".",
"ProofType_NONE",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"base",
".",
"ToDebugString",
"(",
")",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"sb",
".",
"social",
"{",
"ret",
"=",
"NewSocialProofChainLink",
"(",
"base",
",",
"sb",
".",
"typ",
",",
"sb",
".",
"id",
",",
"sptf",
")",
"\n",
"}",
"else",
"{",
"ret",
"=",
"NewWebProofChainLink",
"(",
"base",
",",
"sb",
".",
"typ",
",",
"sb",
".",
"id",
",",
"sptf",
")",
"\n",
"}",
"\n\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // To be used for signatures in a user's signature chain. | [
"To",
"be",
"used",
"for",
"signatures",
"in",
"a",
"user",
"s",
"signature",
"chain",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/id_table.go#L389-L408 |
158,810 | keybase/client | go/libkb/id_table.go | ParsePGPUpdateChainLink | func ParsePGPUpdateChainLink(b GenericChainLink) (ret *PGPUpdateChainLink, err error) {
var kid keybase1.KID
pgpUpdate := b.UnmarshalPayloadJSON().AtPath("body.pgp_update")
if pgpUpdate.IsNil() {
err = ChainLinkError{fmt.Sprintf("missing pgp_update section @%s", b.ToDebugString())}
return
}
if kid, err = GetKID(pgpUpdate.AtKey("kid")); err != nil {
err = ChainLinkError{fmt.Sprintf("Missing kid @%s: %s", b.ToDebugString(), err)}
return
}
ret = &PGPUpdateChainLink{b, kid}
if fh := ret.GetPGPFullHash(); fh == "" {
err = ChainLinkError{fmt.Sprintf("Missing full_hash @%s", b.ToDebugString())}
ret = nil
return
}
return
} | go | func ParsePGPUpdateChainLink(b GenericChainLink) (ret *PGPUpdateChainLink, err error) {
var kid keybase1.KID
pgpUpdate := b.UnmarshalPayloadJSON().AtPath("body.pgp_update")
if pgpUpdate.IsNil() {
err = ChainLinkError{fmt.Sprintf("missing pgp_update section @%s", b.ToDebugString())}
return
}
if kid, err = GetKID(pgpUpdate.AtKey("kid")); err != nil {
err = ChainLinkError{fmt.Sprintf("Missing kid @%s: %s", b.ToDebugString(), err)}
return
}
ret = &PGPUpdateChainLink{b, kid}
if fh := ret.GetPGPFullHash(); fh == "" {
err = ChainLinkError{fmt.Sprintf("Missing full_hash @%s", b.ToDebugString())}
ret = nil
return
}
return
} | [
"func",
"ParsePGPUpdateChainLink",
"(",
"b",
"GenericChainLink",
")",
"(",
"ret",
"*",
"PGPUpdateChainLink",
",",
"err",
"error",
")",
"{",
"var",
"kid",
"keybase1",
".",
"KID",
"\n\n",
"pgpUpdate",
":=",
"b",
".",
"UnmarshalPayloadJSON",
"(",
")",
".",
"AtPath",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"pgpUpdate",
".",
"IsNil",
"(",
")",
"{",
"err",
"=",
"ChainLinkError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"ToDebugString",
"(",
")",
")",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"kid",
",",
"err",
"=",
"GetKID",
"(",
"pgpUpdate",
".",
"AtKey",
"(",
"\"",
"\"",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"ChainLinkError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"ToDebugString",
"(",
")",
",",
"err",
")",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"ret",
"=",
"&",
"PGPUpdateChainLink",
"{",
"b",
",",
"kid",
"}",
"\n\n",
"if",
"fh",
":=",
"ret",
".",
"GetPGPFullHash",
"(",
")",
";",
"fh",
"==",
"\"",
"\"",
"{",
"err",
"=",
"ChainLinkError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"ToDebugString",
"(",
")",
")",
"}",
"\n",
"ret",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // ParsePGPUpdateChainLink creates a PGPUpdateChainLink from a GenericChainLink
// and verifies that its pgp_update section contains a KID and full_hash | [
"ParsePGPUpdateChainLink",
"creates",
"a",
"PGPUpdateChainLink",
"from",
"a",
"GenericChainLink",
"and",
"verifies",
"that",
"its",
"pgp_update",
"section",
"contains",
"a",
"KID",
"and",
"full_hash"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/id_table.go#L845-L869 |
158,811 | keybase/client | go/libkb/id_table.go | VerifyReverseSig | func (s *WalletStellarChainLink) VerifyReverseSig(_ ComputedKeyFamily) (err error) {
key, err := ImportNaclSigningKeyPairFromHex(s.addressKID.String())
if err != nil {
return fmt.Errorf("Invalid wallet reverse signing KID: %s", s.addressKID)
}
return VerifyReverseSig(s.G(), key, "body.wallet_key.reverse_sig", s.UnmarshalPayloadJSON(), s.reverseSig)
} | go | func (s *WalletStellarChainLink) VerifyReverseSig(_ ComputedKeyFamily) (err error) {
key, err := ImportNaclSigningKeyPairFromHex(s.addressKID.String())
if err != nil {
return fmt.Errorf("Invalid wallet reverse signing KID: %s", s.addressKID)
}
return VerifyReverseSig(s.G(), key, "body.wallet_key.reverse_sig", s.UnmarshalPayloadJSON(), s.reverseSig)
} | [
"func",
"(",
"s",
"*",
"WalletStellarChainLink",
")",
"VerifyReverseSig",
"(",
"_",
"ComputedKeyFamily",
")",
"(",
"err",
"error",
")",
"{",
"key",
",",
"err",
":=",
"ImportNaclSigningKeyPairFromHex",
"(",
"s",
".",
"addressKID",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
".",
"addressKID",
")",
"\n",
"}",
"\n\n",
"return",
"VerifyReverseSig",
"(",
"s",
".",
"G",
"(",
")",
",",
"key",
",",
"\"",
"\"",
",",
"s",
".",
"UnmarshalPayloadJSON",
"(",
")",
",",
"s",
".",
"reverseSig",
")",
"\n",
"}"
] | // VerifyReverseSig checks a SibkeyChainLink's reverse signature using the ComputedKeyFamily provided. | [
"VerifyReverseSig",
"checks",
"a",
"SibkeyChainLink",
"s",
"reverse",
"signature",
"using",
"the",
"ComputedKeyFamily",
"provided",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/id_table.go#L971-L978 |
158,812 | keybase/client | go/libkb/id_table.go | VerifyReverseSig | func VerifyReverseSig(g *GlobalContext, key GenericKey, path string, payload *jsonw.Wrapper, reverseSig string) (err error) {
var p1, p2 []byte
if p1, _, err = key.VerifyStringAndExtract(g.Log, reverseSig); err != nil {
err = ReverseSigError{fmt.Sprintf("Failed to verify/extract sig: %s", err)}
return err
}
if p1, err = jsonw.Canonicalize(p1); err != nil {
err = ReverseSigError{fmt.Sprintf("Failed to canonicalize json: %s", err)}
return err
}
// Make a deep copy. It's dangerous to try to mutate this thing
// since other goroutines might be accessing it at the same time.
var jsonCopy *jsonw.Wrapper
if jsonCopy, err = makeDeepCopy(payload); err != nil {
err = ReverseSigError{fmt.Sprintf("Failed to copy payload json: %s", err)}
return err
}
jsonCopy.SetValueAtPath(path, jsonw.NewNil())
if p2, err = jsonCopy.Marshal(); err != nil {
err = ReverseSigError{fmt.Sprintf("Can't remarshal JSON statement: %s", err)}
return err
}
eq := FastByteArrayEq(p1, p2)
if !eq {
err = ReverseSigError{fmt.Sprintf("JSON mismatch: %s != %s",
string(p1), string(p2))}
return err
}
return nil
} | go | func VerifyReverseSig(g *GlobalContext, key GenericKey, path string, payload *jsonw.Wrapper, reverseSig string) (err error) {
var p1, p2 []byte
if p1, _, err = key.VerifyStringAndExtract(g.Log, reverseSig); err != nil {
err = ReverseSigError{fmt.Sprintf("Failed to verify/extract sig: %s", err)}
return err
}
if p1, err = jsonw.Canonicalize(p1); err != nil {
err = ReverseSigError{fmt.Sprintf("Failed to canonicalize json: %s", err)}
return err
}
// Make a deep copy. It's dangerous to try to mutate this thing
// since other goroutines might be accessing it at the same time.
var jsonCopy *jsonw.Wrapper
if jsonCopy, err = makeDeepCopy(payload); err != nil {
err = ReverseSigError{fmt.Sprintf("Failed to copy payload json: %s", err)}
return err
}
jsonCopy.SetValueAtPath(path, jsonw.NewNil())
if p2, err = jsonCopy.Marshal(); err != nil {
err = ReverseSigError{fmt.Sprintf("Can't remarshal JSON statement: %s", err)}
return err
}
eq := FastByteArrayEq(p1, p2)
if !eq {
err = ReverseSigError{fmt.Sprintf("JSON mismatch: %s != %s",
string(p1), string(p2))}
return err
}
return nil
} | [
"func",
"VerifyReverseSig",
"(",
"g",
"*",
"GlobalContext",
",",
"key",
"GenericKey",
",",
"path",
"string",
",",
"payload",
"*",
"jsonw",
".",
"Wrapper",
",",
"reverseSig",
"string",
")",
"(",
"err",
"error",
")",
"{",
"var",
"p1",
",",
"p2",
"[",
"]",
"byte",
"\n",
"if",
"p1",
",",
"_",
",",
"err",
"=",
"key",
".",
"VerifyStringAndExtract",
"(",
"g",
".",
"Log",
",",
"reverseSig",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"ReverseSigError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"p1",
",",
"err",
"=",
"jsonw",
".",
"Canonicalize",
"(",
"p1",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"ReverseSigError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Make a deep copy. It's dangerous to try to mutate this thing",
"// since other goroutines might be accessing it at the same time.",
"var",
"jsonCopy",
"*",
"jsonw",
".",
"Wrapper",
"\n",
"if",
"jsonCopy",
",",
"err",
"=",
"makeDeepCopy",
"(",
"payload",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"ReverseSigError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"jsonCopy",
".",
"SetValueAtPath",
"(",
"path",
",",
"jsonw",
".",
"NewNil",
"(",
")",
")",
"\n",
"if",
"p2",
",",
"err",
"=",
"jsonCopy",
".",
"Marshal",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"ReverseSigError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"eq",
":=",
"FastByteArrayEq",
"(",
"p1",
",",
"p2",
")",
"\n\n",
"if",
"!",
"eq",
"{",
"err",
"=",
"ReverseSigError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"string",
"(",
"p1",
")",
",",
"string",
"(",
"p2",
")",
")",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // VerifyReverseSig checks reverse signature using the key provided.
// does not modify `payload`.
// `path` is the path to the reverse sig spot to null before checking. | [
"VerifyReverseSig",
"checks",
"reverse",
"signature",
"using",
"the",
"key",
"provided",
".",
"does",
"not",
"modify",
"payload",
".",
"path",
"is",
"the",
"path",
"to",
"the",
"reverse",
"sig",
"spot",
"to",
"null",
"before",
"checking",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/id_table.go#L1729-L1763 |
158,813 | keybase/client | go/engine/identify2_with_uid.go | Run | func (e *Identify2WithUID) Run(m libkb.MetaContext) (err error) {
m = m.WithLogTag("ID2")
n := fmt.Sprintf("Identify2WithUID#Run(UID=%v, Assertion=%s)", e.arg.Uid, e.arg.UserAssertion)
defer m.TraceTimed(n, func() error { return err })()
m.Debug("| Full Arg: %+v", e.arg)
if e.arg.Uid.IsNil() {
return libkb.NoUIDError{}
}
// Only the first send matters, but we don't want to block the subsequent no-op
// sends. This code will break when we have more than 100 unblocking opportunities.
ch := make(chan error, 100)
e.resultCh = ch
go e.run(m)
err = <-ch
// Potentially reset the error based on the error and the calling context.
err = e.resetError(m, err)
return err
} | go | func (e *Identify2WithUID) Run(m libkb.MetaContext) (err error) {
m = m.WithLogTag("ID2")
n := fmt.Sprintf("Identify2WithUID#Run(UID=%v, Assertion=%s)", e.arg.Uid, e.arg.UserAssertion)
defer m.TraceTimed(n, func() error { return err })()
m.Debug("| Full Arg: %+v", e.arg)
if e.arg.Uid.IsNil() {
return libkb.NoUIDError{}
}
// Only the first send matters, but we don't want to block the subsequent no-op
// sends. This code will break when we have more than 100 unblocking opportunities.
ch := make(chan error, 100)
e.resultCh = ch
go e.run(m)
err = <-ch
// Potentially reset the error based on the error and the calling context.
err = e.resetError(m, err)
return err
} | [
"func",
"(",
"e",
"*",
"Identify2WithUID",
")",
"Run",
"(",
"m",
"libkb",
".",
"MetaContext",
")",
"(",
"err",
"error",
")",
"{",
"m",
"=",
"m",
".",
"WithLogTag",
"(",
"\"",
"\"",
")",
"\n\n",
"n",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"arg",
".",
"Uid",
",",
"e",
".",
"arg",
".",
"UserAssertion",
")",
"\n",
"defer",
"m",
".",
"TraceTimed",
"(",
"n",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"e",
".",
"arg",
")",
"\n\n",
"if",
"e",
".",
"arg",
".",
"Uid",
".",
"IsNil",
"(",
")",
"{",
"return",
"libkb",
".",
"NoUIDError",
"{",
"}",
"\n",
"}",
"\n\n",
"// Only the first send matters, but we don't want to block the subsequent no-op",
"// sends. This code will break when we have more than 100 unblocking opportunities.",
"ch",
":=",
"make",
"(",
"chan",
"error",
",",
"100",
")",
"\n\n",
"e",
".",
"resultCh",
"=",
"ch",
"\n",
"go",
"e",
".",
"run",
"(",
"m",
")",
"\n",
"err",
"=",
"<-",
"ch",
"\n\n",
"// Potentially reset the error based on the error and the calling context.",
"err",
"=",
"e",
".",
"resetError",
"(",
"m",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Run then engine | [
"Run",
"then",
"engine"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/identify2_with_uid.go#L321-L344 |
158,814 | keybase/client | go/engine/identify2_with_uid.go | CCLCheckCompleted | func (e *Identify2WithUID) CCLCheckCompleted(lcr *libkb.LinkCheckResult) {
e.remotesMutex.Lock()
defer e.remotesMutex.Unlock()
m := e.metaContext
m.Debug("+ CheckCompleted for %s", lcr.GetLink().ToIDString())
defer m.Debug("- CheckCompleted")
// Always add to remotesReceived list, so that we have a full ProofSet.
pf := libkb.RemoteProofChainLinkToProof(lcr.GetLink())
e.remotesReceived.Add(pf)
if !e.useRemoteAssertions() || e.useTracking {
m.Debug("| Not using remote assertions or is tracking")
return
}
if !e.remoteAssertion.HasFactor(pf) {
m.Debug("| Proof isn't needed in our remote-assertion early-out check: %v", pf)
return
}
if err := lcr.GetError(); err != nil {
m.Debug("| got error -> %v", err)
e.remotesError = err
}
// note(maxtaco): this is a little ugly in that it's O(n^2) where n is the number
// of identities in the assertion. But I can't imagine n > 3, so this is fine
// for now.
matched := e.remoteAssertion.MatchSet(*e.remotesReceived)
m.Debug("| matched -> %v", matched)
if matched {
e.remotesCompleted = true
}
if e.remotesError != nil || e.remotesCompleted {
m.Debug("| unblocking, with err = %v", e.remotesError)
e.unblock(m, false, e.remotesError)
}
} | go | func (e *Identify2WithUID) CCLCheckCompleted(lcr *libkb.LinkCheckResult) {
e.remotesMutex.Lock()
defer e.remotesMutex.Unlock()
m := e.metaContext
m.Debug("+ CheckCompleted for %s", lcr.GetLink().ToIDString())
defer m.Debug("- CheckCompleted")
// Always add to remotesReceived list, so that we have a full ProofSet.
pf := libkb.RemoteProofChainLinkToProof(lcr.GetLink())
e.remotesReceived.Add(pf)
if !e.useRemoteAssertions() || e.useTracking {
m.Debug("| Not using remote assertions or is tracking")
return
}
if !e.remoteAssertion.HasFactor(pf) {
m.Debug("| Proof isn't needed in our remote-assertion early-out check: %v", pf)
return
}
if err := lcr.GetError(); err != nil {
m.Debug("| got error -> %v", err)
e.remotesError = err
}
// note(maxtaco): this is a little ugly in that it's O(n^2) where n is the number
// of identities in the assertion. But I can't imagine n > 3, so this is fine
// for now.
matched := e.remoteAssertion.MatchSet(*e.remotesReceived)
m.Debug("| matched -> %v", matched)
if matched {
e.remotesCompleted = true
}
if e.remotesError != nil || e.remotesCompleted {
m.Debug("| unblocking, with err = %v", e.remotesError)
e.unblock(m, false, e.remotesError)
}
} | [
"func",
"(",
"e",
"*",
"Identify2WithUID",
")",
"CCLCheckCompleted",
"(",
"lcr",
"*",
"libkb",
".",
"LinkCheckResult",
")",
"{",
"e",
".",
"remotesMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"remotesMutex",
".",
"Unlock",
"(",
")",
"\n",
"m",
":=",
"e",
".",
"metaContext",
"\n\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"lcr",
".",
"GetLink",
"(",
")",
".",
"ToIDString",
"(",
")",
")",
"\n",
"defer",
"m",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// Always add to remotesReceived list, so that we have a full ProofSet.",
"pf",
":=",
"libkb",
".",
"RemoteProofChainLinkToProof",
"(",
"lcr",
".",
"GetLink",
"(",
")",
")",
"\n",
"e",
".",
"remotesReceived",
".",
"Add",
"(",
"pf",
")",
"\n\n",
"if",
"!",
"e",
".",
"useRemoteAssertions",
"(",
")",
"||",
"e",
".",
"useTracking",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"!",
"e",
".",
"remoteAssertion",
".",
"HasFactor",
"(",
"pf",
")",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"pf",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"lcr",
".",
"GetError",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"e",
".",
"remotesError",
"=",
"err",
"\n",
"}",
"\n\n",
"// note(maxtaco): this is a little ugly in that it's O(n^2) where n is the number",
"// of identities in the assertion. But I can't imagine n > 3, so this is fine",
"// for now.",
"matched",
":=",
"e",
".",
"remoteAssertion",
".",
"MatchSet",
"(",
"*",
"e",
".",
"remotesReceived",
")",
"\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"matched",
")",
"\n",
"if",
"matched",
"{",
"e",
".",
"remotesCompleted",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"remotesError",
"!=",
"nil",
"||",
"e",
".",
"remotesCompleted",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"e",
".",
"remotesError",
")",
"\n",
"e",
".",
"unblock",
"(",
"m",
",",
"false",
",",
"e",
".",
"remotesError",
")",
"\n",
"}",
"\n",
"}"
] | // CCLCheckCompleted is triggered whenever a remote proof check completes.
// We get these calls as a result of being a "CheckCompletedListener".
// When each result comes in, we check against our pool of needed remote
// assertions. If the set is complete, or if one that we need errors,
// we can unblock the caller. | [
"CCLCheckCompleted",
"is",
"triggered",
"whenever",
"a",
"remote",
"proof",
"check",
"completes",
".",
"We",
"get",
"these",
"calls",
"as",
"a",
"result",
"of",
"being",
"a",
"CheckCompletedListener",
".",
"When",
"each",
"result",
"comes",
"in",
"we",
"check",
"against",
"our",
"pool",
"of",
"needed",
"remote",
"assertions",
".",
"If",
"the",
"set",
"is",
"complete",
"or",
"if",
"one",
"that",
"we",
"need",
"errors",
"we",
"can",
"unblock",
"the",
"caller",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/identify2_with_uid.go#L648-L688 |
158,815 | keybase/client | go/kbhttp/srv.go | NewSrv | func NewSrv(log logger.Logger, listenerSource ListenerSource) *Srv {
return &Srv{
log: log,
listenerSource: listenerSource,
}
} | go | func NewSrv(log logger.Logger, listenerSource ListenerSource) *Srv {
return &Srv{
log: log,
listenerSource: listenerSource,
}
} | [
"func",
"NewSrv",
"(",
"log",
"logger",
".",
"Logger",
",",
"listenerSource",
"ListenerSource",
")",
"*",
"Srv",
"{",
"return",
"&",
"Srv",
"{",
"log",
":",
"log",
",",
"listenerSource",
":",
"listenerSource",
",",
"}",
"\n",
"}"
] | // NewSrv creates a new HTTP server with the given listener
// source. | [
"NewSrv",
"creates",
"a",
"new",
"HTTP",
"server",
"with",
"the",
"given",
"listener",
"source",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbhttp/srv.go#L103-L108 |
158,816 | keybase/client | go/kbhttp/srv.go | Start | func (h *Srv) Start() (err error) {
h.Lock()
defer h.Unlock()
if h.server != nil {
h.log.Debug("kbhttp.Srv: already running, not starting again")
// Just bail out of this if we are already running
return errAlreadyRunning
}
h.ServeMux = http.NewServeMux()
listener, address, err := h.listenerSource.GetListener()
if err != nil {
h.log.Debug("kbhttp.Srv: failed to get a listener: %s", err)
return err
}
h.server = &http.Server{
Addr: address,
Handler: h.ServeMux,
}
h.doneCh = make(chan struct{})
go func(server *http.Server, doneCh chan struct{}) {
h.log.Debug("kbhttp.Srv: server starting on: %s", address)
if err := server.Serve(listener); err != nil {
h.log.Debug("kbhttp.Srv: server died: %s", err)
}
close(doneCh)
}(h.server, h.doneCh)
return nil
} | go | func (h *Srv) Start() (err error) {
h.Lock()
defer h.Unlock()
if h.server != nil {
h.log.Debug("kbhttp.Srv: already running, not starting again")
// Just bail out of this if we are already running
return errAlreadyRunning
}
h.ServeMux = http.NewServeMux()
listener, address, err := h.listenerSource.GetListener()
if err != nil {
h.log.Debug("kbhttp.Srv: failed to get a listener: %s", err)
return err
}
h.server = &http.Server{
Addr: address,
Handler: h.ServeMux,
}
h.doneCh = make(chan struct{})
go func(server *http.Server, doneCh chan struct{}) {
h.log.Debug("kbhttp.Srv: server starting on: %s", address)
if err := server.Serve(listener); err != nil {
h.log.Debug("kbhttp.Srv: server died: %s", err)
}
close(doneCh)
}(h.server, h.doneCh)
return nil
} | [
"func",
"(",
"h",
"*",
"Srv",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"h",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"Unlock",
"(",
")",
"\n",
"if",
"h",
".",
"server",
"!=",
"nil",
"{",
"h",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// Just bail out of this if we are already running",
"return",
"errAlreadyRunning",
"\n",
"}",
"\n",
"h",
".",
"ServeMux",
"=",
"http",
".",
"NewServeMux",
"(",
")",
"\n",
"listener",
",",
"address",
",",
"err",
":=",
"h",
".",
"listenerSource",
".",
"GetListener",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"h",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"h",
".",
"server",
"=",
"&",
"http",
".",
"Server",
"{",
"Addr",
":",
"address",
",",
"Handler",
":",
"h",
".",
"ServeMux",
",",
"}",
"\n",
"h",
".",
"doneCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
"server",
"*",
"http",
".",
"Server",
",",
"doneCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"h",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"if",
"err",
":=",
"server",
".",
"Serve",
"(",
"listener",
")",
";",
"err",
"!=",
"nil",
"{",
"h",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"close",
"(",
"doneCh",
")",
"\n",
"}",
"(",
"h",
".",
"server",
",",
"h",
".",
"doneCh",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Start starts listening on the server's listener source. | [
"Start",
"starts",
"listening",
"on",
"the",
"server",
"s",
"listener",
"source",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbhttp/srv.go#L111-L138 |
158,817 | keybase/client | go/kbhttp/srv.go | Active | func (h *Srv) Active() bool {
h.Lock()
defer h.Unlock()
return h.server != nil
} | go | func (h *Srv) Active() bool {
h.Lock()
defer h.Unlock()
return h.server != nil
} | [
"func",
"(",
"h",
"*",
"Srv",
")",
"Active",
"(",
")",
"bool",
"{",
"h",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"Unlock",
"(",
")",
"\n",
"return",
"h",
".",
"server",
"!=",
"nil",
"\n",
"}"
] | // Active returns true if the server is active. | [
"Active",
"returns",
"true",
"if",
"the",
"server",
"is",
"active",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbhttp/srv.go#L141-L145 |
158,818 | keybase/client | go/kbhttp/srv.go | Addr | func (h *Srv) Addr() (string, error) {
h.Lock()
defer h.Unlock()
if h.server != nil {
return h.server.Addr, nil
}
return "", errors.New("server not running")
} | go | func (h *Srv) Addr() (string, error) {
h.Lock()
defer h.Unlock()
if h.server != nil {
return h.server.Addr, nil
}
return "", errors.New("server not running")
} | [
"func",
"(",
"h",
"*",
"Srv",
")",
"Addr",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"h",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"Unlock",
"(",
")",
"\n",
"if",
"h",
".",
"server",
"!=",
"nil",
"{",
"return",
"h",
".",
"server",
".",
"Addr",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Addr returns the server's address, if it's running. | [
"Addr",
"returns",
"the",
"server",
"s",
"address",
"if",
"it",
"s",
"running",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbhttp/srv.go#L148-L155 |
158,819 | keybase/client | go/kbhttp/srv.go | Stop | func (h *Srv) Stop() <-chan struct{} {
h.Lock()
defer h.Unlock()
if h.server != nil {
h.server.Close()
h.server = nil
return h.doneCh
}
doneCh := make(chan struct{})
close(doneCh)
return doneCh
} | go | func (h *Srv) Stop() <-chan struct{} {
h.Lock()
defer h.Unlock()
if h.server != nil {
h.server.Close()
h.server = nil
return h.doneCh
}
doneCh := make(chan struct{})
close(doneCh)
return doneCh
} | [
"func",
"(",
"h",
"*",
"Srv",
")",
"Stop",
"(",
")",
"<-",
"chan",
"struct",
"{",
"}",
"{",
"h",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"Unlock",
"(",
")",
"\n",
"if",
"h",
".",
"server",
"!=",
"nil",
"{",
"h",
".",
"server",
".",
"Close",
"(",
")",
"\n",
"h",
".",
"server",
"=",
"nil",
"\n",
"return",
"h",
".",
"doneCh",
"\n",
"}",
"\n",
"doneCh",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"close",
"(",
"doneCh",
")",
"\n",
"return",
"doneCh",
"\n",
"}"
] | // Stop stops listening on the server's listener source. | [
"Stop",
"stops",
"listening",
"on",
"the",
"server",
"s",
"listener",
"source",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbhttp/srv.go#L158-L169 |
158,820 | keybase/client | go/kbfs/libhttpserver/server.go | NewToken | func (s *Server) NewToken() (token string, err error) {
buf := make([]byte, tokenByteSize)
if _, err = rand.Read(buf); err != nil {
return "", err
}
token = hex.EncodeToString(buf)
s.tokens.Add(token, nil)
return token, nil
} | go | func (s *Server) NewToken() (token string, err error) {
buf := make([]byte, tokenByteSize)
if _, err = rand.Read(buf); err != nil {
return "", err
}
token = hex.EncodeToString(buf)
s.tokens.Add(token, nil)
return token, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"NewToken",
"(",
")",
"(",
"token",
"string",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"tokenByteSize",
")",
"\n",
"if",
"_",
",",
"err",
"=",
"rand",
".",
"Read",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"token",
"=",
"hex",
".",
"EncodeToString",
"(",
"buf",
")",
"\n",
"s",
".",
"tokens",
".",
"Add",
"(",
"token",
",",
"nil",
")",
"\n",
"return",
"token",
",",
"nil",
"\n",
"}"
] | // NewToken returns a new random token that a HTTP client can use to load
// content from the server. | [
"NewToken",
"returns",
"a",
"new",
"random",
"token",
"that",
"a",
"HTTP",
"client",
"can",
"use",
"to",
"load",
"content",
"from",
"the",
"server",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libhttpserver/server.go#L51-L59 |
158,821 | keybase/client | go/kbfs/libhttpserver/server.go | New | func New(appStateUpdater env.AppStateUpdater, config libkbfs.Config) (
s *Server, err error) {
logger := config.MakeLogger("HTTP")
s = &Server{
appStateUpdater: appStateUpdater,
config: config,
logger: logger,
}
if s.tokens, err = lru.New(tokenCacheSize); err != nil {
return nil, err
}
if s.fs, err = lru.New(fsCacheSize); err != nil {
return nil, err
}
if err = s.restart(); err != nil {
return nil, err
}
ctx, cancel := context.WithCancel(context.Background())
go s.monitorAppState(ctx)
s.cancel = cancel
libmime.Patch(additionalMimeTypes)
return s, nil
} | go | func New(appStateUpdater env.AppStateUpdater, config libkbfs.Config) (
s *Server, err error) {
logger := config.MakeLogger("HTTP")
s = &Server{
appStateUpdater: appStateUpdater,
config: config,
logger: logger,
}
if s.tokens, err = lru.New(tokenCacheSize); err != nil {
return nil, err
}
if s.fs, err = lru.New(fsCacheSize); err != nil {
return nil, err
}
if err = s.restart(); err != nil {
return nil, err
}
ctx, cancel := context.WithCancel(context.Background())
go s.monitorAppState(ctx)
s.cancel = cancel
libmime.Patch(additionalMimeTypes)
return s, nil
} | [
"func",
"New",
"(",
"appStateUpdater",
"env",
".",
"AppStateUpdater",
",",
"config",
"libkbfs",
".",
"Config",
")",
"(",
"s",
"*",
"Server",
",",
"err",
"error",
")",
"{",
"logger",
":=",
"config",
".",
"MakeLogger",
"(",
"\"",
"\"",
")",
"\n",
"s",
"=",
"&",
"Server",
"{",
"appStateUpdater",
":",
"appStateUpdater",
",",
"config",
":",
"config",
",",
"logger",
":",
"logger",
",",
"}",
"\n",
"if",
"s",
".",
"tokens",
",",
"err",
"=",
"lru",
".",
"New",
"(",
"tokenCacheSize",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"s",
".",
"fs",
",",
"err",
"=",
"lru",
".",
"New",
"(",
"fsCacheSize",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"s",
".",
"restart",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"go",
"s",
".",
"monitorAppState",
"(",
"ctx",
")",
"\n",
"s",
".",
"cancel",
"=",
"cancel",
"\n",
"libmime",
".",
"Patch",
"(",
"additionalMimeTypes",
")",
"\n",
"return",
"s",
",",
"nil",
"\n",
"}"
] | // New creates and starts a new server. | [
"New",
"creates",
"and",
"starts",
"a",
"new",
"server",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libhttpserver/server.go#L214-L236 |
158,822 | keybase/client | go/kbfs/libhttpserver/server.go | Address | func (s *Server) Address() (string, error) {
s.serverLock.RLock()
defer s.serverLock.RUnlock()
return s.server.Addr()
} | go | func (s *Server) Address() (string, error) {
s.serverLock.RLock()
defer s.serverLock.RUnlock()
return s.server.Addr()
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Address",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
".",
"serverLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"serverLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"s",
".",
"server",
".",
"Addr",
"(",
")",
"\n",
"}"
] | // Address returns the address that the server is listening on. | [
"Address",
"returns",
"the",
"address",
"that",
"the",
"server",
"is",
"listening",
"on",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libhttpserver/server.go#L239-L243 |
158,823 | keybase/client | go/kbfs/libhttpserver/server.go | Shutdown | func (s *Server) Shutdown() {
s.serverLock.Lock()
defer s.serverLock.Unlock()
s.server.Stop()
s.cancel()
} | go | func (s *Server) Shutdown() {
s.serverLock.Lock()
defer s.serverLock.Unlock()
s.server.Stop()
s.cancel()
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Shutdown",
"(",
")",
"{",
"s",
".",
"serverLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"serverLock",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"server",
".",
"Stop",
"(",
")",
"\n",
"s",
".",
"cancel",
"(",
")",
"\n",
"}"
] | // Shutdown shuts down the server. | [
"Shutdown",
"shuts",
"down",
"the",
"server",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libhttpserver/server.go#L246-L251 |
158,824 | keybase/client | go/engine/track.go | NewTrackEngine | func NewTrackEngine(g *libkb.GlobalContext, arg *TrackEngineArg) *TrackEngine {
return &TrackEngine{
arg: arg,
Contextified: libkb.NewContextified(g),
}
} | go | func NewTrackEngine(g *libkb.GlobalContext, arg *TrackEngineArg) *TrackEngine {
return &TrackEngine{
arg: arg,
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewTrackEngine",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"arg",
"*",
"TrackEngineArg",
")",
"*",
"TrackEngine",
"{",
"return",
"&",
"TrackEngine",
"{",
"arg",
":",
"arg",
",",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewTrackEngine creates a default TrackEngine for tracking theirName. | [
"NewTrackEngine",
"creates",
"a",
"default",
"TrackEngine",
"for",
"tracking",
"theirName",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/track.go#L29-L34 |
158,825 | keybase/client | go/kbfs/ioutil/os_wrap.go | OpenFile | func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
f, err := os.OpenFile(name, flag, perm)
if err != nil {
return nil, errors.Wrapf(err, "failed to open %q", name)
}
return f, nil
} | go | func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
f, err := os.OpenFile(name, flag, perm)
if err != nil {
return nil, errors.Wrapf(err, "failed to open %q", name)
}
return f, nil
} | [
"func",
"OpenFile",
"(",
"name",
"string",
",",
"flag",
"int",
",",
"perm",
"os",
".",
"FileMode",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"name",
",",
"flag",
",",
"perm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] | // OpenFile wraps OpenFile from "os". | [
"OpenFile",
"wraps",
"OpenFile",
"from",
"os",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/ioutil/os_wrap.go#L14-L21 |
158,826 | keybase/client | go/kbfs/ioutil/os_wrap.go | Mkdir | func Mkdir(path string, perm os.FileMode) error {
err := os.MkdirAll(path, perm)
if err != nil {
return errors.Wrapf(err, "failed to mkdir %q", path)
}
return nil
} | go | func Mkdir(path string, perm os.FileMode) error {
err := os.MkdirAll(path, perm)
if err != nil {
return errors.Wrapf(err, "failed to mkdir %q", path)
}
return nil
} | [
"func",
"Mkdir",
"(",
"path",
"string",
",",
"perm",
"os",
".",
"FileMode",
")",
"error",
"{",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"path",
",",
"perm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Mkdir wraps MkdirAll from "os". | [
"Mkdir",
"wraps",
"MkdirAll",
"from",
"os",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/ioutil/os_wrap.go#L34-L41 |
158,827 | keybase/client | go/kbfs/ioutil/os_wrap.go | MkdirAll | func MkdirAll(path string, perm os.FileMode) error {
twoAttempts := false
err := os.MkdirAll(path, perm)
// KBFS-3245: Simple workaround for test flake where a directory
// seems to disappear out from under us.
if os.IsNotExist(err) {
twoAttempts = true
err = os.MkdirAll(path, perm)
}
if err != nil {
return errors.Wrapf(err,
"failed to mkdir (all) %q, twoAttempts=%t", path, twoAttempts)
}
return nil
} | go | func MkdirAll(path string, perm os.FileMode) error {
twoAttempts := false
err := os.MkdirAll(path, perm)
// KBFS-3245: Simple workaround for test flake where a directory
// seems to disappear out from under us.
if os.IsNotExist(err) {
twoAttempts = true
err = os.MkdirAll(path, perm)
}
if err != nil {
return errors.Wrapf(err,
"failed to mkdir (all) %q, twoAttempts=%t", path, twoAttempts)
}
return nil
} | [
"func",
"MkdirAll",
"(",
"path",
"string",
",",
"perm",
"os",
".",
"FileMode",
")",
"error",
"{",
"twoAttempts",
":=",
"false",
"\n",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"path",
",",
"perm",
")",
"\n",
"// KBFS-3245: Simple workaround for test flake where a directory",
"// seems to disappear out from under us.",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"twoAttempts",
"=",
"true",
"\n",
"err",
"=",
"os",
".",
"MkdirAll",
"(",
"path",
",",
"perm",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"path",
",",
"twoAttempts",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // MkdirAll wraps MkdirAll from "os". | [
"MkdirAll",
"wraps",
"MkdirAll",
"from",
"os",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/ioutil/os_wrap.go#L44-L59 |
158,828 | keybase/client | go/kbfs/ioutil/os_wrap.go | Stat | func Stat(name string) (os.FileInfo, error) {
info, err := os.Stat(name)
if err != nil {
return nil, errors.Wrapf(err, "failed to stat %q", name)
}
return info, nil
} | go | func Stat(name string) (os.FileInfo, error) {
info, err := os.Stat(name)
if err != nil {
return nil, errors.Wrapf(err, "failed to stat %q", name)
}
return info, nil
} | [
"func",
"Stat",
"(",
"name",
"string",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"return",
"info",
",",
"nil",
"\n",
"}"
] | // Stat wraps Stat from "os". | [
"Stat",
"wraps",
"Stat",
"from",
"os",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/ioutil/os_wrap.go#L62-L69 |
158,829 | keybase/client | go/kbfs/ioutil/os_wrap.go | Remove | func Remove(name string) error {
err := os.Remove(name)
if err != nil {
return errors.Wrapf(err, "failed to remove %q", name)
}
return nil
} | go | func Remove(name string) error {
err := os.Remove(name)
if err != nil {
return errors.Wrapf(err, "failed to remove %q", name)
}
return nil
} | [
"func",
"Remove",
"(",
"name",
"string",
")",
"error",
"{",
"err",
":=",
"os",
".",
"Remove",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Remove wraps Remove from "os". | [
"Remove",
"wraps",
"Remove",
"from",
"os",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/ioutil/os_wrap.go#L72-L79 |
158,830 | keybase/client | go/kbfs/ioutil/os_wrap.go | Rename | func Rename(oldpath, newpath string) error {
err := os.Rename(oldpath, newpath)
if err != nil {
return errors.Wrapf(
err, "failed to rename %q to %q", oldpath, newpath)
}
return nil
} | go | func Rename(oldpath, newpath string) error {
err := os.Rename(oldpath, newpath)
if err != nil {
return errors.Wrapf(
err, "failed to rename %q to %q", oldpath, newpath)
}
return nil
} | [
"func",
"Rename",
"(",
"oldpath",
",",
"newpath",
"string",
")",
"error",
"{",
"err",
":=",
"os",
".",
"Rename",
"(",
"oldpath",
",",
"newpath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"oldpath",
",",
"newpath",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Rename wraps Rename from "os". | [
"Rename",
"wraps",
"Rename",
"from",
"os",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/ioutil/os_wrap.go#L92-L100 |
158,831 | keybase/client | go/libkb/keyfamily.go | Insert | func (cki *ComputedKeyInfos) Insert(i *ComputedKeyInfo) {
cki.Infos[i.KID] = i
cki.dirty = true
} | go | func (cki *ComputedKeyInfos) Insert(i *ComputedKeyInfo) {
cki.Infos[i.KID] = i
cki.dirty = true
} | [
"func",
"(",
"cki",
"*",
"ComputedKeyInfos",
")",
"Insert",
"(",
"i",
"*",
"ComputedKeyInfo",
")",
"{",
"cki",
".",
"Infos",
"[",
"i",
".",
"KID",
"]",
"=",
"i",
"\n",
"cki",
".",
"dirty",
"=",
"true",
"\n",
"}"
] | // Insert inserts the given ComputedKeyInfo object 1 or 2 times,
// depending on if a KID or PGPFingerprint or both are available. | [
"Insert",
"inserts",
"the",
"given",
"ComputedKeyInfo",
"object",
"1",
"or",
"2",
"times",
"depending",
"on",
"if",
"a",
"KID",
"or",
"PGPFingerprint",
"or",
"both",
"are",
"available",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L216-L219 |
158,832 | keybase/client | go/libkb/keyfamily.go | PaperDevices | func (cki *ComputedKeyInfos) PaperDevices() []*Device {
var d []*Device
for _, v := range cki.Devices {
if v.Status == nil {
continue
}
if *v.Status != DeviceStatusActive {
continue
}
if v.Type != DeviceTypePaper {
continue
}
d = append(d, v)
}
return d
} | go | func (cki *ComputedKeyInfos) PaperDevices() []*Device {
var d []*Device
for _, v := range cki.Devices {
if v.Status == nil {
continue
}
if *v.Status != DeviceStatusActive {
continue
}
if v.Type != DeviceTypePaper {
continue
}
d = append(d, v)
}
return d
} | [
"func",
"(",
"cki",
"*",
"ComputedKeyInfos",
")",
"PaperDevices",
"(",
")",
"[",
"]",
"*",
"Device",
"{",
"var",
"d",
"[",
"]",
"*",
"Device",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"cki",
".",
"Devices",
"{",
"if",
"v",
".",
"Status",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"*",
"v",
".",
"Status",
"!=",
"DeviceStatusActive",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"v",
".",
"Type",
"!=",
"DeviceTypePaper",
"{",
"continue",
"\n",
"}",
"\n",
"d",
"=",
"append",
"(",
"d",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"d",
"\n",
"}"
] | // PaperDevices returns a list of all the paperkey devices. | [
"PaperDevices",
"returns",
"a",
"list",
"of",
"all",
"the",
"paperkey",
"devices",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L222-L237 |
158,833 | keybase/client | go/libkb/keyfamily.go | InsertServerEldestKey | func (cki ComputedKeyInfos) InsertServerEldestKey(eldestKey GenericKey, un NormalizedUsername) error {
kbid := KeybaseIdentity(cki.G(), un)
if pgp, ok := eldestKey.(*PGPKeyBundle); ok {
// In the future, we might choose to ignore this etime, as we do in
// InsertEldestLink below. When we do make that change, be certain
// to update the comment in PGPKeyBundle#CheckIdentity to reflect it.
// For now, we continue to honor the [email protected] etime in the case
// there's no sigchain link over the key to specify a different etime.
match, ctime, etime := pgp.CheckIdentity(kbid)
etime = cki.G().HonorPGPExpireTime(etime)
if match {
kid := eldestKey.GetKID()
eldestCki := NewComputedKeyInfo(kid, true, true, KeyUncancelled, ctime, etime, "" /* activePGPHash */)
cki.Insert(&eldestCki)
return nil
}
return KeyFamilyError{"InsertServerEldestKey found a non-matching eldest key."}
}
return KeyFamilyError{"InsertServerEldestKey found a non-PGP key."}
} | go | func (cki ComputedKeyInfos) InsertServerEldestKey(eldestKey GenericKey, un NormalizedUsername) error {
kbid := KeybaseIdentity(cki.G(), un)
if pgp, ok := eldestKey.(*PGPKeyBundle); ok {
// In the future, we might choose to ignore this etime, as we do in
// InsertEldestLink below. When we do make that change, be certain
// to update the comment in PGPKeyBundle#CheckIdentity to reflect it.
// For now, we continue to honor the [email protected] etime in the case
// there's no sigchain link over the key to specify a different etime.
match, ctime, etime := pgp.CheckIdentity(kbid)
etime = cki.G().HonorPGPExpireTime(etime)
if match {
kid := eldestKey.GetKID()
eldestCki := NewComputedKeyInfo(kid, true, true, KeyUncancelled, ctime, etime, "" /* activePGPHash */)
cki.Insert(&eldestCki)
return nil
}
return KeyFamilyError{"InsertServerEldestKey found a non-matching eldest key."}
}
return KeyFamilyError{"InsertServerEldestKey found a non-PGP key."}
} | [
"func",
"(",
"cki",
"ComputedKeyInfos",
")",
"InsertServerEldestKey",
"(",
"eldestKey",
"GenericKey",
",",
"un",
"NormalizedUsername",
")",
"error",
"{",
"kbid",
":=",
"KeybaseIdentity",
"(",
"cki",
".",
"G",
"(",
")",
",",
"un",
")",
"\n",
"if",
"pgp",
",",
"ok",
":=",
"eldestKey",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"ok",
"{",
"// In the future, we might choose to ignore this etime, as we do in",
"// InsertEldestLink below. When we do make that change, be certain",
"// to update the comment in PGPKeyBundle#CheckIdentity to reflect it.",
"// For now, we continue to honor the [email protected] etime in the case",
"// there's no sigchain link over the key to specify a different etime.",
"match",
",",
"ctime",
",",
"etime",
":=",
"pgp",
".",
"CheckIdentity",
"(",
"kbid",
")",
"\n",
"etime",
"=",
"cki",
".",
"G",
"(",
")",
".",
"HonorPGPExpireTime",
"(",
"etime",
")",
"\n",
"if",
"match",
"{",
"kid",
":=",
"eldestKey",
".",
"GetKID",
"(",
")",
"\n",
"eldestCki",
":=",
"NewComputedKeyInfo",
"(",
"kid",
",",
"true",
",",
"true",
",",
"KeyUncancelled",
",",
"ctime",
",",
"etime",
",",
"\"",
"\"",
"/* activePGPHash */",
")",
"\n",
"cki",
".",
"Insert",
"(",
"&",
"eldestCki",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"KeyFamilyError",
"{",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"return",
"KeyFamilyError",
"{",
"\"",
"\"",
"}",
"\n",
"}"
] | // For use when there are no chain links at all, so all we can do is trust the
// eldest key that the server reported. | [
"For",
"use",
"when",
"there",
"are",
"no",
"chain",
"links",
"at",
"all",
"so",
"all",
"we",
"can",
"do",
"is",
"trust",
"the",
"eldest",
"key",
"that",
"the",
"server",
"reported",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L355-L375 |
158,834 | keybase/client | go/libkb/keyfamily.go | ParseKeyFamily | func ParseKeyFamily(g *GlobalContext, jw *jsonw.Wrapper) (ret *KeyFamily, err error) {
defer g.Trace("ParseKeyFamily", func() error { return err })()
if jw == nil || jw.IsNil() {
err = KeyFamilyError{"nil record from server"}
return
}
kf := KeyFamily{
Contextified: NewContextified(g),
pgp2kid: make(map[PGPFingerprint]keybase1.KID),
kid2pgp: make(map[keybase1.KID]PGPFingerprint),
}
// Fill in AllKeys. Somewhat wasteful but probably faster than
// using Jsonw wrappers, and less error-prone.
var rkf RawKeyFamily
if err = jw.UnmarshalAgain(&rkf); err != nil {
return
}
kf.BundlesForTesting = rkf.AllBundles
// Parse the keys, and collect the PGP keys to map their fingerprints.
kf.AllKIDs = make(map[keybase1.KID]bool)
kf.PGPKeySets = make(map[keybase1.KID]*PGPKeySet)
kf.SingleKeys = make(map[keybase1.KID]GenericKey)
for i, bundle := range rkf.AllBundles {
newKey, w, err := ParseGenericKey(bundle)
// Some users have some historical bad keys, so no reason to crap
// out if we can't parse them, especially if there are others than
// can do just as well.
if err != nil {
g.Log.Notice("Failed to parse public key at position %d", i)
g.Log.Debug("Key parsing error: %s", err)
g.Log.Debug("Full key dump follows")
g.Log.Debug(bundle)
continue
}
w.Warn(g)
kid := newKey.GetKID()
if pgp, isPGP := newKey.(*PGPKeyBundle); isPGP {
ks, ok := kf.PGPKeySets[kid]
if !ok {
ks = &PGPKeySet{NewContextified(g), nil, make(map[string]*PGPKeyBundle)}
kf.PGPKeySets[kid] = ks
fp := pgp.GetFingerprint()
kf.pgp2kid[fp] = kid
kf.kid2pgp[kid] = fp
}
ks.addKey(pgp)
} else {
kf.SingleKeys[kid] = newKey
}
kf.AllKIDs[kid] = true
}
ret = &kf
return
} | go | func ParseKeyFamily(g *GlobalContext, jw *jsonw.Wrapper) (ret *KeyFamily, err error) {
defer g.Trace("ParseKeyFamily", func() error { return err })()
if jw == nil || jw.IsNil() {
err = KeyFamilyError{"nil record from server"}
return
}
kf := KeyFamily{
Contextified: NewContextified(g),
pgp2kid: make(map[PGPFingerprint]keybase1.KID),
kid2pgp: make(map[keybase1.KID]PGPFingerprint),
}
// Fill in AllKeys. Somewhat wasteful but probably faster than
// using Jsonw wrappers, and less error-prone.
var rkf RawKeyFamily
if err = jw.UnmarshalAgain(&rkf); err != nil {
return
}
kf.BundlesForTesting = rkf.AllBundles
// Parse the keys, and collect the PGP keys to map their fingerprints.
kf.AllKIDs = make(map[keybase1.KID]bool)
kf.PGPKeySets = make(map[keybase1.KID]*PGPKeySet)
kf.SingleKeys = make(map[keybase1.KID]GenericKey)
for i, bundle := range rkf.AllBundles {
newKey, w, err := ParseGenericKey(bundle)
// Some users have some historical bad keys, so no reason to crap
// out if we can't parse them, especially if there are others than
// can do just as well.
if err != nil {
g.Log.Notice("Failed to parse public key at position %d", i)
g.Log.Debug("Key parsing error: %s", err)
g.Log.Debug("Full key dump follows")
g.Log.Debug(bundle)
continue
}
w.Warn(g)
kid := newKey.GetKID()
if pgp, isPGP := newKey.(*PGPKeyBundle); isPGP {
ks, ok := kf.PGPKeySets[kid]
if !ok {
ks = &PGPKeySet{NewContextified(g), nil, make(map[string]*PGPKeyBundle)}
kf.PGPKeySets[kid] = ks
fp := pgp.GetFingerprint()
kf.pgp2kid[fp] = kid
kf.kid2pgp[kid] = fp
}
ks.addKey(pgp)
} else {
kf.SingleKeys[kid] = newKey
}
kf.AllKIDs[kid] = true
}
ret = &kf
return
} | [
"func",
"ParseKeyFamily",
"(",
"g",
"*",
"GlobalContext",
",",
"jw",
"*",
"jsonw",
".",
"Wrapper",
")",
"(",
"ret",
"*",
"KeyFamily",
",",
"err",
"error",
")",
"{",
"defer",
"g",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n\n",
"if",
"jw",
"==",
"nil",
"||",
"jw",
".",
"IsNil",
"(",
")",
"{",
"err",
"=",
"KeyFamilyError",
"{",
"\"",
"\"",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"kf",
":=",
"KeyFamily",
"{",
"Contextified",
":",
"NewContextified",
"(",
"g",
")",
",",
"pgp2kid",
":",
"make",
"(",
"map",
"[",
"PGPFingerprint",
"]",
"keybase1",
".",
"KID",
")",
",",
"kid2pgp",
":",
"make",
"(",
"map",
"[",
"keybase1",
".",
"KID",
"]",
"PGPFingerprint",
")",
",",
"}",
"\n\n",
"// Fill in AllKeys. Somewhat wasteful but probably faster than",
"// using Jsonw wrappers, and less error-prone.",
"var",
"rkf",
"RawKeyFamily",
"\n",
"if",
"err",
"=",
"jw",
".",
"UnmarshalAgain",
"(",
"&",
"rkf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"kf",
".",
"BundlesForTesting",
"=",
"rkf",
".",
"AllBundles",
"\n\n",
"// Parse the keys, and collect the PGP keys to map their fingerprints.",
"kf",
".",
"AllKIDs",
"=",
"make",
"(",
"map",
"[",
"keybase1",
".",
"KID",
"]",
"bool",
")",
"\n",
"kf",
".",
"PGPKeySets",
"=",
"make",
"(",
"map",
"[",
"keybase1",
".",
"KID",
"]",
"*",
"PGPKeySet",
")",
"\n",
"kf",
".",
"SingleKeys",
"=",
"make",
"(",
"map",
"[",
"keybase1",
".",
"KID",
"]",
"GenericKey",
")",
"\n",
"for",
"i",
",",
"bundle",
":=",
"range",
"rkf",
".",
"AllBundles",
"{",
"newKey",
",",
"w",
",",
"err",
":=",
"ParseGenericKey",
"(",
"bundle",
")",
"\n\n",
"// Some users have some historical bad keys, so no reason to crap",
"// out if we can't parse them, especially if there are others than",
"// can do just as well.",
"if",
"err",
"!=",
"nil",
"{",
"g",
".",
"Log",
".",
"Notice",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"g",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"g",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"g",
".",
"Log",
".",
"Debug",
"(",
"bundle",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"w",
".",
"Warn",
"(",
"g",
")",
"\n\n",
"kid",
":=",
"newKey",
".",
"GetKID",
"(",
")",
"\n\n",
"if",
"pgp",
",",
"isPGP",
":=",
"newKey",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"isPGP",
"{",
"ks",
",",
"ok",
":=",
"kf",
".",
"PGPKeySets",
"[",
"kid",
"]",
"\n",
"if",
"!",
"ok",
"{",
"ks",
"=",
"&",
"PGPKeySet",
"{",
"NewContextified",
"(",
"g",
")",
",",
"nil",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"PGPKeyBundle",
")",
"}",
"\n",
"kf",
".",
"PGPKeySets",
"[",
"kid",
"]",
"=",
"ks",
"\n\n",
"fp",
":=",
"pgp",
".",
"GetFingerprint",
"(",
")",
"\n",
"kf",
".",
"pgp2kid",
"[",
"fp",
"]",
"=",
"kid",
"\n",
"kf",
".",
"kid2pgp",
"[",
"kid",
"]",
"=",
"fp",
"\n",
"}",
"\n",
"ks",
".",
"addKey",
"(",
"pgp",
")",
"\n",
"}",
"else",
"{",
"kf",
".",
"SingleKeys",
"[",
"kid",
"]",
"=",
"newKey",
"\n",
"}",
"\n",
"kf",
".",
"AllKIDs",
"[",
"kid",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"ret",
"=",
"&",
"kf",
"\n",
"return",
"\n",
"}"
] | // ParseKeyFamily takes as input a dictionary from a JSON file and returns
// a parsed version for manipulation in the program. | [
"ParseKeyFamily",
"takes",
"as",
"input",
"a",
"dictionary",
"from",
"a",
"JSON",
"file",
"and",
"returns",
"a",
"parsed",
"version",
"for",
"manipulation",
"in",
"the",
"program",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L419-L481 |
158,835 | keybase/client | go/libkb/keyfamily.go | FindActiveSibkeyAtTime | func (ckf ComputedKeyFamily) FindActiveSibkeyAtTime(kid keybase1.KID, t time.Time) (key GenericKey, cki ComputedKeyInfo, err error) {
liveCki, err := ckf.getCkiIfActiveAtTime(kid, t)
if liveCki == nil || err != nil {
// err gets returned.
} else if !liveCki.Sibkey {
err = kbcrypto.BadKeyError{Msg: fmt.Sprintf("The key '%s' wasn't delegated as a sibkey", kid)}
} else {
key, err = ckf.FindKeyWithKIDUnsafe(kid)
cki = *liveCki
}
return
} | go | func (ckf ComputedKeyFamily) FindActiveSibkeyAtTime(kid keybase1.KID, t time.Time) (key GenericKey, cki ComputedKeyInfo, err error) {
liveCki, err := ckf.getCkiIfActiveAtTime(kid, t)
if liveCki == nil || err != nil {
// err gets returned.
} else if !liveCki.Sibkey {
err = kbcrypto.BadKeyError{Msg: fmt.Sprintf("The key '%s' wasn't delegated as a sibkey", kid)}
} else {
key, err = ckf.FindKeyWithKIDUnsafe(kid)
cki = *liveCki
}
return
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"FindActiveSibkeyAtTime",
"(",
"kid",
"keybase1",
".",
"KID",
",",
"t",
"time",
".",
"Time",
")",
"(",
"key",
"GenericKey",
",",
"cki",
"ComputedKeyInfo",
",",
"err",
"error",
")",
"{",
"liveCki",
",",
"err",
":=",
"ckf",
".",
"getCkiIfActiveAtTime",
"(",
"kid",
",",
"t",
")",
"\n",
"if",
"liveCki",
"==",
"nil",
"||",
"err",
"!=",
"nil",
"{",
"// err gets returned.",
"}",
"else",
"if",
"!",
"liveCki",
".",
"Sibkey",
"{",
"err",
"=",
"kbcrypto",
".",
"BadKeyError",
"{",
"Msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"kid",
")",
"}",
"\n",
"}",
"else",
"{",
"key",
",",
"err",
"=",
"ckf",
".",
"FindKeyWithKIDUnsafe",
"(",
"kid",
")",
"\n",
"cki",
"=",
"*",
"liveCki",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // As FindActiveSibkey, but for a specific time. Note that going back in time
// only affects expiration, not revocation. Thus this function is mainly useful
// for validating the sigchain, when each delegation and revocation is getting
// replayed in order. | [
"As",
"FindActiveSibkey",
"but",
"for",
"a",
"specific",
"time",
".",
"Note",
"that",
"going",
"back",
"in",
"time",
"only",
"affects",
"expiration",
"not",
"revocation",
".",
"Thus",
"this",
"function",
"is",
"mainly",
"useful",
"for",
"validating",
"the",
"sigchain",
"when",
"each",
"delegation",
"and",
"revocation",
"is",
"getting",
"replayed",
"in",
"order",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L541-L552 |
158,836 | keybase/client | go/libkb/keyfamily.go | FindActiveEncryptionSubkey | func (ckf ComputedKeyFamily) FindActiveEncryptionSubkey(kid keybase1.KID) (ret GenericKey, cki ComputedKeyInfo, err error) {
ckip, err := ckf.getCkiIfActiveNow(kid)
if err != nil {
return nil, cki, err
}
if ckip.Sibkey {
return nil, cki, kbcrypto.BadKeyError{Msg: fmt.Sprintf("The key '%s' was delegated as a sibkey", kid.String())}
}
key, err := ckf.FindKeyWithKIDUnsafe(kid)
if err != nil {
return nil, cki, err
}
if !CanEncrypt(key) {
return nil, cki, kbcrypto.BadKeyError{Msg: fmt.Sprintf("The key '%s' cannot encrypt", kid.String())}
}
return key, *ckip, nil
} | go | func (ckf ComputedKeyFamily) FindActiveEncryptionSubkey(kid keybase1.KID) (ret GenericKey, cki ComputedKeyInfo, err error) {
ckip, err := ckf.getCkiIfActiveNow(kid)
if err != nil {
return nil, cki, err
}
if ckip.Sibkey {
return nil, cki, kbcrypto.BadKeyError{Msg: fmt.Sprintf("The key '%s' was delegated as a sibkey", kid.String())}
}
key, err := ckf.FindKeyWithKIDUnsafe(kid)
if err != nil {
return nil, cki, err
}
if !CanEncrypt(key) {
return nil, cki, kbcrypto.BadKeyError{Msg: fmt.Sprintf("The key '%s' cannot encrypt", kid.String())}
}
return key, *ckip, nil
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"FindActiveEncryptionSubkey",
"(",
"kid",
"keybase1",
".",
"KID",
")",
"(",
"ret",
"GenericKey",
",",
"cki",
"ComputedKeyInfo",
",",
"err",
"error",
")",
"{",
"ckip",
",",
"err",
":=",
"ckf",
".",
"getCkiIfActiveNow",
"(",
"kid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cki",
",",
"err",
"\n",
"}",
"\n",
"if",
"ckip",
".",
"Sibkey",
"{",
"return",
"nil",
",",
"cki",
",",
"kbcrypto",
".",
"BadKeyError",
"{",
"Msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"kid",
".",
"String",
"(",
")",
")",
"}",
"\n",
"}",
"\n",
"key",
",",
"err",
":=",
"ckf",
".",
"FindKeyWithKIDUnsafe",
"(",
"kid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cki",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"CanEncrypt",
"(",
"key",
")",
"{",
"return",
"nil",
",",
"cki",
",",
"kbcrypto",
".",
"BadKeyError",
"{",
"Msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"kid",
".",
"String",
"(",
")",
")",
"}",
"\n",
"}",
"\n",
"return",
"key",
",",
"*",
"ckip",
",",
"nil",
"\n",
"}"
] | // FindActiveEncryptionSubkey takes a given KID and finds the corresponding
// active encryption subkey in the current key family. If for any reason it
// cannot find the key, it will return an error saying why. Otherwise, it will
// return the key. In this case either key is non-nil, or err is non-nil. | [
"FindActiveEncryptionSubkey",
"takes",
"a",
"given",
"KID",
"and",
"finds",
"the",
"corresponding",
"active",
"encryption",
"subkey",
"in",
"the",
"current",
"key",
"family",
".",
"If",
"for",
"any",
"reason",
"it",
"cannot",
"find",
"the",
"key",
"it",
"will",
"return",
"an",
"error",
"saying",
"why",
".",
"Otherwise",
"it",
"will",
"return",
"the",
"key",
".",
"In",
"this",
"case",
"either",
"key",
"is",
"non",
"-",
"nil",
"or",
"err",
"is",
"non",
"-",
"nil",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L558-L574 |
158,837 | keybase/client | go/libkb/keyfamily.go | TclToKeybaseTime | func TclToKeybaseTime(tcl TypedChainLink) *KeybaseTime {
return &KeybaseTime{
Unix: tcl.GetCTime().Unix(),
Chain: tcl.GetMerkleSeqno(),
}
} | go | func TclToKeybaseTime(tcl TypedChainLink) *KeybaseTime {
return &KeybaseTime{
Unix: tcl.GetCTime().Unix(),
Chain: tcl.GetMerkleSeqno(),
}
} | [
"func",
"TclToKeybaseTime",
"(",
"tcl",
"TypedChainLink",
")",
"*",
"KeybaseTime",
"{",
"return",
"&",
"KeybaseTime",
"{",
"Unix",
":",
"tcl",
".",
"GetCTime",
"(",
")",
".",
"Unix",
"(",
")",
",",
"Chain",
":",
"tcl",
".",
"GetMerkleSeqno",
"(",
")",
",",
"}",
"\n",
"}"
] | // TclToKeybaseTime turns a TypedChainLink into a KeybaseTime tuple, looking
// inside the chainlink for the Unix wallclock and the global MerkleChain seqno. | [
"TclToKeybaseTime",
"turns",
"a",
"TypedChainLink",
"into",
"a",
"KeybaseTime",
"tuple",
"looking",
"inside",
"the",
"chainlink",
"for",
"the",
"Unix",
"wallclock",
"and",
"the",
"global",
"MerkleChain",
"seqno",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L586-L591 |
158,838 | keybase/client | go/libkb/keyfamily.go | NowAsKeybaseTime | func NowAsKeybaseTime(seqno keybase1.Seqno) *KeybaseTime {
return &KeybaseTime{
Unix: time.Now().Unix(),
Chain: seqno,
}
} | go | func NowAsKeybaseTime(seqno keybase1.Seqno) *KeybaseTime {
return &KeybaseTime{
Unix: time.Now().Unix(),
Chain: seqno,
}
} | [
"func",
"NowAsKeybaseTime",
"(",
"seqno",
"keybase1",
".",
"Seqno",
")",
"*",
"KeybaseTime",
"{",
"return",
"&",
"KeybaseTime",
"{",
"Unix",
":",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
",",
"Chain",
":",
"seqno",
",",
"}",
"\n",
"}"
] | // NowAsKeybaseTime makes a representation of now. IF we don't know the MerkleTree
// chain seqno, just use 0 | [
"NowAsKeybaseTime",
"makes",
"a",
"representation",
"of",
"now",
".",
"IF",
"we",
"don",
"t",
"know",
"the",
"MerkleTree",
"chain",
"seqno",
"just",
"use",
"0"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L595-L600 |
158,839 | keybase/client | go/libkb/keyfamily.go | Delegate | func (ckf *ComputedKeyFamily) Delegate(tcl TypedChainLink) (err error) {
kid := tcl.GetDelegatedKid()
sigid := tcl.GetSigID()
tm := TclToKeybaseTime(tcl)
if kid.IsNil() {
debug.PrintStack()
return KeyFamilyError{fmt.Sprintf("Delegated KID is nil %T", tcl)}
}
if _, err := ckf.FindKeyWithKIDUnsafe(kid); err != nil {
return KeyFamilyError{fmt.Sprintf("Delegated KID %s is not in the key family", kid.String())}
}
mhm, err := tcl.GetMerkleHashMeta()
if err != nil {
return err
}
err = ckf.cki.Delegate(kid, tm, sigid, tcl.GetKID(), tcl.GetParentKid(),
tcl.GetPGPFullHash(), (tcl.GetRole() == DLGSibkey), tcl.GetCTime(), tcl.GetETime(),
mhm, tcl.GetFirstAppearedMerkleSeqnoUnverified(), tcl.ToSigChainLocation())
return
} | go | func (ckf *ComputedKeyFamily) Delegate(tcl TypedChainLink) (err error) {
kid := tcl.GetDelegatedKid()
sigid := tcl.GetSigID()
tm := TclToKeybaseTime(tcl)
if kid.IsNil() {
debug.PrintStack()
return KeyFamilyError{fmt.Sprintf("Delegated KID is nil %T", tcl)}
}
if _, err := ckf.FindKeyWithKIDUnsafe(kid); err != nil {
return KeyFamilyError{fmt.Sprintf("Delegated KID %s is not in the key family", kid.String())}
}
mhm, err := tcl.GetMerkleHashMeta()
if err != nil {
return err
}
err = ckf.cki.Delegate(kid, tm, sigid, tcl.GetKID(), tcl.GetParentKid(),
tcl.GetPGPFullHash(), (tcl.GetRole() == DLGSibkey), tcl.GetCTime(), tcl.GetETime(),
mhm, tcl.GetFirstAppearedMerkleSeqnoUnverified(), tcl.ToSigChainLocation())
return
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"Delegate",
"(",
"tcl",
"TypedChainLink",
")",
"(",
"err",
"error",
")",
"{",
"kid",
":=",
"tcl",
".",
"GetDelegatedKid",
"(",
")",
"\n",
"sigid",
":=",
"tcl",
".",
"GetSigID",
"(",
")",
"\n",
"tm",
":=",
"TclToKeybaseTime",
"(",
"tcl",
")",
"\n\n",
"if",
"kid",
".",
"IsNil",
"(",
")",
"{",
"debug",
".",
"PrintStack",
"(",
")",
"\n",
"return",
"KeyFamilyError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tcl",
")",
"}",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"ckf",
".",
"FindKeyWithKIDUnsafe",
"(",
"kid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"KeyFamilyError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"kid",
".",
"String",
"(",
")",
")",
"}",
"\n",
"}",
"\n\n",
"mhm",
",",
"err",
":=",
"tcl",
".",
"GetMerkleHashMeta",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"ckf",
".",
"cki",
".",
"Delegate",
"(",
"kid",
",",
"tm",
",",
"sigid",
",",
"tcl",
".",
"GetKID",
"(",
")",
",",
"tcl",
".",
"GetParentKid",
"(",
")",
",",
"tcl",
".",
"GetPGPFullHash",
"(",
")",
",",
"(",
"tcl",
".",
"GetRole",
"(",
")",
"==",
"DLGSibkey",
")",
",",
"tcl",
".",
"GetCTime",
"(",
")",
",",
"tcl",
".",
"GetETime",
"(",
")",
",",
"mhm",
",",
"tcl",
".",
"GetFirstAppearedMerkleSeqnoUnverified",
"(",
")",
",",
"tcl",
".",
"ToSigChainLocation",
"(",
")",
")",
"\n",
"return",
"\n",
"}"
] | // Delegate performs a delegation to the key described in the given TypedChainLink.
// This maybe be a sub- or sibkey delegation. | [
"Delegate",
"performs",
"a",
"delegation",
"to",
"the",
"key",
"described",
"in",
"the",
"given",
"TypedChainLink",
".",
"This",
"maybe",
"be",
"a",
"sub",
"-",
"or",
"sibkey",
"delegation",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L604-L628 |
158,840 | keybase/client | go/libkb/keyfamily.go | Delegate | func (cki *ComputedKeyInfos) Delegate(kid keybase1.KID, tm *KeybaseTime, sigid keybase1.SigID, signingKid, parentKID keybase1.KID,
pgpHash string, isSibkey bool, ctime, etime time.Time,
merkleHashMeta keybase1.HashMeta, fau keybase1.Seqno,
dascl keybase1.SigChainLocation) (err error) {
cki.G().Log.Debug("ComputeKeyInfos#Delegate To %s with %s at sig %s", kid.String(), signingKid, sigid.ToDisplayString(true))
info, found := cki.Infos[kid]
etimeUnix := cki.G().HonorSigchainExpireTime(etime.Unix())
if !found {
newInfo := NewComputedKeyInfo(kid, false, isSibkey, KeyUncancelled, ctime.Unix(), etimeUnix, pgpHash)
newInfo.DelegatedAt = tm
info = &newInfo
cki.Infos[kid] = info
} else {
info.Status = KeyUncancelled
info.CTime = ctime.Unix()
info.ETime = etimeUnix
}
info.Delegations[sigid] = signingKid
info.DelegationsList = append(info.DelegationsList, Delegation{signingKid, sigid})
info.Sibkey = isSibkey
info.DelegatedAtHashMeta = merkleHashMeta.DeepCopy()
info.DelegatedAtSigChainLocation = dascl.DeepCopy()
info.FirstAppearedUnverified = fau
cki.Sigs[sigid] = info
// If it's a subkey, make a pointer from it to its parent,
// and also from its parent to it.
if parentKID.Exists() {
info.Parent = parentKID
if parent, found := cki.Infos[parentKID]; found {
parent.Subkey = kid
}
}
return
} | go | func (cki *ComputedKeyInfos) Delegate(kid keybase1.KID, tm *KeybaseTime, sigid keybase1.SigID, signingKid, parentKID keybase1.KID,
pgpHash string, isSibkey bool, ctime, etime time.Time,
merkleHashMeta keybase1.HashMeta, fau keybase1.Seqno,
dascl keybase1.SigChainLocation) (err error) {
cki.G().Log.Debug("ComputeKeyInfos#Delegate To %s with %s at sig %s", kid.String(), signingKid, sigid.ToDisplayString(true))
info, found := cki.Infos[kid]
etimeUnix := cki.G().HonorSigchainExpireTime(etime.Unix())
if !found {
newInfo := NewComputedKeyInfo(kid, false, isSibkey, KeyUncancelled, ctime.Unix(), etimeUnix, pgpHash)
newInfo.DelegatedAt = tm
info = &newInfo
cki.Infos[kid] = info
} else {
info.Status = KeyUncancelled
info.CTime = ctime.Unix()
info.ETime = etimeUnix
}
info.Delegations[sigid] = signingKid
info.DelegationsList = append(info.DelegationsList, Delegation{signingKid, sigid})
info.Sibkey = isSibkey
info.DelegatedAtHashMeta = merkleHashMeta.DeepCopy()
info.DelegatedAtSigChainLocation = dascl.DeepCopy()
info.FirstAppearedUnverified = fau
cki.Sigs[sigid] = info
// If it's a subkey, make a pointer from it to its parent,
// and also from its parent to it.
if parentKID.Exists() {
info.Parent = parentKID
if parent, found := cki.Infos[parentKID]; found {
parent.Subkey = kid
}
}
return
} | [
"func",
"(",
"cki",
"*",
"ComputedKeyInfos",
")",
"Delegate",
"(",
"kid",
"keybase1",
".",
"KID",
",",
"tm",
"*",
"KeybaseTime",
",",
"sigid",
"keybase1",
".",
"SigID",
",",
"signingKid",
",",
"parentKID",
"keybase1",
".",
"KID",
",",
"pgpHash",
"string",
",",
"isSibkey",
"bool",
",",
"ctime",
",",
"etime",
"time",
".",
"Time",
",",
"merkleHashMeta",
"keybase1",
".",
"HashMeta",
",",
"fau",
"keybase1",
".",
"Seqno",
",",
"dascl",
"keybase1",
".",
"SigChainLocation",
")",
"(",
"err",
"error",
")",
"{",
"cki",
".",
"G",
"(",
")",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"kid",
".",
"String",
"(",
")",
",",
"signingKid",
",",
"sigid",
".",
"ToDisplayString",
"(",
"true",
")",
")",
"\n",
"info",
",",
"found",
":=",
"cki",
".",
"Infos",
"[",
"kid",
"]",
"\n",
"etimeUnix",
":=",
"cki",
".",
"G",
"(",
")",
".",
"HonorSigchainExpireTime",
"(",
"etime",
".",
"Unix",
"(",
")",
")",
"\n",
"if",
"!",
"found",
"{",
"newInfo",
":=",
"NewComputedKeyInfo",
"(",
"kid",
",",
"false",
",",
"isSibkey",
",",
"KeyUncancelled",
",",
"ctime",
".",
"Unix",
"(",
")",
",",
"etimeUnix",
",",
"pgpHash",
")",
"\n",
"newInfo",
".",
"DelegatedAt",
"=",
"tm",
"\n",
"info",
"=",
"&",
"newInfo",
"\n",
"cki",
".",
"Infos",
"[",
"kid",
"]",
"=",
"info",
"\n",
"}",
"else",
"{",
"info",
".",
"Status",
"=",
"KeyUncancelled",
"\n",
"info",
".",
"CTime",
"=",
"ctime",
".",
"Unix",
"(",
")",
"\n",
"info",
".",
"ETime",
"=",
"etimeUnix",
"\n",
"}",
"\n",
"info",
".",
"Delegations",
"[",
"sigid",
"]",
"=",
"signingKid",
"\n",
"info",
".",
"DelegationsList",
"=",
"append",
"(",
"info",
".",
"DelegationsList",
",",
"Delegation",
"{",
"signingKid",
",",
"sigid",
"}",
")",
"\n",
"info",
".",
"Sibkey",
"=",
"isSibkey",
"\n",
"info",
".",
"DelegatedAtHashMeta",
"=",
"merkleHashMeta",
".",
"DeepCopy",
"(",
")",
"\n",
"info",
".",
"DelegatedAtSigChainLocation",
"=",
"dascl",
".",
"DeepCopy",
"(",
")",
"\n",
"info",
".",
"FirstAppearedUnverified",
"=",
"fau",
"\n\n",
"cki",
".",
"Sigs",
"[",
"sigid",
"]",
"=",
"info",
"\n\n",
"// If it's a subkey, make a pointer from it to its parent,",
"// and also from its parent to it.",
"if",
"parentKID",
".",
"Exists",
"(",
")",
"{",
"info",
".",
"Parent",
"=",
"parentKID",
"\n",
"if",
"parent",
",",
"found",
":=",
"cki",
".",
"Infos",
"[",
"parentKID",
"]",
";",
"found",
"{",
"parent",
".",
"Subkey",
"=",
"kid",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Delegate marks the given ComputedKeyInfos object that the given kid is now
// delegated, as of time tm, in sigid, as signed by signingKid, etc.
// fau = "FirstAppearedUnverified", a hint from the server that we're going to persist.
// dascl = "DelegatedAtSigChainLocation" | [
"Delegate",
"marks",
"the",
"given",
"ComputedKeyInfos",
"object",
"that",
"the",
"given",
"kid",
"is",
"now",
"delegated",
"as",
"of",
"time",
"tm",
"in",
"sigid",
"as",
"signed",
"by",
"signingKid",
"etc",
".",
"fau",
"=",
"FirstAppearedUnverified",
"a",
"hint",
"from",
"the",
"server",
"that",
"we",
"re",
"going",
"to",
"persist",
".",
"dascl",
"=",
"DelegatedAtSigChainLocation"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L638-L674 |
158,841 | keybase/client | go/libkb/keyfamily.go | DelegatePerUserKey | func (cki *ComputedKeyInfos) DelegatePerUserKey(perUserKey keybase1.PerUserKey) (err error) {
if perUserKey.Gen <= 0 {
return fmt.Errorf("invalid per-user-key generation %v", perUserKey.Gen)
}
if perUserKey.Seqno == 0 {
return fmt.Errorf("invalid per-user-key seqno: %v", perUserKey.Seqno)
}
if perUserKey.SigKID.IsNil() {
return errors.New("nil per-user-key sig kid")
}
if perUserKey.EncKID.IsNil() {
return errors.New("nil per-user-key enc kid")
}
if perUserKey.SignedByKID.IsNil() {
return errors.New("nil per-user-key signed-by kid")
}
cki.PerUserKeys[keybase1.PerUserKeyGeneration(perUserKey.Gen)] = perUserKey
return nil
} | go | func (cki *ComputedKeyInfos) DelegatePerUserKey(perUserKey keybase1.PerUserKey) (err error) {
if perUserKey.Gen <= 0 {
return fmt.Errorf("invalid per-user-key generation %v", perUserKey.Gen)
}
if perUserKey.Seqno == 0 {
return fmt.Errorf("invalid per-user-key seqno: %v", perUserKey.Seqno)
}
if perUserKey.SigKID.IsNil() {
return errors.New("nil per-user-key sig kid")
}
if perUserKey.EncKID.IsNil() {
return errors.New("nil per-user-key enc kid")
}
if perUserKey.SignedByKID.IsNil() {
return errors.New("nil per-user-key signed-by kid")
}
cki.PerUserKeys[keybase1.PerUserKeyGeneration(perUserKey.Gen)] = perUserKey
return nil
} | [
"func",
"(",
"cki",
"*",
"ComputedKeyInfos",
")",
"DelegatePerUserKey",
"(",
"perUserKey",
"keybase1",
".",
"PerUserKey",
")",
"(",
"err",
"error",
")",
"{",
"if",
"perUserKey",
".",
"Gen",
"<=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"perUserKey",
".",
"Gen",
")",
"\n",
"}",
"\n",
"if",
"perUserKey",
".",
"Seqno",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"perUserKey",
".",
"Seqno",
")",
"\n",
"}",
"\n",
"if",
"perUserKey",
".",
"SigKID",
".",
"IsNil",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"perUserKey",
".",
"EncKID",
".",
"IsNil",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"perUserKey",
".",
"SignedByKID",
".",
"IsNil",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cki",
".",
"PerUserKeys",
"[",
"keybase1",
".",
"PerUserKeyGeneration",
"(",
"perUserKey",
".",
"Gen",
")",
"]",
"=",
"perUserKey",
"\n",
"return",
"nil",
"\n",
"}"
] | // DelegatePerUserKey inserts the new per-user key into the list of known per-user keys. | [
"DelegatePerUserKey",
"inserts",
"the",
"new",
"per",
"-",
"user",
"key",
"into",
"the",
"list",
"of",
"known",
"per",
"-",
"user",
"keys",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L681-L699 |
158,842 | keybase/client | go/libkb/keyfamily.go | Revoke | func (ckf *ComputedKeyFamily) Revoke(tcl TypedChainLink) (err error) {
err = ckf.revokeSigs(tcl.GetRevocations(), tcl)
if err == nil {
err = ckf.revokeKids(tcl.GetRevokeKids(), tcl)
}
return err
} | go | func (ckf *ComputedKeyFamily) Revoke(tcl TypedChainLink) (err error) {
err = ckf.revokeSigs(tcl.GetRevocations(), tcl)
if err == nil {
err = ckf.revokeKids(tcl.GetRevokeKids(), tcl)
}
return err
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"Revoke",
"(",
"tcl",
"TypedChainLink",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"ckf",
".",
"revokeSigs",
"(",
"tcl",
".",
"GetRevocations",
"(",
")",
",",
"tcl",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"ckf",
".",
"revokeKids",
"(",
"tcl",
".",
"GetRevokeKids",
"(",
")",
",",
"tcl",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Revoke examines a TypeChainLink and applies any revocations in the link
// to the current ComputedKeyInfos. | [
"Revoke",
"examines",
"a",
"TypeChainLink",
"and",
"applies",
"any",
"revocations",
"in",
"the",
"link",
"to",
"the",
"current",
"ComputedKeyInfos",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L703-L709 |
158,843 | keybase/client | go/libkb/keyfamily.go | ClearActivePGPHash | func (ckf *ComputedKeyFamily) ClearActivePGPHash(kid keybase1.KID) {
if _, ok := ckf.cki.Infos[kid]; ok {
ckf.cki.Infos[kid].ActivePGPHash = ""
} else {
ckf.G().Log.Debug("| Skipped clearing active hash, since key was never delegated")
}
} | go | func (ckf *ComputedKeyFamily) ClearActivePGPHash(kid keybase1.KID) {
if _, ok := ckf.cki.Infos[kid]; ok {
ckf.cki.Infos[kid].ActivePGPHash = ""
} else {
ckf.G().Log.Debug("| Skipped clearing active hash, since key was never delegated")
}
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"ClearActivePGPHash",
"(",
"kid",
"keybase1",
".",
"KID",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"ckf",
".",
"cki",
".",
"Infos",
"[",
"kid",
"]",
";",
"ok",
"{",
"ckf",
".",
"cki",
".",
"Infos",
"[",
"kid",
"]",
".",
"ActivePGPHash",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"ckf",
".",
"G",
"(",
")",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // ClearActivePGPHash clears authoritative hash of PGP key, after a revoke. | [
"ClearActivePGPHash",
"clears",
"authoritative",
"hash",
"of",
"PGP",
"key",
"after",
"a",
"revoke",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L733-L739 |
158,844 | keybase/client | go/libkb/keyfamily.go | revokeSigs | func (ckf *ComputedKeyFamily) revokeSigs(sigs []keybase1.SigID, tcl TypedChainLink) error {
for _, s := range sigs {
if len(s) == 0 {
continue
}
if err := ckf.RevokeSig(s, tcl); err != nil {
return err
}
}
return nil
} | go | func (ckf *ComputedKeyFamily) revokeSigs(sigs []keybase1.SigID, tcl TypedChainLink) error {
for _, s := range sigs {
if len(s) == 0 {
continue
}
if err := ckf.RevokeSig(s, tcl); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"revokeSigs",
"(",
"sigs",
"[",
"]",
"keybase1",
".",
"SigID",
",",
"tcl",
"TypedChainLink",
")",
"error",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"sigs",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ckf",
".",
"RevokeSig",
"(",
"s",
",",
"tcl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // revokeSigs operates on the per-signature revocations in the given
// TypedChainLink and applies them accordingly. | [
"revokeSigs",
"operates",
"on",
"the",
"per",
"-",
"signature",
"revocations",
"in",
"the",
"given",
"TypedChainLink",
"and",
"applies",
"them",
"accordingly",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L743-L753 |
158,845 | keybase/client | go/libkb/keyfamily.go | revokeKids | func (ckf *ComputedKeyFamily) revokeKids(kids []keybase1.KID, tcl TypedChainLink) (err error) {
for _, k := range kids {
if k.Exists() {
if err = ckf.RevokeKid(k, tcl); err != nil {
return
}
}
}
return
} | go | func (ckf *ComputedKeyFamily) revokeKids(kids []keybase1.KID, tcl TypedChainLink) (err error) {
for _, k := range kids {
if k.Exists() {
if err = ckf.RevokeKid(k, tcl); err != nil {
return
}
}
}
return
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"revokeKids",
"(",
"kids",
"[",
"]",
"keybase1",
".",
"KID",
",",
"tcl",
"TypedChainLink",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"k",
":=",
"range",
"kids",
"{",
"if",
"k",
".",
"Exists",
"(",
")",
"{",
"if",
"err",
"=",
"ckf",
".",
"RevokeKid",
"(",
"k",
",",
"tcl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // revokeKids operates on the per-kid revocations in the given
// TypedChainLink and applies them accordingly. | [
"revokeKids",
"operates",
"on",
"the",
"per",
"-",
"kid",
"revocations",
"in",
"the",
"given",
"TypedChainLink",
"and",
"applies",
"them",
"accordingly",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L757-L766 |
158,846 | keybase/client | go/libkb/keyfamily.go | FindKeybaseName | func (ckf ComputedKeyFamily) FindKeybaseName(s string) bool {
kem := KeybaseEmailAddress(s)
for kid := range ckf.kf.PGPKeySets {
if info, found := ckf.cki.Infos[kid]; !found {
continue
} else if info.Status != KeyUncancelled || !info.Sibkey {
continue
}
pgp := ckf.kf.PGPKeySets[kid].PermissivelyMergedKey
if pgp.FindEmail(kem) {
ckf.G().Log.Debug("| Found self-sig for %s in key ID: %s", s, kid)
return true
}
}
return false
} | go | func (ckf ComputedKeyFamily) FindKeybaseName(s string) bool {
kem := KeybaseEmailAddress(s)
for kid := range ckf.kf.PGPKeySets {
if info, found := ckf.cki.Infos[kid]; !found {
continue
} else if info.Status != KeyUncancelled || !info.Sibkey {
continue
}
pgp := ckf.kf.PGPKeySets[kid].PermissivelyMergedKey
if pgp.FindEmail(kem) {
ckf.G().Log.Debug("| Found self-sig for %s in key ID: %s", s, kid)
return true
}
}
return false
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"FindKeybaseName",
"(",
"s",
"string",
")",
"bool",
"{",
"kem",
":=",
"KeybaseEmailAddress",
"(",
"s",
")",
"\n",
"for",
"kid",
":=",
"range",
"ckf",
".",
"kf",
".",
"PGPKeySets",
"{",
"if",
"info",
",",
"found",
":=",
"ckf",
".",
"cki",
".",
"Infos",
"[",
"kid",
"]",
";",
"!",
"found",
"{",
"continue",
"\n",
"}",
"else",
"if",
"info",
".",
"Status",
"!=",
"KeyUncancelled",
"||",
"!",
"info",
".",
"Sibkey",
"{",
"continue",
"\n",
"}",
"\n",
"pgp",
":=",
"ckf",
".",
"kf",
".",
"PGPKeySets",
"[",
"kid",
"]",
".",
"PermissivelyMergedKey",
"\n",
"if",
"pgp",
".",
"FindEmail",
"(",
"kem",
")",
"{",
"ckf",
".",
"G",
"(",
")",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"s",
",",
"kid",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // FindKeybaseName looks at all PGP keys in this key family that are active
// sibkeys to find a key with a signed identity of <[email protected]>. IF
// found return true, and otherwise false. | [
"FindKeybaseName",
"looks",
"at",
"all",
"PGP",
"keys",
"in",
"this",
"key",
"family",
"that",
"are",
"active",
"sibkeys",
"to",
"find",
"a",
"key",
"with",
"a",
"signed",
"identity",
"of",
"<name"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L823-L838 |
158,847 | keybase/client | go/libkb/keyfamily.go | LocalDelegate | func (kf *KeyFamily) LocalDelegate(key GenericKey) (err error) {
if pgp, ok := key.(*PGPKeyBundle); ok {
kid := pgp.GetKID()
kf.pgp2kid[pgp.GetFingerprint()] = kid
}
kf.SingleKeys[key.GetKID()] = key
return
} | go | func (kf *KeyFamily) LocalDelegate(key GenericKey) (err error) {
if pgp, ok := key.(*PGPKeyBundle); ok {
kid := pgp.GetKID()
kf.pgp2kid[pgp.GetFingerprint()] = kid
}
kf.SingleKeys[key.GetKID()] = key
return
} | [
"func",
"(",
"kf",
"*",
"KeyFamily",
")",
"LocalDelegate",
"(",
"key",
"GenericKey",
")",
"(",
"err",
"error",
")",
"{",
"if",
"pgp",
",",
"ok",
":=",
"key",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"ok",
"{",
"kid",
":=",
"pgp",
".",
"GetKID",
"(",
")",
"\n",
"kf",
".",
"pgp2kid",
"[",
"pgp",
".",
"GetFingerprint",
"(",
")",
"]",
"=",
"kid",
"\n",
"}",
"\n",
"kf",
".",
"SingleKeys",
"[",
"key",
".",
"GetKID",
"(",
")",
"]",
"=",
"key",
"\n",
"return",
"\n",
"}"
] | // LocalDelegate performs a local key delegation, without the server's permissions.
// We'll need to do this when a key is locally generated. | [
"LocalDelegate",
"performs",
"a",
"local",
"key",
"delegation",
"without",
"the",
"server",
"s",
"permissions",
".",
"We",
"ll",
"need",
"to",
"do",
"this",
"when",
"a",
"key",
"is",
"locally",
"generated",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L842-L849 |
158,848 | keybase/client | go/libkb/keyfamily.go | HasActiveKey | func (ckf ComputedKeyFamily) HasActiveKey() bool {
for kid := range ckf.kf.AllKIDs {
if ckf.GetKeyRole(kid) == DLGSibkey {
return true
}
}
return false
} | go | func (ckf ComputedKeyFamily) HasActiveKey() bool {
for kid := range ckf.kf.AllKIDs {
if ckf.GetKeyRole(kid) == DLGSibkey {
return true
}
}
return false
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"HasActiveKey",
"(",
")",
"bool",
"{",
"for",
"kid",
":=",
"range",
"ckf",
".",
"kf",
".",
"AllKIDs",
"{",
"if",
"ckf",
".",
"GetKeyRole",
"(",
"kid",
")",
"==",
"DLGSibkey",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // HasActiveKey returns if the given ComputeKeyFamily has any active keys.
// The key has to be in the server-given KeyFamily and also in our ComputedKeyFamily.
// The former check is so that we can handle the case nuked sigchains. | [
"HasActiveKey",
"returns",
"if",
"the",
"given",
"ComputeKeyFamily",
"has",
"any",
"active",
"keys",
".",
"The",
"key",
"has",
"to",
"be",
"in",
"the",
"server",
"-",
"given",
"KeyFamily",
"and",
"also",
"in",
"our",
"ComputedKeyFamily",
".",
"The",
"former",
"check",
"is",
"so",
"that",
"we",
"can",
"handle",
"the",
"case",
"nuked",
"sigchains",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L959-L966 |
158,849 | keybase/client | go/libkb/keyfamily.go | GetActivePGPKeys | func (ckf ComputedKeyFamily) GetActivePGPKeys(sibkey bool) (ret []*PGPKeyBundle) {
for kid := range ckf.kf.PGPKeySets {
role := ckf.GetKeyRole(kid)
if (sibkey && role == DLGSibkey) || role != DLGNone {
if key, err := ckf.FindKeyWithKIDUnsafe(kid); err == nil {
ret = append(ret, key.(*PGPKeyBundle))
} else {
ckf.G().Log.Errorf("KID %s was in a KeyFamily's list of PGP keys, but the key doesn't exist: %s", kid, err)
}
}
}
return
} | go | func (ckf ComputedKeyFamily) GetActivePGPKeys(sibkey bool) (ret []*PGPKeyBundle) {
for kid := range ckf.kf.PGPKeySets {
role := ckf.GetKeyRole(kid)
if (sibkey && role == DLGSibkey) || role != DLGNone {
if key, err := ckf.FindKeyWithKIDUnsafe(kid); err == nil {
ret = append(ret, key.(*PGPKeyBundle))
} else {
ckf.G().Log.Errorf("KID %s was in a KeyFamily's list of PGP keys, but the key doesn't exist: %s", kid, err)
}
}
}
return
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"GetActivePGPKeys",
"(",
"sibkey",
"bool",
")",
"(",
"ret",
"[",
"]",
"*",
"PGPKeyBundle",
")",
"{",
"for",
"kid",
":=",
"range",
"ckf",
".",
"kf",
".",
"PGPKeySets",
"{",
"role",
":=",
"ckf",
".",
"GetKeyRole",
"(",
"kid",
")",
"\n",
"if",
"(",
"sibkey",
"&&",
"role",
"==",
"DLGSibkey",
")",
"||",
"role",
"!=",
"DLGNone",
"{",
"if",
"key",
",",
"err",
":=",
"ckf",
".",
"FindKeyWithKIDUnsafe",
"(",
"kid",
")",
";",
"err",
"==",
"nil",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"key",
".",
"(",
"*",
"PGPKeyBundle",
")",
")",
"\n",
"}",
"else",
"{",
"ckf",
".",
"G",
"(",
")",
".",
"Log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"kid",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // GetActivePGPKeys gets the active PGP keys from the ComputedKeyFamily.
// If sibkey is False it will return all active PGP keys. Otherwise, it
// will return only the Sibkeys. Note the keys need to be non-canceled,
// and non-expired. | [
"GetActivePGPKeys",
"gets",
"the",
"active",
"PGP",
"keys",
"from",
"the",
"ComputedKeyFamily",
".",
"If",
"sibkey",
"is",
"False",
"it",
"will",
"return",
"all",
"active",
"PGP",
"keys",
".",
"Otherwise",
"it",
"will",
"return",
"only",
"the",
"Sibkeys",
".",
"Note",
"the",
"keys",
"need",
"to",
"be",
"non",
"-",
"canceled",
"and",
"non",
"-",
"expired",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L972-L984 |
158,850 | keybase/client | go/libkb/keyfamily.go | UpdateDevices | func (ckf *ComputedKeyFamily) UpdateDevices(tcl TypedChainLink) (err error) {
var dobj *Device
if dobj = tcl.GetDevice(); dobj == nil {
ckf.G().VDL.Log(VLog1, "Short-circuit of UpdateDevices(); not a device link")
return
}
defer ckf.G().Trace("UpdateDevice", func() error { return err })()
did := dobj.ID
kid := dobj.Kid
ckf.G().Log.Debug("| Device ID=%s; KID=%s", did, kid.String())
var prevKid keybase1.KID
if existing, found := ckf.cki.Devices[did]; found {
ckf.G().Log.Debug("| merge with existing")
prevKid = existing.Kid
existing.Merge(dobj)
dobj = existing
} else {
ckf.G().Log.Debug("| New insert")
ckf.cki.Devices[did] = dobj
}
// If a KID is specified, we should clear out any previous KID from the
// KID->Device map. But if not, leave the map as it is. Later "device"
// blobs in the sigchain aren't required to repeat the KID every time.
if kid.IsValid() {
if prevKid.IsValid() {
ckf.G().Log.Debug("| Clear out old key")
delete(ckf.cki.KIDToDeviceID, prevKid)
}
ckf.cki.KIDToDeviceID[kid] = did
}
return
} | go | func (ckf *ComputedKeyFamily) UpdateDevices(tcl TypedChainLink) (err error) {
var dobj *Device
if dobj = tcl.GetDevice(); dobj == nil {
ckf.G().VDL.Log(VLog1, "Short-circuit of UpdateDevices(); not a device link")
return
}
defer ckf.G().Trace("UpdateDevice", func() error { return err })()
did := dobj.ID
kid := dobj.Kid
ckf.G().Log.Debug("| Device ID=%s; KID=%s", did, kid.String())
var prevKid keybase1.KID
if existing, found := ckf.cki.Devices[did]; found {
ckf.G().Log.Debug("| merge with existing")
prevKid = existing.Kid
existing.Merge(dobj)
dobj = existing
} else {
ckf.G().Log.Debug("| New insert")
ckf.cki.Devices[did] = dobj
}
// If a KID is specified, we should clear out any previous KID from the
// KID->Device map. But if not, leave the map as it is. Later "device"
// blobs in the sigchain aren't required to repeat the KID every time.
if kid.IsValid() {
if prevKid.IsValid() {
ckf.G().Log.Debug("| Clear out old key")
delete(ckf.cki.KIDToDeviceID, prevKid)
}
ckf.cki.KIDToDeviceID[kid] = did
}
return
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"UpdateDevices",
"(",
"tcl",
"TypedChainLink",
")",
"(",
"err",
"error",
")",
"{",
"var",
"dobj",
"*",
"Device",
"\n",
"if",
"dobj",
"=",
"tcl",
".",
"GetDevice",
"(",
")",
";",
"dobj",
"==",
"nil",
"{",
"ckf",
".",
"G",
"(",
")",
".",
"VDL",
".",
"Log",
"(",
"VLog1",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"defer",
"ckf",
".",
"G",
"(",
")",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n\n",
"did",
":=",
"dobj",
".",
"ID",
"\n",
"kid",
":=",
"dobj",
".",
"Kid",
"\n\n",
"ckf",
".",
"G",
"(",
")",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"did",
",",
"kid",
".",
"String",
"(",
")",
")",
"\n\n",
"var",
"prevKid",
"keybase1",
".",
"KID",
"\n",
"if",
"existing",
",",
"found",
":=",
"ckf",
".",
"cki",
".",
"Devices",
"[",
"did",
"]",
";",
"found",
"{",
"ckf",
".",
"G",
"(",
")",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"prevKid",
"=",
"existing",
".",
"Kid",
"\n",
"existing",
".",
"Merge",
"(",
"dobj",
")",
"\n",
"dobj",
"=",
"existing",
"\n",
"}",
"else",
"{",
"ckf",
".",
"G",
"(",
")",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"ckf",
".",
"cki",
".",
"Devices",
"[",
"did",
"]",
"=",
"dobj",
"\n",
"}",
"\n\n",
"// If a KID is specified, we should clear out any previous KID from the",
"// KID->Device map. But if not, leave the map as it is. Later \"device\"",
"// blobs in the sigchain aren't required to repeat the KID every time.",
"if",
"kid",
".",
"IsValid",
"(",
")",
"{",
"if",
"prevKid",
".",
"IsValid",
"(",
")",
"{",
"ckf",
".",
"G",
"(",
")",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"delete",
"(",
"ckf",
".",
"cki",
".",
"KIDToDeviceID",
",",
"prevKid",
")",
"\n",
"}",
"\n",
"ckf",
".",
"cki",
".",
"KIDToDeviceID",
"[",
"kid",
"]",
"=",
"did",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // UpdateDevices takes the Device object from the given ChainLink
// and updates keys to reflects any device changes encoded therein. | [
"UpdateDevices",
"takes",
"the",
"Device",
"object",
"from",
"the",
"given",
"ChainLink",
"and",
"updates",
"keys",
"to",
"reflects",
"any",
"device",
"changes",
"encoded",
"therein",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L1049-L1087 |
158,851 | keybase/client | go/libkb/keyfamily.go | GetSibkeyForDevice | func (ckf *ComputedKeyFamily) GetSibkeyForDevice(did keybase1.DeviceID) (key GenericKey, err error) {
var kid keybase1.KID
kid, err = ckf.getSibkeyKidForDevice(did)
if kid.Exists() {
key, _, err = ckf.FindActiveSibkey(kid)
}
return
} | go | func (ckf *ComputedKeyFamily) GetSibkeyForDevice(did keybase1.DeviceID) (key GenericKey, err error) {
var kid keybase1.KID
kid, err = ckf.getSibkeyKidForDevice(did)
if kid.Exists() {
key, _, err = ckf.FindActiveSibkey(kid)
}
return
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"GetSibkeyForDevice",
"(",
"did",
"keybase1",
".",
"DeviceID",
")",
"(",
"key",
"GenericKey",
",",
"err",
"error",
")",
"{",
"var",
"kid",
"keybase1",
".",
"KID",
"\n",
"kid",
",",
"err",
"=",
"ckf",
".",
"getSibkeyKidForDevice",
"(",
"did",
")",
"\n",
"if",
"kid",
".",
"Exists",
"(",
")",
"{",
"key",
",",
"_",
",",
"err",
"=",
"ckf",
".",
"FindActiveSibkey",
"(",
"kid",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // GetSibkeyForDevice gets the current per-device key for the given Device. Will
// return nil if one isn't found, and set err for a real error. The sibkey should
// be a signing key, not an encryption key of course. | [
"GetSibkeyForDevice",
"gets",
"the",
"current",
"per",
"-",
"device",
"key",
"for",
"the",
"given",
"Device",
".",
"Will",
"return",
"nil",
"if",
"one",
"isn",
"t",
"found",
"and",
"set",
"err",
"for",
"a",
"real",
"error",
".",
"The",
"sibkey",
"should",
"be",
"a",
"signing",
"key",
"not",
"an",
"encryption",
"key",
"of",
"course",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L1111-L1118 |
158,852 | keybase/client | go/libkb/keyfamily.go | GetCurrentDevice | func (ckf *ComputedKeyFamily) GetCurrentDevice(g *GlobalContext) (*Device, error) {
did := g.Env.GetDeviceID()
if did.IsNil() {
return nil, NotProvisionedError{}
}
dev, ok := ckf.cki.Devices[did]
if !ok {
return nil, NotFoundError{}
}
return dev, nil
} | go | func (ckf *ComputedKeyFamily) GetCurrentDevice(g *GlobalContext) (*Device, error) {
did := g.Env.GetDeviceID()
if did.IsNil() {
return nil, NotProvisionedError{}
}
dev, ok := ckf.cki.Devices[did]
if !ok {
return nil, NotFoundError{}
}
return dev, nil
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"GetCurrentDevice",
"(",
"g",
"*",
"GlobalContext",
")",
"(",
"*",
"Device",
",",
"error",
")",
"{",
"did",
":=",
"g",
".",
"Env",
".",
"GetDeviceID",
"(",
")",
"\n",
"if",
"did",
".",
"IsNil",
"(",
")",
"{",
"return",
"nil",
",",
"NotProvisionedError",
"{",
"}",
"\n",
"}",
"\n\n",
"dev",
",",
"ok",
":=",
"ckf",
".",
"cki",
".",
"Devices",
"[",
"did",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"NotFoundError",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"dev",
",",
"nil",
"\n",
"}"
] | // GetCurrentDevice returns the current device. | [
"GetCurrentDevice",
"returns",
"the",
"current",
"device",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L1121-L1133 |
158,853 | keybase/client | go/libkb/keyfamily.go | GetEncryptionSubkeyForDevice | func (ckf *ComputedKeyFamily) GetEncryptionSubkeyForDevice(did keybase1.DeviceID) (key GenericKey, err error) {
var kid keybase1.KID
if kid, err = ckf.getSibkeyKidForDevice(did); err != nil {
return
}
if kid.IsNil() {
return
}
if cki, found := ckf.cki.Infos[kid]; !found {
return
} else if !cki.Subkey.IsValid() {
return
} else {
key, _, err = ckf.FindActiveEncryptionSubkey(cki.Subkey)
}
return
} | go | func (ckf *ComputedKeyFamily) GetEncryptionSubkeyForDevice(did keybase1.DeviceID) (key GenericKey, err error) {
var kid keybase1.KID
if kid, err = ckf.getSibkeyKidForDevice(did); err != nil {
return
}
if kid.IsNil() {
return
}
if cki, found := ckf.cki.Infos[kid]; !found {
return
} else if !cki.Subkey.IsValid() {
return
} else {
key, _, err = ckf.FindActiveEncryptionSubkey(cki.Subkey)
}
return
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"GetEncryptionSubkeyForDevice",
"(",
"did",
"keybase1",
".",
"DeviceID",
")",
"(",
"key",
"GenericKey",
",",
"err",
"error",
")",
"{",
"var",
"kid",
"keybase1",
".",
"KID",
"\n",
"if",
"kid",
",",
"err",
"=",
"ckf",
".",
"getSibkeyKidForDevice",
"(",
"did",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"kid",
".",
"IsNil",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"if",
"cki",
",",
"found",
":=",
"ckf",
".",
"cki",
".",
"Infos",
"[",
"kid",
"]",
";",
"!",
"found",
"{",
"return",
"\n",
"}",
"else",
"if",
"!",
"cki",
".",
"Subkey",
".",
"IsValid",
"(",
")",
"{",
"return",
"\n",
"}",
"else",
"{",
"key",
",",
"_",
",",
"err",
"=",
"ckf",
".",
"FindActiveEncryptionSubkey",
"(",
"cki",
".",
"Subkey",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // GetEncryptionSubkeyForDevice gets the current encryption subkey for the given device. | [
"GetEncryptionSubkeyForDevice",
"gets",
"the",
"current",
"encryption",
"subkey",
"for",
"the",
"given",
"device",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L1136-L1152 |
158,854 | keybase/client | go/libkb/keyfamily.go | GetDeviceForKey | func (ckf *ComputedKeyFamily) GetDeviceForKey(key GenericKey) (*Device, error) {
return ckf.GetDeviceForKID(key.GetKID())
} | go | func (ckf *ComputedKeyFamily) GetDeviceForKey(key GenericKey) (*Device, error) {
return ckf.GetDeviceForKID(key.GetKID())
} | [
"func",
"(",
"ckf",
"*",
"ComputedKeyFamily",
")",
"GetDeviceForKey",
"(",
"key",
"GenericKey",
")",
"(",
"*",
"Device",
",",
"error",
")",
"{",
"return",
"ckf",
".",
"GetDeviceForKID",
"(",
"key",
".",
"GetKID",
"(",
")",
")",
"\n",
"}"
] | // GetDeviceForKey gets the device that this key is bound to, if any. | [
"GetDeviceForKey",
"gets",
"the",
"device",
"that",
"this",
"key",
"is",
"bound",
"to",
"if",
"any",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/keyfamily.go#L1167-L1169 |
158,855 | keybase/client | go/teams/sig.go | NewSubteamID | func NewSubteamID(public bool) keybase1.TeamID {
var useSuffix byte = keybase1.SUB_TEAMID_PRIVATE_SUFFIX
if public {
useSuffix = keybase1.SUB_TEAMID_PUBLIC_SUFFIX
}
idBytes, err := libkb.RandBytesWithSuffix(16, useSuffix)
if err != nil {
panic("RandBytes failed: " + err.Error())
}
return keybase1.TeamID(hex.EncodeToString(idBytes))
} | go | func NewSubteamID(public bool) keybase1.TeamID {
var useSuffix byte = keybase1.SUB_TEAMID_PRIVATE_SUFFIX
if public {
useSuffix = keybase1.SUB_TEAMID_PUBLIC_SUFFIX
}
idBytes, err := libkb.RandBytesWithSuffix(16, useSuffix)
if err != nil {
panic("RandBytes failed: " + err.Error())
}
return keybase1.TeamID(hex.EncodeToString(idBytes))
} | [
"func",
"NewSubteamID",
"(",
"public",
"bool",
")",
"keybase1",
".",
"TeamID",
"{",
"var",
"useSuffix",
"byte",
"=",
"keybase1",
".",
"SUB_TEAMID_PRIVATE_SUFFIX",
"\n",
"if",
"public",
"{",
"useSuffix",
"=",
"keybase1",
".",
"SUB_TEAMID_PUBLIC_SUFFIX",
"\n",
"}",
"\n",
"idBytes",
",",
"err",
":=",
"libkb",
".",
"RandBytesWithSuffix",
"(",
"16",
",",
"useSuffix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"keybase1",
".",
"TeamID",
"(",
"hex",
".",
"EncodeToString",
"(",
"idBytes",
")",
")",
"\n",
"}"
] | // 15 random bytes, followed by the byte 0x25, encoded as hex | [
"15",
"random",
"bytes",
"followed",
"by",
"the",
"byte",
"0x25",
"encoded",
"as",
"hex"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/sig.go#L197-L207 |
158,856 | keybase/client | go/engine/device_keygen.go | NewDeviceKeygen | func NewDeviceKeygen(g *libkb.GlobalContext, args *DeviceKeygenArgs) *DeviceKeygen {
return &DeviceKeygen{
args: args,
Contextified: libkb.NewContextified(g),
}
} | go | func NewDeviceKeygen(g *libkb.GlobalContext, args *DeviceKeygenArgs) *DeviceKeygen {
return &DeviceKeygen{
args: args,
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewDeviceKeygen",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"args",
"*",
"DeviceKeygenArgs",
")",
"*",
"DeviceKeygen",
"{",
"return",
"&",
"DeviceKeygen",
"{",
"args",
":",
"args",
",",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewDeviceKeygen creates a DeviceKeygen engine. | [
"NewDeviceKeygen",
"creates",
"a",
"DeviceKeygen",
"engine",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/device_keygen.go#L69-L74 |
158,857 | keybase/client | go/engine/device_keygen.go | preparePerUserKeyBoxFromProvisioningKey | func (e *DeviceKeygen) preparePerUserKeyBoxFromProvisioningKey(m libkb.MetaContext) ([]keybase1.PerUserKeyBox, error) {
// Assuming this is a paperkey or self provision.
upak := e.args.Me.ExportToUserPlusAllKeys()
if len(upak.Base.PerUserKeys) == 0 {
m.Debug("DeviceKeygen skipping per-user-keys, none exist")
return nil, nil
}
pukring := e.args.PerUserKeyring
if pukring == nil {
return nil, errors.New("missing PerUserKeyring")
}
provisioningKey := m.ActiveDevice().ProvisioningKey(m)
var provisioningSigKey, provisioningEncKeyGeneric libkb.GenericKey
if provisioningKey != nil {
provisioningSigKey = provisioningKey.SigningKey()
provisioningEncKeyGeneric = provisioningKey.EncryptionKey()
}
if provisioningSigKey == nil && provisioningEncKeyGeneric == nil {
// GPG provisioning is not supported when the user has per-user-keys.
// This is the error that manifests. See CORE-4960
return nil, errors.New("missing provisioning key in login context")
}
if provisioningSigKey == nil {
return nil, errors.New("missing provisioning sig key")
}
if provisioningEncKeyGeneric == nil {
return nil, errors.New("missing provisioning enc key")
}
provisioningEncKey, ok := provisioningEncKeyGeneric.(libkb.NaclDHKeyPair)
if !ok {
return nil, errors.New("Unexpected encryption key type")
}
provisioningDeviceID, err := upak.GetDeviceID(provisioningSigKey.GetKID())
if err != nil {
return nil, err
}
err = pukring.SyncAsProvisioningKey(m, &upak, provisioningDeviceID, provisioningEncKey)
if err != nil {
return nil, err
}
if !pukring.HasAnyKeys() {
return nil, nil
}
pukBox, err := pukring.PrepareBoxForNewDevice(m,
e.EncryptionKey(), // receiver key: provisionee enc
provisioningEncKey, // sender key: provisioning key enc
)
return []keybase1.PerUserKeyBox{pukBox}, err
} | go | func (e *DeviceKeygen) preparePerUserKeyBoxFromProvisioningKey(m libkb.MetaContext) ([]keybase1.PerUserKeyBox, error) {
// Assuming this is a paperkey or self provision.
upak := e.args.Me.ExportToUserPlusAllKeys()
if len(upak.Base.PerUserKeys) == 0 {
m.Debug("DeviceKeygen skipping per-user-keys, none exist")
return nil, nil
}
pukring := e.args.PerUserKeyring
if pukring == nil {
return nil, errors.New("missing PerUserKeyring")
}
provisioningKey := m.ActiveDevice().ProvisioningKey(m)
var provisioningSigKey, provisioningEncKeyGeneric libkb.GenericKey
if provisioningKey != nil {
provisioningSigKey = provisioningKey.SigningKey()
provisioningEncKeyGeneric = provisioningKey.EncryptionKey()
}
if provisioningSigKey == nil && provisioningEncKeyGeneric == nil {
// GPG provisioning is not supported when the user has per-user-keys.
// This is the error that manifests. See CORE-4960
return nil, errors.New("missing provisioning key in login context")
}
if provisioningSigKey == nil {
return nil, errors.New("missing provisioning sig key")
}
if provisioningEncKeyGeneric == nil {
return nil, errors.New("missing provisioning enc key")
}
provisioningEncKey, ok := provisioningEncKeyGeneric.(libkb.NaclDHKeyPair)
if !ok {
return nil, errors.New("Unexpected encryption key type")
}
provisioningDeviceID, err := upak.GetDeviceID(provisioningSigKey.GetKID())
if err != nil {
return nil, err
}
err = pukring.SyncAsProvisioningKey(m, &upak, provisioningDeviceID, provisioningEncKey)
if err != nil {
return nil, err
}
if !pukring.HasAnyKeys() {
return nil, nil
}
pukBox, err := pukring.PrepareBoxForNewDevice(m,
e.EncryptionKey(), // receiver key: provisionee enc
provisioningEncKey, // sender key: provisioning key enc
)
return []keybase1.PerUserKeyBox{pukBox}, err
} | [
"func",
"(",
"e",
"*",
"DeviceKeygen",
")",
"preparePerUserKeyBoxFromProvisioningKey",
"(",
"m",
"libkb",
".",
"MetaContext",
")",
"(",
"[",
"]",
"keybase1",
".",
"PerUserKeyBox",
",",
"error",
")",
"{",
"// Assuming this is a paperkey or self provision.",
"upak",
":=",
"e",
".",
"args",
".",
"Me",
".",
"ExportToUserPlusAllKeys",
"(",
")",
"\n",
"if",
"len",
"(",
"upak",
".",
"Base",
".",
"PerUserKeys",
")",
"==",
"0",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"pukring",
":=",
"e",
".",
"args",
".",
"PerUserKeyring",
"\n",
"if",
"pukring",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"provisioningKey",
":=",
"m",
".",
"ActiveDevice",
"(",
")",
".",
"ProvisioningKey",
"(",
"m",
")",
"\n",
"var",
"provisioningSigKey",
",",
"provisioningEncKeyGeneric",
"libkb",
".",
"GenericKey",
"\n",
"if",
"provisioningKey",
"!=",
"nil",
"{",
"provisioningSigKey",
"=",
"provisioningKey",
".",
"SigningKey",
"(",
")",
"\n",
"provisioningEncKeyGeneric",
"=",
"provisioningKey",
".",
"EncryptionKey",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"provisioningSigKey",
"==",
"nil",
"&&",
"provisioningEncKeyGeneric",
"==",
"nil",
"{",
"// GPG provisioning is not supported when the user has per-user-keys.",
"// This is the error that manifests. See CORE-4960",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"provisioningSigKey",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"provisioningEncKeyGeneric",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"provisioningEncKey",
",",
"ok",
":=",
"provisioningEncKeyGeneric",
".",
"(",
"libkb",
".",
"NaclDHKeyPair",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"provisioningDeviceID",
",",
"err",
":=",
"upak",
".",
"GetDeviceID",
"(",
"provisioningSigKey",
".",
"GetKID",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"pukring",
".",
"SyncAsProvisioningKey",
"(",
"m",
",",
"&",
"upak",
",",
"provisioningDeviceID",
",",
"provisioningEncKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"pukring",
".",
"HasAnyKeys",
"(",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"pukBox",
",",
"err",
":=",
"pukring",
".",
"PrepareBoxForNewDevice",
"(",
"m",
",",
"e",
".",
"EncryptionKey",
"(",
")",
",",
"// receiver key: provisionee enc",
"provisioningEncKey",
",",
"// sender key: provisioning key enc",
")",
"\n",
"return",
"[",
"]",
"keybase1",
".",
"PerUserKeyBox",
"{",
"pukBox",
"}",
",",
"err",
"\n",
"}"
] | // Can return no boxes if there are no per-user-keys. | [
"Can",
"return",
"no",
"boxes",
"if",
"there",
"are",
"no",
"per",
"-",
"user",
"-",
"keys",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/device_keygen.go#L389-L442 |
158,858 | keybase/client | go/stellar/bundle/bundle.go | New | func New(secret stellar1.SecretKey, name string) (*stellar1.Bundle, error) {
secretKey, accountID, _, err := libkb.ParseStellarSecretKey(string(secret))
if err != nil {
return nil, err
}
return &stellar1.Bundle{
Revision: 1,
Accounts: []stellar1.BundleEntry{
newEntry(accountID, name, false, stellar1.AccountMode_USER),
},
AccountBundles: map[stellar1.AccountID]stellar1.AccountBundle{
accountID: newAccountBundle(accountID, secretKey),
},
}, nil
} | go | func New(secret stellar1.SecretKey, name string) (*stellar1.Bundle, error) {
secretKey, accountID, _, err := libkb.ParseStellarSecretKey(string(secret))
if err != nil {
return nil, err
}
return &stellar1.Bundle{
Revision: 1,
Accounts: []stellar1.BundleEntry{
newEntry(accountID, name, false, stellar1.AccountMode_USER),
},
AccountBundles: map[stellar1.AccountID]stellar1.AccountBundle{
accountID: newAccountBundle(accountID, secretKey),
},
}, nil
} | [
"func",
"New",
"(",
"secret",
"stellar1",
".",
"SecretKey",
",",
"name",
"string",
")",
"(",
"*",
"stellar1",
".",
"Bundle",
",",
"error",
")",
"{",
"secretKey",
",",
"accountID",
",",
"_",
",",
"err",
":=",
"libkb",
".",
"ParseStellarSecretKey",
"(",
"string",
"(",
"secret",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"stellar1",
".",
"Bundle",
"{",
"Revision",
":",
"1",
",",
"Accounts",
":",
"[",
"]",
"stellar1",
".",
"BundleEntry",
"{",
"newEntry",
"(",
"accountID",
",",
"name",
",",
"false",
",",
"stellar1",
".",
"AccountMode_USER",
")",
",",
"}",
",",
"AccountBundles",
":",
"map",
"[",
"stellar1",
".",
"AccountID",
"]",
"stellar1",
".",
"AccountBundle",
"{",
"accountID",
":",
"newAccountBundle",
"(",
"accountID",
",",
"secretKey",
")",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // New creates a Bundle from an existing secret key. | [
"New",
"creates",
"a",
"Bundle",
"from",
"an",
"existing",
"secret",
"key",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/bundle/bundle.go#L13-L27 |
158,859 | keybase/client | go/stellar/bundle/bundle.go | NewInitial | func NewInitial(name string) (*stellar1.Bundle, error) {
full, err := keypair.Random()
if err != nil {
return nil, err
}
x, err := New(stellar1.SecretKey(full.Seed()), name)
if err != nil {
return nil, err
}
x.Accounts[0].IsPrimary = true
return x, nil
} | go | func NewInitial(name string) (*stellar1.Bundle, error) {
full, err := keypair.Random()
if err != nil {
return nil, err
}
x, err := New(stellar1.SecretKey(full.Seed()), name)
if err != nil {
return nil, err
}
x.Accounts[0].IsPrimary = true
return x, nil
} | [
"func",
"NewInitial",
"(",
"name",
"string",
")",
"(",
"*",
"stellar1",
".",
"Bundle",
",",
"error",
")",
"{",
"full",
",",
"err",
":=",
"keypair",
".",
"Random",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"x",
",",
"err",
":=",
"New",
"(",
"stellar1",
".",
"SecretKey",
"(",
"full",
".",
"Seed",
"(",
")",
")",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"x",
".",
"Accounts",
"[",
"0",
"]",
".",
"IsPrimary",
"=",
"true",
"\n\n",
"return",
"x",
",",
"nil",
"\n",
"}"
] | // NewInitial creates a Bundle with a new random secret key. | [
"NewInitial",
"creates",
"a",
"Bundle",
"with",
"a",
"new",
"random",
"secret",
"key",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/bundle/bundle.go#L30-L44 |
158,860 | keybase/client | go/stellar/bundle/bundle.go | MakeMobileOnly | func MakeMobileOnly(a *stellar1.Bundle, accountID stellar1.AccountID) error {
var found bool
for i, account := range a.Accounts {
if account.AccountID == accountID {
if account.Mode == stellar1.AccountMode_MOBILE {
return ErrNoChangeNecessary
}
account.Mode = stellar1.AccountMode_MOBILE
a.Accounts[i] = account
found = true
break
}
}
if !found {
return libkb.NotFoundError{}
}
return nil
} | go | func MakeMobileOnly(a *stellar1.Bundle, accountID stellar1.AccountID) error {
var found bool
for i, account := range a.Accounts {
if account.AccountID == accountID {
if account.Mode == stellar1.AccountMode_MOBILE {
return ErrNoChangeNecessary
}
account.Mode = stellar1.AccountMode_MOBILE
a.Accounts[i] = account
found = true
break
}
}
if !found {
return libkb.NotFoundError{}
}
return nil
} | [
"func",
"MakeMobileOnly",
"(",
"a",
"*",
"stellar1",
".",
"Bundle",
",",
"accountID",
"stellar1",
".",
"AccountID",
")",
"error",
"{",
"var",
"found",
"bool",
"\n",
"for",
"i",
",",
"account",
":=",
"range",
"a",
".",
"Accounts",
"{",
"if",
"account",
".",
"AccountID",
"==",
"accountID",
"{",
"if",
"account",
".",
"Mode",
"==",
"stellar1",
".",
"AccountMode_MOBILE",
"{",
"return",
"ErrNoChangeNecessary",
"\n",
"}",
"\n",
"account",
".",
"Mode",
"=",
"stellar1",
".",
"AccountMode_MOBILE",
"\n",
"a",
".",
"Accounts",
"[",
"i",
"]",
"=",
"account",
"\n",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"libkb",
".",
"NotFoundError",
"{",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // MakeMobileOnly transforms an account in a stellar1.Bundle into a mobile-only
// account. This advances the revision of the Bundle. If it's already mobile-only,
// this function will return ErrNoChangeNecessary. | [
"MakeMobileOnly",
"transforms",
"an",
"account",
"in",
"a",
"stellar1",
".",
"Bundle",
"into",
"a",
"mobile",
"-",
"only",
"account",
".",
"This",
"advances",
"the",
"revision",
"of",
"the",
"Bundle",
".",
"If",
"it",
"s",
"already",
"mobile",
"-",
"only",
"this",
"function",
"will",
"return",
"ErrNoChangeNecessary",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/bundle/bundle.go#L70-L87 |
158,861 | keybase/client | go/stellar/bundle/bundle.go | AccountWithSecret | func AccountWithSecret(bundle *stellar1.Bundle, accountID stellar1.AccountID) (*WithSecret, error) {
secret, ok := bundle.AccountBundles[accountID]
if !ok {
return nil, libkb.NotFoundError{}
}
// ugh
var found *stellar1.BundleEntry
for _, a := range bundle.Accounts {
if a.AccountID == accountID {
found = &a
break
}
}
if found == nil {
// this is bad: secret found but not visible portion
return nil, libkb.NotFoundError{}
}
return &WithSecret{
AccountID: found.AccountID,
Mode: found.Mode,
Name: found.Name,
Revision: found.AcctBundleRevision,
Signers: secret.Signers,
}, nil
} | go | func AccountWithSecret(bundle *stellar1.Bundle, accountID stellar1.AccountID) (*WithSecret, error) {
secret, ok := bundle.AccountBundles[accountID]
if !ok {
return nil, libkb.NotFoundError{}
}
// ugh
var found *stellar1.BundleEntry
for _, a := range bundle.Accounts {
if a.AccountID == accountID {
found = &a
break
}
}
if found == nil {
// this is bad: secret found but not visible portion
return nil, libkb.NotFoundError{}
}
return &WithSecret{
AccountID: found.AccountID,
Mode: found.Mode,
Name: found.Name,
Revision: found.AcctBundleRevision,
Signers: secret.Signers,
}, nil
} | [
"func",
"AccountWithSecret",
"(",
"bundle",
"*",
"stellar1",
".",
"Bundle",
",",
"accountID",
"stellar1",
".",
"AccountID",
")",
"(",
"*",
"WithSecret",
",",
"error",
")",
"{",
"secret",
",",
"ok",
":=",
"bundle",
".",
"AccountBundles",
"[",
"accountID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"libkb",
".",
"NotFoundError",
"{",
"}",
"\n",
"}",
"\n",
"// ugh",
"var",
"found",
"*",
"stellar1",
".",
"BundleEntry",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"bundle",
".",
"Accounts",
"{",
"if",
"a",
".",
"AccountID",
"==",
"accountID",
"{",
"found",
"=",
"&",
"a",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"found",
"==",
"nil",
"{",
"// this is bad: secret found but not visible portion",
"return",
"nil",
",",
"libkb",
".",
"NotFoundError",
"{",
"}",
"\n",
"}",
"\n",
"return",
"&",
"WithSecret",
"{",
"AccountID",
":",
"found",
".",
"AccountID",
",",
"Mode",
":",
"found",
".",
"Mode",
",",
"Name",
":",
"found",
".",
"Name",
",",
"Revision",
":",
"found",
".",
"AcctBundleRevision",
",",
"Signers",
":",
"secret",
".",
"Signers",
",",
"}",
",",
"nil",
"\n",
"}"
] | // AccountWithSecret finds an account in bundle and its associated secret
// and extracts them into a convenience type bundle.WithSecret.
// It will return libkb.NotFoundError if it can't find the secret or the
// account in the bundle. | [
"AccountWithSecret",
"finds",
"an",
"account",
"in",
"bundle",
"and",
"its",
"associated",
"secret",
"and",
"extracts",
"them",
"into",
"a",
"convenience",
"type",
"bundle",
".",
"WithSecret",
".",
"It",
"will",
"return",
"libkb",
".",
"NotFoundError",
"if",
"it",
"can",
"t",
"find",
"the",
"secret",
"or",
"the",
"account",
"in",
"the",
"bundle",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/bundle/bundle.go#L125-L149 |
158,862 | keybase/client | go/stellar/bundle/bundle.go | AdvanceBundle | func AdvanceBundle(prevBundle stellar1.Bundle) stellar1.Bundle {
nextBundle := prevBundle.DeepCopy()
nextBundle.Prev = nextBundle.OwnHash
nextBundle.OwnHash = nil
nextBundle.Revision++
return nextBundle
} | go | func AdvanceBundle(prevBundle stellar1.Bundle) stellar1.Bundle {
nextBundle := prevBundle.DeepCopy()
nextBundle.Prev = nextBundle.OwnHash
nextBundle.OwnHash = nil
nextBundle.Revision++
return nextBundle
} | [
"func",
"AdvanceBundle",
"(",
"prevBundle",
"stellar1",
".",
"Bundle",
")",
"stellar1",
".",
"Bundle",
"{",
"nextBundle",
":=",
"prevBundle",
".",
"DeepCopy",
"(",
")",
"\n",
"nextBundle",
".",
"Prev",
"=",
"nextBundle",
".",
"OwnHash",
"\n",
"nextBundle",
".",
"OwnHash",
"=",
"nil",
"\n",
"nextBundle",
".",
"Revision",
"++",
"\n",
"return",
"nextBundle",
"\n",
"}"
] | // AdvanceBundle only advances the revisions and hashes on the Bundle
// and not on the accounts. This is useful for adding and removing accounts
// but not for changing them. | [
"AdvanceBundle",
"only",
"advances",
"the",
"revisions",
"and",
"hashes",
"on",
"the",
"Bundle",
"and",
"not",
"on",
"the",
"accounts",
".",
"This",
"is",
"useful",
"for",
"adding",
"and",
"removing",
"accounts",
"but",
"not",
"for",
"changing",
"them",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/bundle/bundle.go#L154-L160 |
158,863 | keybase/client | go/stellar/bundle/bundle.go | AddAccount | func AddAccount(bundle *stellar1.Bundle, secretKey stellar1.SecretKey, name string, makePrimary bool) (err error) {
if bundle == nil {
return fmt.Errorf("nil bundle")
}
secretKey, accountID, _, err := libkb.ParseStellarSecretKey(string(secretKey))
if err != nil {
return err
}
if name == "" {
return fmt.Errorf("Name required for new account")
}
if makePrimary {
for i := range bundle.Accounts {
bundle.Accounts[i].IsPrimary = false
}
}
bundle.Accounts = append(bundle.Accounts, stellar1.BundleEntry{
AccountID: accountID,
Mode: stellar1.AccountMode_USER,
IsPrimary: makePrimary,
AcctBundleRevision: 1,
Name: name,
})
bundle.AccountBundles[accountID] = stellar1.AccountBundle{
AccountID: accountID,
Signers: []stellar1.SecretKey{secretKey},
}
return bundle.CheckInvariants()
} | go | func AddAccount(bundle *stellar1.Bundle, secretKey stellar1.SecretKey, name string, makePrimary bool) (err error) {
if bundle == nil {
return fmt.Errorf("nil bundle")
}
secretKey, accountID, _, err := libkb.ParseStellarSecretKey(string(secretKey))
if err != nil {
return err
}
if name == "" {
return fmt.Errorf("Name required for new account")
}
if makePrimary {
for i := range bundle.Accounts {
bundle.Accounts[i].IsPrimary = false
}
}
bundle.Accounts = append(bundle.Accounts, stellar1.BundleEntry{
AccountID: accountID,
Mode: stellar1.AccountMode_USER,
IsPrimary: makePrimary,
AcctBundleRevision: 1,
Name: name,
})
bundle.AccountBundles[accountID] = stellar1.AccountBundle{
AccountID: accountID,
Signers: []stellar1.SecretKey{secretKey},
}
return bundle.CheckInvariants()
} | [
"func",
"AddAccount",
"(",
"bundle",
"*",
"stellar1",
".",
"Bundle",
",",
"secretKey",
"stellar1",
".",
"SecretKey",
",",
"name",
"string",
",",
"makePrimary",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"if",
"bundle",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"secretKey",
",",
"accountID",
",",
"_",
",",
"err",
":=",
"libkb",
".",
"ParseStellarSecretKey",
"(",
"string",
"(",
"secretKey",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"name",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"makePrimary",
"{",
"for",
"i",
":=",
"range",
"bundle",
".",
"Accounts",
"{",
"bundle",
".",
"Accounts",
"[",
"i",
"]",
".",
"IsPrimary",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"bundle",
".",
"Accounts",
"=",
"append",
"(",
"bundle",
".",
"Accounts",
",",
"stellar1",
".",
"BundleEntry",
"{",
"AccountID",
":",
"accountID",
",",
"Mode",
":",
"stellar1",
".",
"AccountMode_USER",
",",
"IsPrimary",
":",
"makePrimary",
",",
"AcctBundleRevision",
":",
"1",
",",
"Name",
":",
"name",
",",
"}",
")",
"\n",
"bundle",
".",
"AccountBundles",
"[",
"accountID",
"]",
"=",
"stellar1",
".",
"AccountBundle",
"{",
"AccountID",
":",
"accountID",
",",
"Signers",
":",
"[",
"]",
"stellar1",
".",
"SecretKey",
"{",
"secretKey",
"}",
",",
"}",
"\n",
"return",
"bundle",
".",
"CheckInvariants",
"(",
")",
"\n",
"}"
] | // AddAccount adds an account to the bundle. Mutates `bundle`. | [
"AddAccount",
"adds",
"an",
"account",
"to",
"the",
"bundle",
".",
"Mutates",
"bundle",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/bundle/bundle.go#L187-L215 |
158,864 | keybase/client | go/stellar/bundle/bundle.go | CreateNewAccount | func CreateNewAccount(bundle *stellar1.Bundle, name string, makePrimary bool) (pub stellar1.AccountID, err error) {
accountID, masterKey, err := randomStellarKeypair()
if err != nil {
return pub, err
}
if err := AddAccount(bundle, masterKey, name, makePrimary); err != nil {
return pub, err
}
return accountID, nil
} | go | func CreateNewAccount(bundle *stellar1.Bundle, name string, makePrimary bool) (pub stellar1.AccountID, err error) {
accountID, masterKey, err := randomStellarKeypair()
if err != nil {
return pub, err
}
if err := AddAccount(bundle, masterKey, name, makePrimary); err != nil {
return pub, err
}
return accountID, nil
} | [
"func",
"CreateNewAccount",
"(",
"bundle",
"*",
"stellar1",
".",
"Bundle",
",",
"name",
"string",
",",
"makePrimary",
"bool",
")",
"(",
"pub",
"stellar1",
".",
"AccountID",
",",
"err",
"error",
")",
"{",
"accountID",
",",
"masterKey",
",",
"err",
":=",
"randomStellarKeypair",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"pub",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"AddAccount",
"(",
"bundle",
",",
"masterKey",
",",
"name",
",",
"makePrimary",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"pub",
",",
"err",
"\n",
"}",
"\n",
"return",
"accountID",
",",
"nil",
"\n",
"}"
] | // CreateNewAccount generates a Stellar key pair and adds it to the
// bundle. Mutates `bundle`. | [
"CreateNewAccount",
"generates",
"a",
"Stellar",
"key",
"pair",
"and",
"adds",
"it",
"to",
"the",
"bundle",
".",
"Mutates",
"bundle",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/bundle/bundle.go#L219-L228 |
158,865 | keybase/client | go/chat/search/indexer.go | validBatch | func (idx *Indexer) validBatch(msgs []chat1.MessageUnboxed) bool {
if len(msgs) == 0 {
return false
}
for _, msg := range msgs {
switch msg.GetTopicType() {
case chat1.TopicType_CHAT:
return true
case chat1.TopicType_NONE:
continue
default:
return false
}
}
// if we only have TopicType_NONE, assume it's ok to return true so we
// document the seen ids properly.
return true
} | go | func (idx *Indexer) validBatch(msgs []chat1.MessageUnboxed) bool {
if len(msgs) == 0 {
return false
}
for _, msg := range msgs {
switch msg.GetTopicType() {
case chat1.TopicType_CHAT:
return true
case chat1.TopicType_NONE:
continue
default:
return false
}
}
// if we only have TopicType_NONE, assume it's ok to return true so we
// document the seen ids properly.
return true
} | [
"func",
"(",
"idx",
"*",
"Indexer",
")",
"validBatch",
"(",
"msgs",
"[",
"]",
"chat1",
".",
"MessageUnboxed",
")",
"bool",
"{",
"if",
"len",
"(",
"msgs",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"msg",
":=",
"range",
"msgs",
"{",
"switch",
"msg",
".",
"GetTopicType",
"(",
")",
"{",
"case",
"chat1",
".",
"TopicType_CHAT",
":",
"return",
"true",
"\n",
"case",
"chat1",
".",
"TopicType_NONE",
":",
"continue",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"// if we only have TopicType_NONE, assume it's ok to return true so we",
"// document the seen ids properly.",
"return",
"true",
"\n",
"}"
] | // validBatch verifies the topic type is CHAT | [
"validBatch",
"verifies",
"the",
"topic",
"type",
"is",
"CHAT"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/search/indexer.go#L207-L225 |
158,866 | keybase/client | go/chat/search/indexer.go | Search | func (idx *Indexer) Search(ctx context.Context, uid gregor1.UID, query, origQuery string,
opts chat1.SearchOpts, hitUICh chan chat1.ChatSearchInboxHit, indexUICh chan chat1.ChatSearchIndexStatus) (res *chat1.ChatSearchInboxResults, err error) {
defer idx.Trace(ctx, func() error { return err }, "Indexer.Search")()
defer func() {
// get a selective sync to run after the search completes even if we
// errored.
idx.PokeSync(ctx)
if hitUICh != nil {
close(hitUICh)
}
if indexUICh != nil {
close(indexUICh)
}
}()
if idx.G().GetEnv().GetDisableSearchIndexer() {
idx.Debug(ctx, "Search: Search indexer is disabled, results will be inaccurate.")
}
idx.CancelSync(ctx)
sess := newSearchSession(query, origQuery, uid, hitUICh, indexUICh, idx, opts)
return sess.run(ctx)
} | go | func (idx *Indexer) Search(ctx context.Context, uid gregor1.UID, query, origQuery string,
opts chat1.SearchOpts, hitUICh chan chat1.ChatSearchInboxHit, indexUICh chan chat1.ChatSearchIndexStatus) (res *chat1.ChatSearchInboxResults, err error) {
defer idx.Trace(ctx, func() error { return err }, "Indexer.Search")()
defer func() {
// get a selective sync to run after the search completes even if we
// errored.
idx.PokeSync(ctx)
if hitUICh != nil {
close(hitUICh)
}
if indexUICh != nil {
close(indexUICh)
}
}()
if idx.G().GetEnv().GetDisableSearchIndexer() {
idx.Debug(ctx, "Search: Search indexer is disabled, results will be inaccurate.")
}
idx.CancelSync(ctx)
sess := newSearchSession(query, origQuery, uid, hitUICh, indexUICh, idx, opts)
return sess.run(ctx)
} | [
"func",
"(",
"idx",
"*",
"Indexer",
")",
"Search",
"(",
"ctx",
"context",
".",
"Context",
",",
"uid",
"gregor1",
".",
"UID",
",",
"query",
",",
"origQuery",
"string",
",",
"opts",
"chat1",
".",
"SearchOpts",
",",
"hitUICh",
"chan",
"chat1",
".",
"ChatSearchInboxHit",
",",
"indexUICh",
"chan",
"chat1",
".",
"ChatSearchIndexStatus",
")",
"(",
"res",
"*",
"chat1",
".",
"ChatSearchInboxResults",
",",
"err",
"error",
")",
"{",
"defer",
"idx",
".",
"Trace",
"(",
"ctx",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
",",
"\"",
"\"",
")",
"(",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"// get a selective sync to run after the search completes even if we",
"// errored.",
"idx",
".",
"PokeSync",
"(",
"ctx",
")",
"\n\n",
"if",
"hitUICh",
"!=",
"nil",
"{",
"close",
"(",
"hitUICh",
")",
"\n",
"}",
"\n",
"if",
"indexUICh",
"!=",
"nil",
"{",
"close",
"(",
"indexUICh",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"if",
"idx",
".",
"G",
"(",
")",
".",
"GetEnv",
"(",
")",
".",
"GetDisableSearchIndexer",
"(",
")",
"{",
"idx",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"idx",
".",
"CancelSync",
"(",
"ctx",
")",
"\n",
"sess",
":=",
"newSearchSession",
"(",
"query",
",",
"origQuery",
",",
"uid",
",",
"hitUICh",
",",
"indexUICh",
",",
"idx",
",",
"opts",
")",
"\n",
"return",
"sess",
".",
"run",
"(",
"ctx",
")",
"\n",
"}"
] | // Search tokenizes the given query and finds the intersection of all matches
// for each token, returning matches. | [
"Search",
"tokenizes",
"the",
"given",
"query",
"and",
"finds",
"the",
"intersection",
"of",
"all",
"matches",
"for",
"each",
"token",
"returning",
"matches",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/search/indexer.go#L431-L453 |
158,867 | keybase/client | go/chat/search/indexer.go | SelectiveSync | func (idx *Indexer) SelectiveSync(ctx context.Context, uid gregor1.UID) (err error) {
defer idx.Trace(ctx, func() error { return err }, "SelectiveSync")()
convMap, err := idx.allConvs(ctx, uid, nil)
if err != nil {
return err
}
// make sure the most recently modified convs are fully indexed
convs := idx.convsByMTime(ctx, uid, convMap)
// number of batches of messages to fetch in total
numJobs := idx.maxSyncConvs
for _, conv := range convs {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
convID := conv.GetConvID()
md, err := idx.store.GetMetadata(ctx, uid, convID)
if err != nil {
idx.Debug(ctx, "SelectiveSync: Unable to get md for conv: %v, %v", convID, err)
continue
}
if md.FullyIndexed(conv.Conv) {
continue
}
completedJobs, err := idx.reindexConv(ctx, conv, uid, numJobs, nil)
if err != nil {
idx.Debug(ctx, "Unable to reindex conv: %v, %v", convID, err)
continue
} else if completedJobs == 0 {
continue
}
idx.Debug(ctx, "SelectiveSync: Indexed completed jobs %d", completedJobs)
numJobs -= completedJobs
if numJobs <= 0 {
break
}
}
return nil
} | go | func (idx *Indexer) SelectiveSync(ctx context.Context, uid gregor1.UID) (err error) {
defer idx.Trace(ctx, func() error { return err }, "SelectiveSync")()
convMap, err := idx.allConvs(ctx, uid, nil)
if err != nil {
return err
}
// make sure the most recently modified convs are fully indexed
convs := idx.convsByMTime(ctx, uid, convMap)
// number of batches of messages to fetch in total
numJobs := idx.maxSyncConvs
for _, conv := range convs {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
convID := conv.GetConvID()
md, err := idx.store.GetMetadata(ctx, uid, convID)
if err != nil {
idx.Debug(ctx, "SelectiveSync: Unable to get md for conv: %v, %v", convID, err)
continue
}
if md.FullyIndexed(conv.Conv) {
continue
}
completedJobs, err := idx.reindexConv(ctx, conv, uid, numJobs, nil)
if err != nil {
idx.Debug(ctx, "Unable to reindex conv: %v, %v", convID, err)
continue
} else if completedJobs == 0 {
continue
}
idx.Debug(ctx, "SelectiveSync: Indexed completed jobs %d", completedJobs)
numJobs -= completedJobs
if numJobs <= 0 {
break
}
}
return nil
} | [
"func",
"(",
"idx",
"*",
"Indexer",
")",
"SelectiveSync",
"(",
"ctx",
"context",
".",
"Context",
",",
"uid",
"gregor1",
".",
"UID",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"idx",
".",
"Trace",
"(",
"ctx",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
",",
"\"",
"\"",
")",
"(",
")",
"\n\n",
"convMap",
",",
"err",
":=",
"idx",
".",
"allConvs",
"(",
"ctx",
",",
"uid",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// make sure the most recently modified convs are fully indexed",
"convs",
":=",
"idx",
".",
"convsByMTime",
"(",
"ctx",
",",
"uid",
",",
"convMap",
")",
"\n",
"// number of batches of messages to fetch in total",
"numJobs",
":=",
"idx",
".",
"maxSyncConvs",
"\n",
"for",
"_",
",",
"conv",
":=",
"range",
"convs",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"ctx",
".",
"Err",
"(",
")",
"\n",
"default",
":",
"}",
"\n",
"convID",
":=",
"conv",
".",
"GetConvID",
"(",
")",
"\n",
"md",
",",
"err",
":=",
"idx",
".",
"store",
".",
"GetMetadata",
"(",
"ctx",
",",
"uid",
",",
"convID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"idx",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"convID",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"md",
".",
"FullyIndexed",
"(",
"conv",
".",
"Conv",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"completedJobs",
",",
"err",
":=",
"idx",
".",
"reindexConv",
"(",
"ctx",
",",
"conv",
",",
"uid",
",",
"numJobs",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"idx",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"convID",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"else",
"if",
"completedJobs",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"idx",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"completedJobs",
")",
"\n",
"numJobs",
"-=",
"completedJobs",
"\n",
"if",
"numJobs",
"<=",
"0",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SelectiveSync queues up a small number of jobs on the background loader
// periodically so our index can cover all conversations. The number of jobs
// varies between desktop and mobile so mobile can be more conservative. | [
"SelectiveSync",
"queues",
"up",
"a",
"small",
"number",
"of",
"jobs",
"on",
"the",
"background",
"loader",
"periodically",
"so",
"our",
"index",
"can",
"cover",
"all",
"conversations",
".",
"The",
"number",
"of",
"jobs",
"varies",
"between",
"desktop",
"and",
"mobile",
"so",
"mobile",
"can",
"be",
"more",
"conservative",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/search/indexer.go#L458-L500 |
158,868 | keybase/client | go/kbnm/hostmanifest/user.go | CurrentUser | func CurrentUser() (*UserPath, error) {
current, err := user.Current()
if err != nil {
return nil, err
}
u := &UserPath{
Admin: current.Uid == "0",
}
if !u.IsAdmin() {
u.Path = current.HomeDir
}
return u, nil
} | go | func CurrentUser() (*UserPath, error) {
current, err := user.Current()
if err != nil {
return nil, err
}
u := &UserPath{
Admin: current.Uid == "0",
}
if !u.IsAdmin() {
u.Path = current.HomeDir
}
return u, nil
} | [
"func",
"CurrentUser",
"(",
")",
"(",
"*",
"UserPath",
",",
"error",
")",
"{",
"current",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"u",
":=",
"&",
"UserPath",
"{",
"Admin",
":",
"current",
".",
"Uid",
"==",
"\"",
"\"",
",",
"}",
"\n",
"if",
"!",
"u",
".",
"IsAdmin",
"(",
")",
"{",
"u",
".",
"Path",
"=",
"current",
".",
"HomeDir",
"\n",
"}",
"\n",
"return",
"u",
",",
"nil",
"\n",
"}"
] | // CurrentUser returns a UserPath representing the current user. | [
"CurrentUser",
"returns",
"a",
"UserPath",
"representing",
"the",
"current",
"user",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/hostmanifest/user.go#L28-L40 |
158,869 | keybase/client | go/kbfs/tlf/utils.go | SplitAndNormalizeTLFName | func SplitAndNormalizeTLFName(g *libkb.GlobalContext, name string, public bool) (
writerNames, readerNames []string,
extensionSuffix string, err error) {
names := strings.SplitN(name, TlfHandleExtensionSep, 2)
if len(names) > 2 {
return nil, nil, "", BadTLFNameError{name}
}
if len(names) > 1 {
extensionSuffix = names[1]
}
splitNames := strings.SplitN(names[0], ReaderSep, 3)
if len(splitNames) > 2 {
return nil, nil, "", BadTLFNameError{name}
}
writerNames = strings.Split(splitNames[0], ",")
if len(splitNames) > 1 {
readerNames = strings.Split(splitNames[1], ",")
}
hasPublic := len(readerNames) == 0
if public && !hasPublic {
// No public folder exists for this folder.
return nil, nil, "", NoSuchNameError{Name: name}
}
normalizedName, err := NormalizeNamesInTLF(g,
writerNames, readerNames, extensionSuffix)
if err != nil {
return nil, nil, "", err
}
if normalizedName != name {
return nil, nil, "", NameNotCanonical{name, normalizedName}
}
return writerNames, readerNames, strings.ToLower(extensionSuffix), nil
} | go | func SplitAndNormalizeTLFName(g *libkb.GlobalContext, name string, public bool) (
writerNames, readerNames []string,
extensionSuffix string, err error) {
names := strings.SplitN(name, TlfHandleExtensionSep, 2)
if len(names) > 2 {
return nil, nil, "", BadTLFNameError{name}
}
if len(names) > 1 {
extensionSuffix = names[1]
}
splitNames := strings.SplitN(names[0], ReaderSep, 3)
if len(splitNames) > 2 {
return nil, nil, "", BadTLFNameError{name}
}
writerNames = strings.Split(splitNames[0], ",")
if len(splitNames) > 1 {
readerNames = strings.Split(splitNames[1], ",")
}
hasPublic := len(readerNames) == 0
if public && !hasPublic {
// No public folder exists for this folder.
return nil, nil, "", NoSuchNameError{Name: name}
}
normalizedName, err := NormalizeNamesInTLF(g,
writerNames, readerNames, extensionSuffix)
if err != nil {
return nil, nil, "", err
}
if normalizedName != name {
return nil, nil, "", NameNotCanonical{name, normalizedName}
}
return writerNames, readerNames, strings.ToLower(extensionSuffix), nil
} | [
"func",
"SplitAndNormalizeTLFName",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"name",
"string",
",",
"public",
"bool",
")",
"(",
"writerNames",
",",
"readerNames",
"[",
"]",
"string",
",",
"extensionSuffix",
"string",
",",
"err",
"error",
")",
"{",
"names",
":=",
"strings",
".",
"SplitN",
"(",
"name",
",",
"TlfHandleExtensionSep",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"names",
")",
">",
"2",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"BadTLFNameError",
"{",
"name",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"names",
")",
">",
"1",
"{",
"extensionSuffix",
"=",
"names",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"splitNames",
":=",
"strings",
".",
"SplitN",
"(",
"names",
"[",
"0",
"]",
",",
"ReaderSep",
",",
"3",
")",
"\n",
"if",
"len",
"(",
"splitNames",
")",
">",
"2",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"BadTLFNameError",
"{",
"name",
"}",
"\n",
"}",
"\n",
"writerNames",
"=",
"strings",
".",
"Split",
"(",
"splitNames",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"splitNames",
")",
">",
"1",
"{",
"readerNames",
"=",
"strings",
".",
"Split",
"(",
"splitNames",
"[",
"1",
"]",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"hasPublic",
":=",
"len",
"(",
"readerNames",
")",
"==",
"0",
"\n\n",
"if",
"public",
"&&",
"!",
"hasPublic",
"{",
"// No public folder exists for this folder.",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"NoSuchNameError",
"{",
"Name",
":",
"name",
"}",
"\n",
"}",
"\n\n",
"normalizedName",
",",
"err",
":=",
"NormalizeNamesInTLF",
"(",
"g",
",",
"writerNames",
",",
"readerNames",
",",
"extensionSuffix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"normalizedName",
"!=",
"name",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"NameNotCanonical",
"{",
"name",
",",
"normalizedName",
"}",
"\n",
"}",
"\n\n",
"return",
"writerNames",
",",
"readerNames",
",",
"strings",
".",
"ToLower",
"(",
"extensionSuffix",
")",
",",
"nil",
"\n",
"}"
] | // SplitAndNormalizeTLFName returns separate lists of normalized
// writer and reader names, as well as the extension suffix, of the
// given `name`. | [
"SplitAndNormalizeTLFName",
"returns",
"separate",
"lists",
"of",
"normalized",
"writer",
"and",
"reader",
"names",
"as",
"well",
"as",
"the",
"extension",
"suffix",
"of",
"the",
"given",
"name",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/utils.go#L31-L69 |
158,870 | keybase/client | go/kbfs/tlf/utils.go | NormalizeNamesInTLF | func NormalizeNamesInTLF(g *libkb.GlobalContext, writerNames, readerNames []string,
extensionSuffix string) (string, error) {
sortedWriterNames := make([]string, len(writerNames))
var err error
for i, w := range writerNames {
sortedWriterNames[i], err = NormalizeAssertionOrName(g, w)
if err != nil {
return "", err
}
}
sort.Strings(sortedWriterNames)
normalizedName := strings.Join(sortedWriterNames, ",")
if len(readerNames) > 0 {
sortedReaderNames := make([]string, len(readerNames))
for i, r := range readerNames {
sortedReaderNames[i], err = NormalizeAssertionOrName(g, r)
if err != nil {
return "", err
}
}
sort.Strings(sortedReaderNames)
normalizedName += ReaderSep + strings.Join(sortedReaderNames, ",")
}
if len(extensionSuffix) != 0 {
// This *should* be normalized already but make sure. I can see not
// doing so might surprise a caller.
normalizedName += TlfHandleExtensionSep + strings.ToLower(extensionSuffix)
}
return normalizedName, nil
} | go | func NormalizeNamesInTLF(g *libkb.GlobalContext, writerNames, readerNames []string,
extensionSuffix string) (string, error) {
sortedWriterNames := make([]string, len(writerNames))
var err error
for i, w := range writerNames {
sortedWriterNames[i], err = NormalizeAssertionOrName(g, w)
if err != nil {
return "", err
}
}
sort.Strings(sortedWriterNames)
normalizedName := strings.Join(sortedWriterNames, ",")
if len(readerNames) > 0 {
sortedReaderNames := make([]string, len(readerNames))
for i, r := range readerNames {
sortedReaderNames[i], err = NormalizeAssertionOrName(g, r)
if err != nil {
return "", err
}
}
sort.Strings(sortedReaderNames)
normalizedName += ReaderSep + strings.Join(sortedReaderNames, ",")
}
if len(extensionSuffix) != 0 {
// This *should* be normalized already but make sure. I can see not
// doing so might surprise a caller.
normalizedName += TlfHandleExtensionSep + strings.ToLower(extensionSuffix)
}
return normalizedName, nil
} | [
"func",
"NormalizeNamesInTLF",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"writerNames",
",",
"readerNames",
"[",
"]",
"string",
",",
"extensionSuffix",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"sortedWriterNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"writerNames",
")",
")",
"\n",
"var",
"err",
"error",
"\n",
"for",
"i",
",",
"w",
":=",
"range",
"writerNames",
"{",
"sortedWriterNames",
"[",
"i",
"]",
",",
"err",
"=",
"NormalizeAssertionOrName",
"(",
"g",
",",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"sortedWriterNames",
")",
"\n",
"normalizedName",
":=",
"strings",
".",
"Join",
"(",
"sortedWriterNames",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"readerNames",
")",
">",
"0",
"{",
"sortedReaderNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"readerNames",
")",
")",
"\n",
"for",
"i",
",",
"r",
":=",
"range",
"readerNames",
"{",
"sortedReaderNames",
"[",
"i",
"]",
",",
"err",
"=",
"NormalizeAssertionOrName",
"(",
"g",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"sortedReaderNames",
")",
"\n",
"normalizedName",
"+=",
"ReaderSep",
"+",
"strings",
".",
"Join",
"(",
"sortedReaderNames",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"extensionSuffix",
")",
"!=",
"0",
"{",
"// This *should* be normalized already but make sure. I can see not",
"// doing so might surprise a caller.",
"normalizedName",
"+=",
"TlfHandleExtensionSep",
"+",
"strings",
".",
"ToLower",
"(",
"extensionSuffix",
")",
"\n",
"}",
"\n\n",
"return",
"normalizedName",
",",
"nil",
"\n",
"}"
] | // NormalizeNamesInTLF takes a split TLF name and, without doing any
// resolutions or identify calls, normalizes all elements of the
// name. It then returns the normalized name. | [
"NormalizeNamesInTLF",
"takes",
"a",
"split",
"TLF",
"name",
"and",
"without",
"doing",
"any",
"resolutions",
"or",
"identify",
"calls",
"normalizes",
"all",
"elements",
"of",
"the",
"name",
".",
"It",
"then",
"returns",
"the",
"normalized",
"name",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/utils.go#L74-L104 |
158,871 | keybase/client | go/kbfs/tlf/utils.go | ToStatus | func (e NoSuchUserError) ToStatus() keybase1.Status {
return keybase1.Status{
Name: "NotFound",
Code: int(keybase1.StatusCode_SCNotFound),
Desc: e.Error(),
}
} | go | func (e NoSuchUserError) ToStatus() keybase1.Status {
return keybase1.Status{
Name: "NotFound",
Code: int(keybase1.StatusCode_SCNotFound),
Desc: e.Error(),
}
} | [
"func",
"(",
"e",
"NoSuchUserError",
")",
"ToStatus",
"(",
")",
"keybase1",
".",
"Status",
"{",
"return",
"keybase1",
".",
"Status",
"{",
"Name",
":",
"\"",
"\"",
",",
"Code",
":",
"int",
"(",
"keybase1",
".",
"StatusCode_SCNotFound",
")",
",",
"Desc",
":",
"e",
".",
"Error",
"(",
")",
",",
"}",
"\n",
"}"
] | // ToStatus implements the keybase1.ToStatusAble interface for NoSuchUserError | [
"ToStatus",
"implements",
"the",
"keybase1",
".",
"ToStatusAble",
"interface",
"for",
"NoSuchUserError"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/utils.go#L186-L192 |
158,872 | keybase/client | go/libkb/util_nix.go | SafeWriteToFile | func SafeWriteToFile(g SafeWriteLogger, t SafeWriter, mode os.FileMode) error {
return safeWriteToFileOnce(g, t, mode)
} | go | func SafeWriteToFile(g SafeWriteLogger, t SafeWriter, mode os.FileMode) error {
return safeWriteToFileOnce(g, t, mode)
} | [
"func",
"SafeWriteToFile",
"(",
"g",
"SafeWriteLogger",
",",
"t",
"SafeWriter",
",",
"mode",
"os",
".",
"FileMode",
")",
"error",
"{",
"return",
"safeWriteToFileOnce",
"(",
"g",
",",
"t",
",",
"mode",
")",
"\n",
"}"
] | // SafeWriteToFile is a pass-through to safeWriteToFileOnce on non-Windows. | [
"SafeWriteToFile",
"is",
"a",
"pass",
"-",
"through",
"to",
"safeWriteToFileOnce",
"on",
"non",
"-",
"Windows",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/util_nix.go#L55-L57 |
158,873 | keybase/client | go/engine/pgp_import_key.go | checkPregenPrivate | func (e *PGPKeyImportEngine) checkPregenPrivate() error {
if e.arg.Pregen == nil {
return nil
}
if e.arg.Pregen.HasSecretKey() || e.arg.GPGFallback {
return nil
}
return libkb.NoSecretKeyError{}
} | go | func (e *PGPKeyImportEngine) checkPregenPrivate() error {
if e.arg.Pregen == nil {
return nil
}
if e.arg.Pregen.HasSecretKey() || e.arg.GPGFallback {
return nil
}
return libkb.NoSecretKeyError{}
} | [
"func",
"(",
"e",
"*",
"PGPKeyImportEngine",
")",
"checkPregenPrivate",
"(",
")",
"error",
"{",
"if",
"e",
".",
"arg",
".",
"Pregen",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"e",
".",
"arg",
".",
"Pregen",
".",
"HasSecretKey",
"(",
")",
"||",
"e",
".",
"arg",
".",
"GPGFallback",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"libkb",
".",
"NoSecretKeyError",
"{",
"}",
"\n",
"}"
] | // checkPregenPrivate makes sure that the pregenerated key is a
// private key. | [
"checkPregenPrivate",
"makes",
"sure",
"that",
"the",
"pregenerated",
"key",
"is",
"a",
"private",
"key",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/pgp_import_key.go#L140-L148 |
158,874 | keybase/client | go/engine/pgp_import_key.go | clonePGPKeyBundle | func clonePGPKeyBundle(bundle *libkb.PGPKeyBundle) (*libkb.PGPKeyBundle, error) {
var buf bytes.Buffer
if err := bundle.SerializePrivate(&buf); err != nil {
return nil, err
}
res, _, err := libkb.ReadOneKeyFromBytes(buf.Bytes())
if err != nil {
return nil, err
}
return res, nil
} | go | func clonePGPKeyBundle(bundle *libkb.PGPKeyBundle) (*libkb.PGPKeyBundle, error) {
var buf bytes.Buffer
if err := bundle.SerializePrivate(&buf); err != nil {
return nil, err
}
res, _, err := libkb.ReadOneKeyFromBytes(buf.Bytes())
if err != nil {
return nil, err
}
return res, nil
} | [
"func",
"clonePGPKeyBundle",
"(",
"bundle",
"*",
"libkb",
".",
"PGPKeyBundle",
")",
"(",
"*",
"libkb",
".",
"PGPKeyBundle",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"bundle",
".",
"SerializePrivate",
"(",
"&",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"res",
",",
"_",
",",
"err",
":=",
"libkb",
".",
"ReadOneKeyFromBytes",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] | // clonePGPKeyBundle returns an approximate deep copy of PGPKeyBundle
// by exporting and re-importing PGPKeyBundle. If PGP key contains
// something that is not supported by either go-crypto exporter or
// importer, that information will be lost. | [
"clonePGPKeyBundle",
"returns",
"an",
"approximate",
"deep",
"copy",
"of",
"PGPKeyBundle",
"by",
"exporting",
"and",
"re",
"-",
"importing",
"PGPKeyBundle",
".",
"If",
"PGP",
"key",
"contains",
"something",
"that",
"is",
"not",
"supported",
"by",
"either",
"go",
"-",
"crypto",
"exporter",
"or",
"importer",
"that",
"information",
"will",
"be",
"lost",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/pgp_import_key.go#L258-L268 |
158,875 | keybase/client | go/kbfs/libkbfs/modes.go | NewInitModeFromType | func NewInitModeFromType(t InitModeType) InitMode {
switch t {
case InitDefault:
return modeDefault{}
case InitMinimal:
return modeMinimal{}
case InitSingleOp:
return modeSingleOp{modeDefault{}}
case InitConstrained:
return modeConstrained{modeDefault{}}
case InitMemoryLimited:
return modeMemoryLimited{modeConstrained{modeDefault{}}}
default:
panic(fmt.Sprintf("Unknown mode: %s", t))
}
} | go | func NewInitModeFromType(t InitModeType) InitMode {
switch t {
case InitDefault:
return modeDefault{}
case InitMinimal:
return modeMinimal{}
case InitSingleOp:
return modeSingleOp{modeDefault{}}
case InitConstrained:
return modeConstrained{modeDefault{}}
case InitMemoryLimited:
return modeMemoryLimited{modeConstrained{modeDefault{}}}
default:
panic(fmt.Sprintf("Unknown mode: %s", t))
}
} | [
"func",
"NewInitModeFromType",
"(",
"t",
"InitModeType",
")",
"InitMode",
"{",
"switch",
"t",
"{",
"case",
"InitDefault",
":",
"return",
"modeDefault",
"{",
"}",
"\n",
"case",
"InitMinimal",
":",
"return",
"modeMinimal",
"{",
"}",
"\n",
"case",
"InitSingleOp",
":",
"return",
"modeSingleOp",
"{",
"modeDefault",
"{",
"}",
"}",
"\n",
"case",
"InitConstrained",
":",
"return",
"modeConstrained",
"{",
"modeDefault",
"{",
"}",
"}",
"\n",
"case",
"InitMemoryLimited",
":",
"return",
"modeMemoryLimited",
"{",
"modeConstrained",
"{",
"modeDefault",
"{",
"}",
"}",
"}",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
")",
")",
"\n",
"}",
"\n",
"}"
] | // NewInitModeFromType returns an InitMode object corresponding to the
// given type. | [
"NewInitModeFromType",
"returns",
"an",
"InitMode",
"object",
"corresponding",
"to",
"the",
"given",
"type",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/modes.go#L17-L32 |
158,876 | keybase/client | go/libkb/usercard_cache.go | NewUserCardCache | func NewUserCardCache(maxAge time.Duration) *UserCardCache {
c := &UserCardCache{
cache: ramcache.New(),
}
c.cache.MaxAge = maxAge
c.cache.TTL = maxAge
return c
} | go | func NewUserCardCache(maxAge time.Duration) *UserCardCache {
c := &UserCardCache{
cache: ramcache.New(),
}
c.cache.MaxAge = maxAge
c.cache.TTL = maxAge
return c
} | [
"func",
"NewUserCardCache",
"(",
"maxAge",
"time",
".",
"Duration",
")",
"*",
"UserCardCache",
"{",
"c",
":=",
"&",
"UserCardCache",
"{",
"cache",
":",
"ramcache",
".",
"New",
"(",
")",
",",
"}",
"\n",
"c",
".",
"cache",
".",
"MaxAge",
"=",
"maxAge",
"\n",
"c",
".",
"cache",
".",
"TTL",
"=",
"maxAge",
"\n",
"return",
"c",
"\n",
"}"
] | // NewUserCardCache creates a UserCardCache. keybase1.UserCards will expire
// after maxAge. | [
"NewUserCardCache",
"creates",
"a",
"UserCardCache",
".",
"keybase1",
".",
"UserCards",
"will",
"expire",
"after",
"maxAge",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/usercard_cache.go#L19-L26 |
158,877 | keybase/client | go/libkb/usercard_cache.go | Get | func (c *UserCardCache) Get(uid keybase1.UID, useSession bool) (*keybase1.UserCard, error) {
v, err := c.cache.Get(c.key(uid, useSession))
if err != nil {
if err == ramcache.ErrNotFound {
return nil, nil
}
return nil, err
}
card, ok := v.(keybase1.UserCard)
if !ok {
return nil, fmt.Errorf("invalid type in cache: %T", v)
}
return &card, nil
} | go | func (c *UserCardCache) Get(uid keybase1.UID, useSession bool) (*keybase1.UserCard, error) {
v, err := c.cache.Get(c.key(uid, useSession))
if err != nil {
if err == ramcache.ErrNotFound {
return nil, nil
}
return nil, err
}
card, ok := v.(keybase1.UserCard)
if !ok {
return nil, fmt.Errorf("invalid type in cache: %T", v)
}
return &card, nil
} | [
"func",
"(",
"c",
"*",
"UserCardCache",
")",
"Get",
"(",
"uid",
"keybase1",
".",
"UID",
",",
"useSession",
"bool",
")",
"(",
"*",
"keybase1",
".",
"UserCard",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"c",
".",
"cache",
".",
"Get",
"(",
"c",
".",
"key",
"(",
"uid",
",",
"useSession",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"ramcache",
".",
"ErrNotFound",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"card",
",",
"ok",
":=",
"v",
".",
"(",
"keybase1",
".",
"UserCard",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"&",
"card",
",",
"nil",
"\n",
"}"
] | // Get looks for a keybase1.UserCard for uid. It returns nil, nil if not found.
// useSession is set if the card is being looked up with a session. | [
"Get",
"looks",
"for",
"a",
"keybase1",
".",
"UserCard",
"for",
"uid",
".",
"It",
"returns",
"nil",
"nil",
"if",
"not",
"found",
".",
"useSession",
"is",
"set",
"if",
"the",
"card",
"is",
"being",
"looked",
"up",
"with",
"a",
"session",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/usercard_cache.go#L30-L43 |
158,878 | keybase/client | go/libkb/generickey.go | KeyMatchesQuery | func KeyMatchesQuery(key GenericKey, q string, exact bool) bool {
if key.GetKID().Match(q, exact) {
return true
}
return GetPGPFingerprintFromGenericKey(key).Match(q, exact)
} | go | func KeyMatchesQuery(key GenericKey, q string, exact bool) bool {
if key.GetKID().Match(q, exact) {
return true
}
return GetPGPFingerprintFromGenericKey(key).Match(q, exact)
} | [
"func",
"KeyMatchesQuery",
"(",
"key",
"GenericKey",
",",
"q",
"string",
",",
"exact",
"bool",
")",
"bool",
"{",
"if",
"key",
".",
"GetKID",
"(",
")",
".",
"Match",
"(",
"q",
",",
"exact",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"GetPGPFingerprintFromGenericKey",
"(",
"key",
")",
".",
"Match",
"(",
"q",
",",
"exact",
")",
"\n",
"}"
] | // Any valid key matches the empty string. | [
"Any",
"valid",
"key",
"matches",
"the",
"empty",
"string",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/generickey.go#L87-L92 |
158,879 | keybase/client | go/kbfs/libkey/key_bundle_cache_measured.go | NewKeyBundleCacheMeasured | func NewKeyBundleCacheMeasured(delegate kbfsmd.KeyBundleCache, r metrics.Registry) KeyBundleCacheMeasured {
getReaderBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.GetTLFReaderKeyBundle", r)
putReaderBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.PutTLFReaderKeyBundle", r)
getWriterBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.GetTLFWriterKeyBundle", r)
putWriterBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.PutTLFWriterKeyBundle", r)
hitReaderBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFReaderKeyBundleHitCount", r)
hitWriterBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFWriterKeyBundleHitCount", r)
attemptReaderBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFReaderKeyBundleAttemptCount", r)
attemptWriterBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFWriterKeyBundleAttemptCount", r)
return KeyBundleCacheMeasured{
delegate: delegate,
getReaderBundleTimer: getReaderBundleTimer,
getWriterBundleTimer: getWriterBundleTimer,
putReaderBundleTimer: putReaderBundleTimer,
putWriterBundleTimer: putWriterBundleTimer,
hitReaderBundleCountMeter: hitReaderBundleCountMeter,
hitWriterBundleCountMeter: hitWriterBundleCountMeter,
attemptReaderBundleCountMeter: attemptReaderBundleCountMeter,
attemptWriterBundleCountMeter: attemptWriterBundleCountMeter,
}
} | go | func NewKeyBundleCacheMeasured(delegate kbfsmd.KeyBundleCache, r metrics.Registry) KeyBundleCacheMeasured {
getReaderBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.GetTLFReaderKeyBundle", r)
putReaderBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.PutTLFReaderKeyBundle", r)
getWriterBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.GetTLFWriterKeyBundle", r)
putWriterBundleTimer := metrics.GetOrRegisterTimer("KeyBundleCache.PutTLFWriterKeyBundle", r)
hitReaderBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFReaderKeyBundleHitCount", r)
hitWriterBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFWriterKeyBundleHitCount", r)
attemptReaderBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFReaderKeyBundleAttemptCount", r)
attemptWriterBundleCountMeter := metrics.GetOrRegisterMeter("KeyBundleCache.TLFWriterKeyBundleAttemptCount", r)
return KeyBundleCacheMeasured{
delegate: delegate,
getReaderBundleTimer: getReaderBundleTimer,
getWriterBundleTimer: getWriterBundleTimer,
putReaderBundleTimer: putReaderBundleTimer,
putWriterBundleTimer: putWriterBundleTimer,
hitReaderBundleCountMeter: hitReaderBundleCountMeter,
hitWriterBundleCountMeter: hitWriterBundleCountMeter,
attemptReaderBundleCountMeter: attemptReaderBundleCountMeter,
attemptWriterBundleCountMeter: attemptWriterBundleCountMeter,
}
} | [
"func",
"NewKeyBundleCacheMeasured",
"(",
"delegate",
"kbfsmd",
".",
"KeyBundleCache",
",",
"r",
"metrics",
".",
"Registry",
")",
"KeyBundleCacheMeasured",
"{",
"getReaderBundleTimer",
":=",
"metrics",
".",
"GetOrRegisterTimer",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"putReaderBundleTimer",
":=",
"metrics",
".",
"GetOrRegisterTimer",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"getWriterBundleTimer",
":=",
"metrics",
".",
"GetOrRegisterTimer",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"putWriterBundleTimer",
":=",
"metrics",
".",
"GetOrRegisterTimer",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"hitReaderBundleCountMeter",
":=",
"metrics",
".",
"GetOrRegisterMeter",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"hitWriterBundleCountMeter",
":=",
"metrics",
".",
"GetOrRegisterMeter",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"attemptReaderBundleCountMeter",
":=",
"metrics",
".",
"GetOrRegisterMeter",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"attemptWriterBundleCountMeter",
":=",
"metrics",
".",
"GetOrRegisterMeter",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"return",
"KeyBundleCacheMeasured",
"{",
"delegate",
":",
"delegate",
",",
"getReaderBundleTimer",
":",
"getReaderBundleTimer",
",",
"getWriterBundleTimer",
":",
"getWriterBundleTimer",
",",
"putReaderBundleTimer",
":",
"putReaderBundleTimer",
",",
"putWriterBundleTimer",
":",
"putWriterBundleTimer",
",",
"hitReaderBundleCountMeter",
":",
"hitReaderBundleCountMeter",
",",
"hitWriterBundleCountMeter",
":",
"hitWriterBundleCountMeter",
",",
"attemptReaderBundleCountMeter",
":",
"attemptReaderBundleCountMeter",
",",
"attemptWriterBundleCountMeter",
":",
"attemptWriterBundleCountMeter",
",",
"}",
"\n",
"}"
] | // NewKeyBundleCacheMeasured creates and returns a new KeyBundleCacheMeasured
// instance with the given delegate and registry. | [
"NewKeyBundleCacheMeasured",
"creates",
"and",
"returns",
"a",
"new",
"KeyBundleCacheMeasured",
"instance",
"with",
"the",
"given",
"delegate",
"and",
"registry",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_bundle_cache_measured.go#L30-L50 |
158,880 | keybase/client | go/kbfs/libkey/key_bundle_cache_measured.go | GetTLFReaderKeyBundle | func (b KeyBundleCacheMeasured) GetTLFReaderKeyBundle(
bundleID kbfsmd.TLFReaderKeyBundleID) (rkb *kbfsmd.TLFReaderKeyBundleV3, err error) {
b.attemptReaderBundleCountMeter.Mark(1)
b.getReaderBundleTimer.Time(func() {
rkb, err = b.delegate.GetTLFReaderKeyBundle(bundleID)
})
if err == nil && rkb != nil {
b.hitReaderBundleCountMeter.Mark(1)
}
return rkb, err
} | go | func (b KeyBundleCacheMeasured) GetTLFReaderKeyBundle(
bundleID kbfsmd.TLFReaderKeyBundleID) (rkb *kbfsmd.TLFReaderKeyBundleV3, err error) {
b.attemptReaderBundleCountMeter.Mark(1)
b.getReaderBundleTimer.Time(func() {
rkb, err = b.delegate.GetTLFReaderKeyBundle(bundleID)
})
if err == nil && rkb != nil {
b.hitReaderBundleCountMeter.Mark(1)
}
return rkb, err
} | [
"func",
"(",
"b",
"KeyBundleCacheMeasured",
")",
"GetTLFReaderKeyBundle",
"(",
"bundleID",
"kbfsmd",
".",
"TLFReaderKeyBundleID",
")",
"(",
"rkb",
"*",
"kbfsmd",
".",
"TLFReaderKeyBundleV3",
",",
"err",
"error",
")",
"{",
"b",
".",
"attemptReaderBundleCountMeter",
".",
"Mark",
"(",
"1",
")",
"\n",
"b",
".",
"getReaderBundleTimer",
".",
"Time",
"(",
"func",
"(",
")",
"{",
"rkb",
",",
"err",
"=",
"b",
".",
"delegate",
".",
"GetTLFReaderKeyBundle",
"(",
"bundleID",
")",
"\n",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"rkb",
"!=",
"nil",
"{",
"b",
".",
"hitReaderBundleCountMeter",
".",
"Mark",
"(",
"1",
")",
"\n",
"}",
"\n",
"return",
"rkb",
",",
"err",
"\n",
"}"
] | // GetTLFReaderKeyBundle implements the KeyBundleCache interface for
// KeyBundleCacheMeasured. | [
"GetTLFReaderKeyBundle",
"implements",
"the",
"KeyBundleCache",
"interface",
"for",
"KeyBundleCacheMeasured",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_bundle_cache_measured.go#L54-L64 |
158,881 | keybase/client | go/kbfs/libkey/key_bundle_cache_measured.go | GetTLFWriterKeyBundle | func (b KeyBundleCacheMeasured) GetTLFWriterKeyBundle(
bundleID kbfsmd.TLFWriterKeyBundleID) (wkb *kbfsmd.TLFWriterKeyBundleV3, err error) {
b.attemptWriterBundleCountMeter.Mark(1)
b.getWriterBundleTimer.Time(func() {
wkb, err = b.delegate.GetTLFWriterKeyBundle(bundleID)
})
if err == nil && wkb != nil {
b.hitWriterBundleCountMeter.Mark(1)
}
return wkb, err
} | go | func (b KeyBundleCacheMeasured) GetTLFWriterKeyBundle(
bundleID kbfsmd.TLFWriterKeyBundleID) (wkb *kbfsmd.TLFWriterKeyBundleV3, err error) {
b.attemptWriterBundleCountMeter.Mark(1)
b.getWriterBundleTimer.Time(func() {
wkb, err = b.delegate.GetTLFWriterKeyBundle(bundleID)
})
if err == nil && wkb != nil {
b.hitWriterBundleCountMeter.Mark(1)
}
return wkb, err
} | [
"func",
"(",
"b",
"KeyBundleCacheMeasured",
")",
"GetTLFWriterKeyBundle",
"(",
"bundleID",
"kbfsmd",
".",
"TLFWriterKeyBundleID",
")",
"(",
"wkb",
"*",
"kbfsmd",
".",
"TLFWriterKeyBundleV3",
",",
"err",
"error",
")",
"{",
"b",
".",
"attemptWriterBundleCountMeter",
".",
"Mark",
"(",
"1",
")",
"\n",
"b",
".",
"getWriterBundleTimer",
".",
"Time",
"(",
"func",
"(",
")",
"{",
"wkb",
",",
"err",
"=",
"b",
".",
"delegate",
".",
"GetTLFWriterKeyBundle",
"(",
"bundleID",
")",
"\n",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"wkb",
"!=",
"nil",
"{",
"b",
".",
"hitWriterBundleCountMeter",
".",
"Mark",
"(",
"1",
")",
"\n",
"}",
"\n",
"return",
"wkb",
",",
"err",
"\n",
"}"
] | // GetTLFWriterKeyBundle implements the KeyBundleCache interface for
// KeyBundleCacheMeasured. | [
"GetTLFWriterKeyBundle",
"implements",
"the",
"KeyBundleCache",
"interface",
"for",
"KeyBundleCacheMeasured",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_bundle_cache_measured.go#L68-L78 |
158,882 | keybase/client | go/kbfs/libkey/key_bundle_cache_measured.go | PutTLFReaderKeyBundle | func (b KeyBundleCacheMeasured) PutTLFReaderKeyBundle(
bundleID kbfsmd.TLFReaderKeyBundleID, rkb kbfsmd.TLFReaderKeyBundleV3) {
b.putReaderBundleTimer.Time(func() {
b.delegate.PutTLFReaderKeyBundle(bundleID, rkb)
})
} | go | func (b KeyBundleCacheMeasured) PutTLFReaderKeyBundle(
bundleID kbfsmd.TLFReaderKeyBundleID, rkb kbfsmd.TLFReaderKeyBundleV3) {
b.putReaderBundleTimer.Time(func() {
b.delegate.PutTLFReaderKeyBundle(bundleID, rkb)
})
} | [
"func",
"(",
"b",
"KeyBundleCacheMeasured",
")",
"PutTLFReaderKeyBundle",
"(",
"bundleID",
"kbfsmd",
".",
"TLFReaderKeyBundleID",
",",
"rkb",
"kbfsmd",
".",
"TLFReaderKeyBundleV3",
")",
"{",
"b",
".",
"putReaderBundleTimer",
".",
"Time",
"(",
"func",
"(",
")",
"{",
"b",
".",
"delegate",
".",
"PutTLFReaderKeyBundle",
"(",
"bundleID",
",",
"rkb",
")",
"\n",
"}",
")",
"\n",
"}"
] | // PutTLFReaderKeyBundle implements the KeyBundleCache interface for
// KeyBundleCacheMeasured. | [
"PutTLFReaderKeyBundle",
"implements",
"the",
"KeyBundleCache",
"interface",
"for",
"KeyBundleCacheMeasured",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_bundle_cache_measured.go#L82-L87 |
158,883 | keybase/client | go/kbfs/libkey/key_bundle_cache_measured.go | PutTLFWriterKeyBundle | func (b KeyBundleCacheMeasured) PutTLFWriterKeyBundle(
bundleID kbfsmd.TLFWriterKeyBundleID, wkb kbfsmd.TLFWriterKeyBundleV3) {
b.putWriterBundleTimer.Time(func() {
b.delegate.PutTLFWriterKeyBundle(bundleID, wkb)
})
} | go | func (b KeyBundleCacheMeasured) PutTLFWriterKeyBundle(
bundleID kbfsmd.TLFWriterKeyBundleID, wkb kbfsmd.TLFWriterKeyBundleV3) {
b.putWriterBundleTimer.Time(func() {
b.delegate.PutTLFWriterKeyBundle(bundleID, wkb)
})
} | [
"func",
"(",
"b",
"KeyBundleCacheMeasured",
")",
"PutTLFWriterKeyBundle",
"(",
"bundleID",
"kbfsmd",
".",
"TLFWriterKeyBundleID",
",",
"wkb",
"kbfsmd",
".",
"TLFWriterKeyBundleV3",
")",
"{",
"b",
".",
"putWriterBundleTimer",
".",
"Time",
"(",
"func",
"(",
")",
"{",
"b",
".",
"delegate",
".",
"PutTLFWriterKeyBundle",
"(",
"bundleID",
",",
"wkb",
")",
"\n",
"}",
")",
"\n",
"}"
] | // PutTLFWriterKeyBundle implements the KeyBundleCache interface for
// KeyBundleCacheMeasured. | [
"PutTLFWriterKeyBundle",
"implements",
"the",
"KeyBundleCache",
"interface",
"for",
"KeyBundleCacheMeasured",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkey/key_bundle_cache_measured.go#L91-L96 |
158,884 | keybase/client | go/kbfs/libdokan/user_edit_history.go | NewUserEditHistoryFile | func NewUserEditHistoryFile(folder *Folder) *SpecialReadFile {
return &SpecialReadFile{
read: func(ctx context.Context) ([]byte, time.Time, error) {
return libfs.GetEncodedUserEditHistory(ctx, folder.fs.config)
},
fs: folder.fs,
}
} | go | func NewUserEditHistoryFile(folder *Folder) *SpecialReadFile {
return &SpecialReadFile{
read: func(ctx context.Context) ([]byte, time.Time, error) {
return libfs.GetEncodedUserEditHistory(ctx, folder.fs.config)
},
fs: folder.fs,
}
} | [
"func",
"NewUserEditHistoryFile",
"(",
"folder",
"*",
"Folder",
")",
"*",
"SpecialReadFile",
"{",
"return",
"&",
"SpecialReadFile",
"{",
"read",
":",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"byte",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"libfs",
".",
"GetEncodedUserEditHistory",
"(",
"ctx",
",",
"folder",
".",
"fs",
".",
"config",
")",
"\n",
"}",
",",
"fs",
":",
"folder",
".",
"fs",
",",
"}",
"\n",
"}"
] | // NewUserEditHistoryFile returns a special read file that contains a text
// representation of the file edit history for the logged-in user. | [
"NewUserEditHistoryFile",
"returns",
"a",
"special",
"read",
"file",
"that",
"contains",
"a",
"text",
"representation",
"of",
"the",
"file",
"edit",
"history",
"for",
"the",
"logged",
"-",
"in",
"user",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libdokan/user_edit_history.go#L16-L23 |
158,885 | keybase/client | go/kbfs/libkbfs/crypto_client.go | Sign | func (c *CryptoClient) Sign(ctx context.Context, msg []byte) (
sigInfo kbfscrypto.SignatureInfo, err error) {
c.log.CDebugf(ctx, "Signing %d-byte message", len(msg))
defer func() {
c.deferLog.CDebugf(ctx, "Signed %d-byte message with %s: err=%+v", len(msg),
sigInfo, err)
}()
timer := c.logAboutTooLongUnlessCancelled(ctx, "SignED25519")
defer timer.Stop()
ed25519SigInfo, err := c.client.SignED25519(ctx, keybase1.SignED25519Arg{
Msg: msg,
Reason: "to use kbfs",
})
if err != nil {
return kbfscrypto.SignatureInfo{}, errors.WithStack(err)
}
return kbfscrypto.SignatureInfo{
Version: kbfscrypto.SigED25519,
Signature: ed25519SigInfo.Sig[:],
VerifyingKey: kbfscrypto.MakeVerifyingKey(kbcrypto.NaclSigningKeyPublic(ed25519SigInfo.PublicKey).GetKID()),
}, nil
} | go | func (c *CryptoClient) Sign(ctx context.Context, msg []byte) (
sigInfo kbfscrypto.SignatureInfo, err error) {
c.log.CDebugf(ctx, "Signing %d-byte message", len(msg))
defer func() {
c.deferLog.CDebugf(ctx, "Signed %d-byte message with %s: err=%+v", len(msg),
sigInfo, err)
}()
timer := c.logAboutTooLongUnlessCancelled(ctx, "SignED25519")
defer timer.Stop()
ed25519SigInfo, err := c.client.SignED25519(ctx, keybase1.SignED25519Arg{
Msg: msg,
Reason: "to use kbfs",
})
if err != nil {
return kbfscrypto.SignatureInfo{}, errors.WithStack(err)
}
return kbfscrypto.SignatureInfo{
Version: kbfscrypto.SigED25519,
Signature: ed25519SigInfo.Sig[:],
VerifyingKey: kbfscrypto.MakeVerifyingKey(kbcrypto.NaclSigningKeyPublic(ed25519SigInfo.PublicKey).GetKID()),
}, nil
} | [
"func",
"(",
"c",
"*",
"CryptoClient",
")",
"Sign",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"[",
"]",
"byte",
")",
"(",
"sigInfo",
"kbfscrypto",
".",
"SignatureInfo",
",",
"err",
"error",
")",
"{",
"c",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"len",
"(",
"msg",
")",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"deferLog",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"len",
"(",
"msg",
")",
",",
"sigInfo",
",",
"err",
")",
"\n",
"}",
"(",
")",
"\n\n",
"timer",
":=",
"c",
".",
"logAboutTooLongUnlessCancelled",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n",
"ed25519SigInfo",
",",
"err",
":=",
"c",
".",
"client",
".",
"SignED25519",
"(",
"ctx",
",",
"keybase1",
".",
"SignED25519Arg",
"{",
"Msg",
":",
"msg",
",",
"Reason",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"kbfscrypto",
".",
"SignatureInfo",
"{",
"}",
",",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"kbfscrypto",
".",
"SignatureInfo",
"{",
"Version",
":",
"kbfscrypto",
".",
"SigED25519",
",",
"Signature",
":",
"ed25519SigInfo",
".",
"Sig",
"[",
":",
"]",
",",
"VerifyingKey",
":",
"kbfscrypto",
".",
"MakeVerifyingKey",
"(",
"kbcrypto",
".",
"NaclSigningKeyPublic",
"(",
"ed25519SigInfo",
".",
"PublicKey",
")",
".",
"GetKID",
"(",
")",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Sign implements the Crypto interface for CryptoClient. | [
"Sign",
"implements",
"the",
"Crypto",
"interface",
"for",
"CryptoClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/crypto_client.go#L44-L67 |
158,886 | keybase/client | go/kbfs/libkbfs/crypto_client.go | SignToString | func (c *CryptoClient) SignToString(ctx context.Context, msg []byte) (
signature string, err error) {
c.log.CDebugf(ctx, "Signing %d-byte message to string", len(msg))
defer func() {
c.deferLog.CDebugf(ctx, "Signed %d-byte message: err=%+v", len(msg), err)
}()
timer := c.logAboutTooLongUnlessCancelled(ctx, "SignToString")
defer timer.Stop()
signature, err = c.client.SignToString(ctx, keybase1.SignToStringArg{
Msg: msg,
Reason: "KBFS Authentication",
})
if err != nil {
return "", errors.WithStack(err)
}
return signature, nil
} | go | func (c *CryptoClient) SignToString(ctx context.Context, msg []byte) (
signature string, err error) {
c.log.CDebugf(ctx, "Signing %d-byte message to string", len(msg))
defer func() {
c.deferLog.CDebugf(ctx, "Signed %d-byte message: err=%+v", len(msg), err)
}()
timer := c.logAboutTooLongUnlessCancelled(ctx, "SignToString")
defer timer.Stop()
signature, err = c.client.SignToString(ctx, keybase1.SignToStringArg{
Msg: msg,
Reason: "KBFS Authentication",
})
if err != nil {
return "", errors.WithStack(err)
}
return signature, nil
} | [
"func",
"(",
"c",
"*",
"CryptoClient",
")",
"SignToString",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"[",
"]",
"byte",
")",
"(",
"signature",
"string",
",",
"err",
"error",
")",
"{",
"c",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"len",
"(",
"msg",
")",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"deferLog",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"len",
"(",
"msg",
")",
",",
"err",
")",
"\n",
"}",
"(",
")",
"\n\n",
"timer",
":=",
"c",
".",
"logAboutTooLongUnlessCancelled",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n",
"signature",
",",
"err",
"=",
"c",
".",
"client",
".",
"SignToString",
"(",
"ctx",
",",
"keybase1",
".",
"SignToStringArg",
"{",
"Msg",
":",
"msg",
",",
"Reason",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"signature",
",",
"nil",
"\n",
"}"
] | // SignToString implements the Crypto interface for CryptoClient. | [
"SignToString",
"implements",
"the",
"Crypto",
"interface",
"for",
"CryptoClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/crypto_client.go#L96-L113 |
158,887 | keybase/client | go/kbfs/libkbfs/crypto_client.go | DecryptTLFCryptKeyClientHalf | func (c *CryptoClient) DecryptTLFCryptKeyClientHalf(ctx context.Context,
publicKey kbfscrypto.TLFEphemeralPublicKey,
encryptedClientHalf kbfscrypto.EncryptedTLFCryptKeyClientHalf) (
clientHalf kbfscrypto.TLFCryptKeyClientHalf, err error) {
c.log.CDebugf(ctx, "Decrypting TLF client key half")
defer func() {
c.deferLog.CDebugf(ctx, "Decrypted TLF client key half: %+v",
err)
}()
encryptedData, nonce, err := c.prepareTLFCryptKeyClientHalf(
encryptedClientHalf)
if err != nil {
return kbfscrypto.TLFCryptKeyClientHalf{}, err
}
timer := c.logAboutTooLongUnlessCancelled(ctx, "UnboxBytes32")
defer timer.Stop()
decryptedClientHalf, err := c.client.UnboxBytes32(ctx, keybase1.UnboxBytes32Arg{
EncryptedBytes32: encryptedData,
Nonce: nonce,
PeersPublicKey: keybase1.BoxPublicKey(publicKey.Data()),
Reason: "to use kbfs",
})
if err != nil {
return kbfscrypto.TLFCryptKeyClientHalf{}, errors.WithStack(err)
}
return kbfscrypto.MakeTLFCryptKeyClientHalf(decryptedClientHalf), nil
} | go | func (c *CryptoClient) DecryptTLFCryptKeyClientHalf(ctx context.Context,
publicKey kbfscrypto.TLFEphemeralPublicKey,
encryptedClientHalf kbfscrypto.EncryptedTLFCryptKeyClientHalf) (
clientHalf kbfscrypto.TLFCryptKeyClientHalf, err error) {
c.log.CDebugf(ctx, "Decrypting TLF client key half")
defer func() {
c.deferLog.CDebugf(ctx, "Decrypted TLF client key half: %+v",
err)
}()
encryptedData, nonce, err := c.prepareTLFCryptKeyClientHalf(
encryptedClientHalf)
if err != nil {
return kbfscrypto.TLFCryptKeyClientHalf{}, err
}
timer := c.logAboutTooLongUnlessCancelled(ctx, "UnboxBytes32")
defer timer.Stop()
decryptedClientHalf, err := c.client.UnboxBytes32(ctx, keybase1.UnboxBytes32Arg{
EncryptedBytes32: encryptedData,
Nonce: nonce,
PeersPublicKey: keybase1.BoxPublicKey(publicKey.Data()),
Reason: "to use kbfs",
})
if err != nil {
return kbfscrypto.TLFCryptKeyClientHalf{}, errors.WithStack(err)
}
return kbfscrypto.MakeTLFCryptKeyClientHalf(decryptedClientHalf), nil
} | [
"func",
"(",
"c",
"*",
"CryptoClient",
")",
"DecryptTLFCryptKeyClientHalf",
"(",
"ctx",
"context",
".",
"Context",
",",
"publicKey",
"kbfscrypto",
".",
"TLFEphemeralPublicKey",
",",
"encryptedClientHalf",
"kbfscrypto",
".",
"EncryptedTLFCryptKeyClientHalf",
")",
"(",
"clientHalf",
"kbfscrypto",
".",
"TLFCryptKeyClientHalf",
",",
"err",
"error",
")",
"{",
"c",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"deferLog",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"(",
")",
"\n",
"encryptedData",
",",
"nonce",
",",
"err",
":=",
"c",
".",
"prepareTLFCryptKeyClientHalf",
"(",
"encryptedClientHalf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"kbfscrypto",
".",
"TLFCryptKeyClientHalf",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"timer",
":=",
"c",
".",
"logAboutTooLongUnlessCancelled",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n",
"decryptedClientHalf",
",",
"err",
":=",
"c",
".",
"client",
".",
"UnboxBytes32",
"(",
"ctx",
",",
"keybase1",
".",
"UnboxBytes32Arg",
"{",
"EncryptedBytes32",
":",
"encryptedData",
",",
"Nonce",
":",
"nonce",
",",
"PeersPublicKey",
":",
"keybase1",
".",
"BoxPublicKey",
"(",
"publicKey",
".",
"Data",
"(",
")",
")",
",",
"Reason",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"kbfscrypto",
".",
"TLFCryptKeyClientHalf",
"{",
"}",
",",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"kbfscrypto",
".",
"MakeTLFCryptKeyClientHalf",
"(",
"decryptedClientHalf",
")",
",",
"nil",
"\n",
"}"
] | // DecryptTLFCryptKeyClientHalf implements the Crypto interface for
// CryptoClient. | [
"DecryptTLFCryptKeyClientHalf",
"implements",
"the",
"Crypto",
"interface",
"for",
"CryptoClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/crypto_client.go#L144-L172 |
158,888 | keybase/client | go/kbfs/libkbfs/crypto_client.go | DecryptTLFCryptKeyClientHalfAny | func (c *CryptoClient) DecryptTLFCryptKeyClientHalfAny(ctx context.Context,
keys []EncryptedTLFCryptKeyClientAndEphemeral, promptPaper bool) (
clientHalf kbfscrypto.TLFCryptKeyClientHalf, index int, err error) {
c.log.CDebugf(ctx, "Decrypting TLF client key half with any key")
defer func() {
c.deferLog.CDebugf(ctx,
"Decrypted TLF client key half with any key: %+v",
err)
}()
if len(keys) == 0 {
return kbfscrypto.TLFCryptKeyClientHalf{}, -1,
errors.WithStack(NoKeysError{})
}
bundles := make([]keybase1.CiphertextBundle, 0, len(keys))
prepErrs := make([]error, 0, len(keys))
indexLookup := make([]int, 0, len(keys))
for i, k := range keys {
encryptedData, nonce, prepErr :=
c.prepareTLFCryptKeyClientHalf(k.ClientHalf)
if err != nil {
prepErrs = append(prepErrs, prepErr)
} else {
bundles = append(bundles, keybase1.CiphertextBundle{
Kid: k.PubKey.KID(),
Ciphertext: encryptedData,
Nonce: nonce,
PublicKey: keybase1.BoxPublicKey(k.EPubKey.Data()),
})
indexLookup = append(indexLookup, i)
}
}
if len(bundles) == 0 {
return kbfscrypto.TLFCryptKeyClientHalf{}, -1, prepErrs[0]
}
timer := c.logAboutTooLongUnlessCancelled(ctx, "UnboxBytes32Any")
defer timer.Stop()
res, err := c.client.UnboxBytes32Any(ctx, keybase1.UnboxBytes32AnyArg{
Bundles: bundles,
Reason: "to rekey for kbfs",
PromptPaper: promptPaper,
})
if err != nil {
return kbfscrypto.TLFCryptKeyClientHalf{}, -1,
errors.WithStack(err)
}
return kbfscrypto.MakeTLFCryptKeyClientHalf(res.Plaintext),
indexLookup[res.Index], nil
} | go | func (c *CryptoClient) DecryptTLFCryptKeyClientHalfAny(ctx context.Context,
keys []EncryptedTLFCryptKeyClientAndEphemeral, promptPaper bool) (
clientHalf kbfscrypto.TLFCryptKeyClientHalf, index int, err error) {
c.log.CDebugf(ctx, "Decrypting TLF client key half with any key")
defer func() {
c.deferLog.CDebugf(ctx,
"Decrypted TLF client key half with any key: %+v",
err)
}()
if len(keys) == 0 {
return kbfscrypto.TLFCryptKeyClientHalf{}, -1,
errors.WithStack(NoKeysError{})
}
bundles := make([]keybase1.CiphertextBundle, 0, len(keys))
prepErrs := make([]error, 0, len(keys))
indexLookup := make([]int, 0, len(keys))
for i, k := range keys {
encryptedData, nonce, prepErr :=
c.prepareTLFCryptKeyClientHalf(k.ClientHalf)
if err != nil {
prepErrs = append(prepErrs, prepErr)
} else {
bundles = append(bundles, keybase1.CiphertextBundle{
Kid: k.PubKey.KID(),
Ciphertext: encryptedData,
Nonce: nonce,
PublicKey: keybase1.BoxPublicKey(k.EPubKey.Data()),
})
indexLookup = append(indexLookup, i)
}
}
if len(bundles) == 0 {
return kbfscrypto.TLFCryptKeyClientHalf{}, -1, prepErrs[0]
}
timer := c.logAboutTooLongUnlessCancelled(ctx, "UnboxBytes32Any")
defer timer.Stop()
res, err := c.client.UnboxBytes32Any(ctx, keybase1.UnboxBytes32AnyArg{
Bundles: bundles,
Reason: "to rekey for kbfs",
PromptPaper: promptPaper,
})
if err != nil {
return kbfscrypto.TLFCryptKeyClientHalf{}, -1,
errors.WithStack(err)
}
return kbfscrypto.MakeTLFCryptKeyClientHalf(res.Plaintext),
indexLookup[res.Index], nil
} | [
"func",
"(",
"c",
"*",
"CryptoClient",
")",
"DecryptTLFCryptKeyClientHalfAny",
"(",
"ctx",
"context",
".",
"Context",
",",
"keys",
"[",
"]",
"EncryptedTLFCryptKeyClientAndEphemeral",
",",
"promptPaper",
"bool",
")",
"(",
"clientHalf",
"kbfscrypto",
".",
"TLFCryptKeyClientHalf",
",",
"index",
"int",
",",
"err",
"error",
")",
"{",
"c",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"deferLog",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"(",
")",
"\n",
"if",
"len",
"(",
"keys",
")",
"==",
"0",
"{",
"return",
"kbfscrypto",
".",
"TLFCryptKeyClientHalf",
"{",
"}",
",",
"-",
"1",
",",
"errors",
".",
"WithStack",
"(",
"NoKeysError",
"{",
"}",
")",
"\n",
"}",
"\n",
"bundles",
":=",
"make",
"(",
"[",
"]",
"keybase1",
".",
"CiphertextBundle",
",",
"0",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"prepErrs",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"0",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"indexLookup",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"for",
"i",
",",
"k",
":=",
"range",
"keys",
"{",
"encryptedData",
",",
"nonce",
",",
"prepErr",
":=",
"c",
".",
"prepareTLFCryptKeyClientHalf",
"(",
"k",
".",
"ClientHalf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"prepErrs",
"=",
"append",
"(",
"prepErrs",
",",
"prepErr",
")",
"\n",
"}",
"else",
"{",
"bundles",
"=",
"append",
"(",
"bundles",
",",
"keybase1",
".",
"CiphertextBundle",
"{",
"Kid",
":",
"k",
".",
"PubKey",
".",
"KID",
"(",
")",
",",
"Ciphertext",
":",
"encryptedData",
",",
"Nonce",
":",
"nonce",
",",
"PublicKey",
":",
"keybase1",
".",
"BoxPublicKey",
"(",
"k",
".",
"EPubKey",
".",
"Data",
"(",
")",
")",
",",
"}",
")",
"\n",
"indexLookup",
"=",
"append",
"(",
"indexLookup",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"bundles",
")",
"==",
"0",
"{",
"return",
"kbfscrypto",
".",
"TLFCryptKeyClientHalf",
"{",
"}",
",",
"-",
"1",
",",
"prepErrs",
"[",
"0",
"]",
"\n",
"}",
"\n",
"timer",
":=",
"c",
".",
"logAboutTooLongUnlessCancelled",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n",
"res",
",",
"err",
":=",
"c",
".",
"client",
".",
"UnboxBytes32Any",
"(",
"ctx",
",",
"keybase1",
".",
"UnboxBytes32AnyArg",
"{",
"Bundles",
":",
"bundles",
",",
"Reason",
":",
"\"",
"\"",
",",
"PromptPaper",
":",
"promptPaper",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"kbfscrypto",
".",
"TLFCryptKeyClientHalf",
"{",
"}",
",",
"-",
"1",
",",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"kbfscrypto",
".",
"MakeTLFCryptKeyClientHalf",
"(",
"res",
".",
"Plaintext",
")",
",",
"indexLookup",
"[",
"res",
".",
"Index",
"]",
",",
"nil",
"\n",
"}"
] | // DecryptTLFCryptKeyClientHalfAny implements the Crypto interface for
// CryptoClient. | [
"DecryptTLFCryptKeyClientHalfAny",
"implements",
"the",
"Crypto",
"interface",
"for",
"CryptoClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/crypto_client.go#L176-L223 |
158,889 | keybase/client | go/kbfs/libkbfs/crypto_client.go | DecryptTeamMerkleLeaf | func (c *CryptoClient) DecryptTeamMerkleLeaf(
ctx context.Context, teamID keybase1.TeamID,
publicKey kbfscrypto.TLFEphemeralPublicKey,
encryptedMerkleLeaf kbfscrypto.EncryptedMerkleLeaf,
minKeyGen keybase1.PerTeamKeyGeneration) (decryptedData []byte, err error) {
c.log.CDebugf(ctx, "Decrypting team Merkle leaf")
defer func() {
c.deferLog.CDebugf(ctx, "Decrypted team Merkle leaf: %+v", err)
}()
nonce, err := kbfscrypto.PrepareMerkleLeaf(
encryptedMerkleLeaf)
if err != nil {
return nil, err
}
timer := c.logAboutTooLongUnlessCancelled(ctx, "DecryptTeamMerkleLeaf")
defer timer.Stop()
decryptedData, err = c.teamsClient.TryDecryptWithTeamKey(ctx,
keybase1.TryDecryptWithTeamKeyArg{
TeamID: teamID,
EncryptedData: encryptedMerkleLeaf.EncryptedData,
Nonce: nonce,
PeersPublicKey: keybase1.BoxPublicKey(publicKey.Data()),
MinGeneration: minKeyGen,
})
if err != nil {
return nil, errors.WithStack(err)
}
return decryptedData, nil
} | go | func (c *CryptoClient) DecryptTeamMerkleLeaf(
ctx context.Context, teamID keybase1.TeamID,
publicKey kbfscrypto.TLFEphemeralPublicKey,
encryptedMerkleLeaf kbfscrypto.EncryptedMerkleLeaf,
minKeyGen keybase1.PerTeamKeyGeneration) (decryptedData []byte, err error) {
c.log.CDebugf(ctx, "Decrypting team Merkle leaf")
defer func() {
c.deferLog.CDebugf(ctx, "Decrypted team Merkle leaf: %+v", err)
}()
nonce, err := kbfscrypto.PrepareMerkleLeaf(
encryptedMerkleLeaf)
if err != nil {
return nil, err
}
timer := c.logAboutTooLongUnlessCancelled(ctx, "DecryptTeamMerkleLeaf")
defer timer.Stop()
decryptedData, err = c.teamsClient.TryDecryptWithTeamKey(ctx,
keybase1.TryDecryptWithTeamKeyArg{
TeamID: teamID,
EncryptedData: encryptedMerkleLeaf.EncryptedData,
Nonce: nonce,
PeersPublicKey: keybase1.BoxPublicKey(publicKey.Data()),
MinGeneration: minKeyGen,
})
if err != nil {
return nil, errors.WithStack(err)
}
return decryptedData, nil
} | [
"func",
"(",
"c",
"*",
"CryptoClient",
")",
"DecryptTeamMerkleLeaf",
"(",
"ctx",
"context",
".",
"Context",
",",
"teamID",
"keybase1",
".",
"TeamID",
",",
"publicKey",
"kbfscrypto",
".",
"TLFEphemeralPublicKey",
",",
"encryptedMerkleLeaf",
"kbfscrypto",
".",
"EncryptedMerkleLeaf",
",",
"minKeyGen",
"keybase1",
".",
"PerTeamKeyGeneration",
")",
"(",
"decryptedData",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"c",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"deferLog",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"(",
")",
"\n",
"nonce",
",",
"err",
":=",
"kbfscrypto",
".",
"PrepareMerkleLeaf",
"(",
"encryptedMerkleLeaf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"timer",
":=",
"c",
".",
"logAboutTooLongUnlessCancelled",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n",
"decryptedData",
",",
"err",
"=",
"c",
".",
"teamsClient",
".",
"TryDecryptWithTeamKey",
"(",
"ctx",
",",
"keybase1",
".",
"TryDecryptWithTeamKeyArg",
"{",
"TeamID",
":",
"teamID",
",",
"EncryptedData",
":",
"encryptedMerkleLeaf",
".",
"EncryptedData",
",",
"Nonce",
":",
"nonce",
",",
"PeersPublicKey",
":",
"keybase1",
".",
"BoxPublicKey",
"(",
"publicKey",
".",
"Data",
"(",
")",
")",
",",
"MinGeneration",
":",
"minKeyGen",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"decryptedData",
",",
"nil",
"\n",
"}"
] | // DecryptTeamMerkleLeaf implements the Crypto interface for
// CryptoClient. | [
"DecryptTeamMerkleLeaf",
"implements",
"the",
"Crypto",
"interface",
"for",
"CryptoClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/crypto_client.go#L227-L256 |
158,890 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | MakeGetBlockArg | func MakeGetBlockArg(tlfID tlf.ID, id ID, context Context) keybase1.GetBlockArg {
return keybase1.GetBlockArg{
Bid: makeIDCombo(id, context),
Folder: tlfID.String(),
}
} | go | func MakeGetBlockArg(tlfID tlf.ID, id ID, context Context) keybase1.GetBlockArg {
return keybase1.GetBlockArg{
Bid: makeIDCombo(id, context),
Folder: tlfID.String(),
}
} | [
"func",
"MakeGetBlockArg",
"(",
"tlfID",
"tlf",
".",
"ID",
",",
"id",
"ID",
",",
"context",
"Context",
")",
"keybase1",
".",
"GetBlockArg",
"{",
"return",
"keybase1",
".",
"GetBlockArg",
"{",
"Bid",
":",
"makeIDCombo",
"(",
"id",
",",
"context",
")",
",",
"Folder",
":",
"tlfID",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}"
] | // MakeGetBlockArg builds a keybase1.GetBlockArg from the given params. | [
"MakeGetBlockArg",
"builds",
"a",
"keybase1",
".",
"GetBlockArg",
"from",
"the",
"given",
"params",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L45-L50 |
158,891 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | ParseGetBlockRes | func ParseGetBlockRes(res keybase1.GetBlockRes, resErr error) (
buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf, err error) {
if resErr != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, resErr
}
serverHalf, err = kbfscrypto.ParseBlockCryptKeyServerHalf(res.BlockKey)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, err
}
return res.Buf, serverHalf, nil
} | go | func ParseGetBlockRes(res keybase1.GetBlockRes, resErr error) (
buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf, err error) {
if resErr != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, resErr
}
serverHalf, err = kbfscrypto.ParseBlockCryptKeyServerHalf(res.BlockKey)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, err
}
return res.Buf, serverHalf, nil
} | [
"func",
"ParseGetBlockRes",
"(",
"res",
"keybase1",
".",
"GetBlockRes",
",",
"resErr",
"error",
")",
"(",
"buf",
"[",
"]",
"byte",
",",
"serverHalf",
"kbfscrypto",
".",
"BlockCryptKeyServerHalf",
",",
"err",
"error",
")",
"{",
"if",
"resErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"kbfscrypto",
".",
"BlockCryptKeyServerHalf",
"{",
"}",
",",
"resErr",
"\n",
"}",
"\n",
"serverHalf",
",",
"err",
"=",
"kbfscrypto",
".",
"ParseBlockCryptKeyServerHalf",
"(",
"res",
".",
"BlockKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"kbfscrypto",
".",
"BlockCryptKeyServerHalf",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
".",
"Buf",
",",
"serverHalf",
",",
"nil",
"\n",
"}"
] | // ParseGetBlockRes parses the given keybase1.GetBlockRes into its
// components. | [
"ParseGetBlockRes",
"parses",
"the",
"given",
"keybase1",
".",
"GetBlockRes",
"into",
"its",
"components",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L54-L64 |
158,892 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | MakePutBlockArg | func MakePutBlockArg(tlfID tlf.ID, id ID,
bContext Context, buf []byte,
serverHalf kbfscrypto.BlockCryptKeyServerHalf) keybase1.PutBlockArg {
return keybase1.PutBlockArg{
Bid: makeIDCombo(id, bContext),
// BlockKey is misnamed -- it contains just the server
// half.
BlockKey: serverHalf.String(),
Folder: tlfID.String(),
Buf: buf,
}
} | go | func MakePutBlockArg(tlfID tlf.ID, id ID,
bContext Context, buf []byte,
serverHalf kbfscrypto.BlockCryptKeyServerHalf) keybase1.PutBlockArg {
return keybase1.PutBlockArg{
Bid: makeIDCombo(id, bContext),
// BlockKey is misnamed -- it contains just the server
// half.
BlockKey: serverHalf.String(),
Folder: tlfID.String(),
Buf: buf,
}
} | [
"func",
"MakePutBlockArg",
"(",
"tlfID",
"tlf",
".",
"ID",
",",
"id",
"ID",
",",
"bContext",
"Context",
",",
"buf",
"[",
"]",
"byte",
",",
"serverHalf",
"kbfscrypto",
".",
"BlockCryptKeyServerHalf",
")",
"keybase1",
".",
"PutBlockArg",
"{",
"return",
"keybase1",
".",
"PutBlockArg",
"{",
"Bid",
":",
"makeIDCombo",
"(",
"id",
",",
"bContext",
")",
",",
"// BlockKey is misnamed -- it contains just the server",
"// half.",
"BlockKey",
":",
"serverHalf",
".",
"String",
"(",
")",
",",
"Folder",
":",
"tlfID",
".",
"String",
"(",
")",
",",
"Buf",
":",
"buf",
",",
"}",
"\n",
"}"
] | // MakePutBlockArg builds a keybase1.PutBlockArg from the given params. | [
"MakePutBlockArg",
"builds",
"a",
"keybase1",
".",
"PutBlockArg",
"from",
"the",
"given",
"params",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L67-L78 |
158,893 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | MakePutBlockAgainArg | func MakePutBlockAgainArg(tlfID tlf.ID, id ID,
bContext Context, buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf) keybase1.PutBlockAgainArg {
return keybase1.PutBlockAgainArg{
Ref: makeReference(id, bContext),
// BlockKey is misnamed -- it contains just the server
// half.
BlockKey: serverHalf.String(),
Folder: tlfID.String(),
Buf: buf,
}
} | go | func MakePutBlockAgainArg(tlfID tlf.ID, id ID,
bContext Context, buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf) keybase1.PutBlockAgainArg {
return keybase1.PutBlockAgainArg{
Ref: makeReference(id, bContext),
// BlockKey is misnamed -- it contains just the server
// half.
BlockKey: serverHalf.String(),
Folder: tlfID.String(),
Buf: buf,
}
} | [
"func",
"MakePutBlockAgainArg",
"(",
"tlfID",
"tlf",
".",
"ID",
",",
"id",
"ID",
",",
"bContext",
"Context",
",",
"buf",
"[",
"]",
"byte",
",",
"serverHalf",
"kbfscrypto",
".",
"BlockCryptKeyServerHalf",
")",
"keybase1",
".",
"PutBlockAgainArg",
"{",
"return",
"keybase1",
".",
"PutBlockAgainArg",
"{",
"Ref",
":",
"makeReference",
"(",
"id",
",",
"bContext",
")",
",",
"// BlockKey is misnamed -- it contains just the server",
"// half.",
"BlockKey",
":",
"serverHalf",
".",
"String",
"(",
")",
",",
"Folder",
":",
"tlfID",
".",
"String",
"(",
")",
",",
"Buf",
":",
"buf",
",",
"}",
"\n",
"}"
] | // MakePutBlockAgainArg builds a keybase1.PutBlockAgainArg from the
// given params. | [
"MakePutBlockAgainArg",
"builds",
"a",
"keybase1",
".",
"PutBlockAgainArg",
"from",
"the",
"given",
"params",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L82-L92 |
158,894 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | MakeAddReferenceArg | func MakeAddReferenceArg(tlfID tlf.ID, id ID, context Context) keybase1.AddReferenceArg {
return keybase1.AddReferenceArg{
Ref: makeReference(id, context),
Folder: tlfID.String(),
}
} | go | func MakeAddReferenceArg(tlfID tlf.ID, id ID, context Context) keybase1.AddReferenceArg {
return keybase1.AddReferenceArg{
Ref: makeReference(id, context),
Folder: tlfID.String(),
}
} | [
"func",
"MakeAddReferenceArg",
"(",
"tlfID",
"tlf",
".",
"ID",
",",
"id",
"ID",
",",
"context",
"Context",
")",
"keybase1",
".",
"AddReferenceArg",
"{",
"return",
"keybase1",
".",
"AddReferenceArg",
"{",
"Ref",
":",
"makeReference",
"(",
"id",
",",
"context",
")",
",",
"Folder",
":",
"tlfID",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}"
] | // MakeAddReferenceArg builds a keybase1.AddReferenceArg from the
// given params. | [
"MakeAddReferenceArg",
"builds",
"a",
"keybase1",
".",
"AddReferenceArg",
"from",
"the",
"given",
"params",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L96-L101 |
158,895 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | getNotDone | func getNotDone(all ContextMap, doneRefs map[ID]map[RefNonce]int) (
notDone []keybase1.BlockReference) {
for id, idContexts := range all {
for _, context := range idContexts {
if _, ok := doneRefs[id]; ok {
if _, ok1 := doneRefs[id][context.GetRefNonce()]; ok1 {
continue
}
}
ref := makeReference(id, context)
notDone = append(notDone, ref)
}
}
return notDone
} | go | func getNotDone(all ContextMap, doneRefs map[ID]map[RefNonce]int) (
notDone []keybase1.BlockReference) {
for id, idContexts := range all {
for _, context := range idContexts {
if _, ok := doneRefs[id]; ok {
if _, ok1 := doneRefs[id][context.GetRefNonce()]; ok1 {
continue
}
}
ref := makeReference(id, context)
notDone = append(notDone, ref)
}
}
return notDone
} | [
"func",
"getNotDone",
"(",
"all",
"ContextMap",
",",
"doneRefs",
"map",
"[",
"ID",
"]",
"map",
"[",
"RefNonce",
"]",
"int",
")",
"(",
"notDone",
"[",
"]",
"keybase1",
".",
"BlockReference",
")",
"{",
"for",
"id",
",",
"idContexts",
":=",
"range",
"all",
"{",
"for",
"_",
",",
"context",
":=",
"range",
"idContexts",
"{",
"if",
"_",
",",
"ok",
":=",
"doneRefs",
"[",
"id",
"]",
";",
"ok",
"{",
"if",
"_",
",",
"ok1",
":=",
"doneRefs",
"[",
"id",
"]",
"[",
"context",
".",
"GetRefNonce",
"(",
")",
"]",
";",
"ok1",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"ref",
":=",
"makeReference",
"(",
"id",
",",
"context",
")",
"\n",
"notDone",
"=",
"append",
"(",
"notDone",
",",
"ref",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"notDone",
"\n",
"}"
] | // getNotDone returns the set of block references in "all" that do not
// yet appear in "results" | [
"getNotDone",
"returns",
"the",
"set",
"of",
"block",
"references",
"in",
"all",
"that",
"do",
"not",
"yet",
"appear",
"in",
"results"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L105-L119 |
158,896 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | BatchDowngradeReferences | func BatchDowngradeReferences(ctx context.Context, log logger.Logger,
tlfID tlf.ID, contexts ContextMap, archive bool,
server keybase1.BlockInterface) (
doneRefs map[ID]map[RefNonce]int, finalError error) {
doneRefs = make(map[ID]map[RefNonce]int)
notDone := getNotDone(contexts, doneRefs)
throttleErr := backoff.Retry(func() error {
var res keybase1.DowngradeReferenceRes
var err error
if archive {
res, err = server.ArchiveReferenceWithCount(ctx,
keybase1.ArchiveReferenceWithCountArg{
Refs: notDone,
Folder: tlfID.String(),
})
} else {
res, err = server.DelReferenceWithCount(ctx,
keybase1.DelReferenceWithCountArg{
Refs: notDone,
Folder: tlfID.String(),
})
}
// log errors
if err != nil {
log.CWarningf(ctx, "batchDowngradeReferences archive=%t sent=%v done=%v failedRef=%v err=%v",
archive, notDone, res.Completed, res.Failed, err)
} else {
log.CDebugf(ctx, "batchDowngradeReferences archive=%t notdone=%v all succeeded",
archive, notDone)
}
// update the set of completed reference
for _, ref := range res.Completed {
bid, err := IDFromString(ref.Ref.Bid.BlockHash)
if err != nil {
continue
}
nonces, ok := doneRefs[bid]
if !ok {
nonces = make(map[RefNonce]int)
doneRefs[bid] = nonces
}
nonces[RefNonce(ref.Ref.Nonce)] = ref.LiveCount
}
// update the list of references to downgrade
notDone = getNotDone(contexts, doneRefs)
//if context is cancelled, return immediately
select {
case <-ctx.Done():
finalError = ctx.Err()
return nil
default:
}
// check whether to backoff and retry
if err != nil {
// if error is of type throttle, retry
if IsThrottleError(err) {
return err
}
// non-throttle error, do not retry here
finalError = err
}
return nil
}, backoff.NewExponentialBackOff())
// if backoff has given up retrying, return error
if throttleErr != nil {
return doneRefs, throttleErr
}
if finalError == nil {
if len(notDone) != 0 {
log.CErrorf(ctx, "batchDowngradeReferences finished successfully with outstanding refs? all=%v done=%v notDone=%v\n", contexts, doneRefs, notDone)
return doneRefs,
errors.New("batchDowngradeReferences inconsistent result")
}
}
return doneRefs, finalError
} | go | func BatchDowngradeReferences(ctx context.Context, log logger.Logger,
tlfID tlf.ID, contexts ContextMap, archive bool,
server keybase1.BlockInterface) (
doneRefs map[ID]map[RefNonce]int, finalError error) {
doneRefs = make(map[ID]map[RefNonce]int)
notDone := getNotDone(contexts, doneRefs)
throttleErr := backoff.Retry(func() error {
var res keybase1.DowngradeReferenceRes
var err error
if archive {
res, err = server.ArchiveReferenceWithCount(ctx,
keybase1.ArchiveReferenceWithCountArg{
Refs: notDone,
Folder: tlfID.String(),
})
} else {
res, err = server.DelReferenceWithCount(ctx,
keybase1.DelReferenceWithCountArg{
Refs: notDone,
Folder: tlfID.String(),
})
}
// log errors
if err != nil {
log.CWarningf(ctx, "batchDowngradeReferences archive=%t sent=%v done=%v failedRef=%v err=%v",
archive, notDone, res.Completed, res.Failed, err)
} else {
log.CDebugf(ctx, "batchDowngradeReferences archive=%t notdone=%v all succeeded",
archive, notDone)
}
// update the set of completed reference
for _, ref := range res.Completed {
bid, err := IDFromString(ref.Ref.Bid.BlockHash)
if err != nil {
continue
}
nonces, ok := doneRefs[bid]
if !ok {
nonces = make(map[RefNonce]int)
doneRefs[bid] = nonces
}
nonces[RefNonce(ref.Ref.Nonce)] = ref.LiveCount
}
// update the list of references to downgrade
notDone = getNotDone(contexts, doneRefs)
//if context is cancelled, return immediately
select {
case <-ctx.Done():
finalError = ctx.Err()
return nil
default:
}
// check whether to backoff and retry
if err != nil {
// if error is of type throttle, retry
if IsThrottleError(err) {
return err
}
// non-throttle error, do not retry here
finalError = err
}
return nil
}, backoff.NewExponentialBackOff())
// if backoff has given up retrying, return error
if throttleErr != nil {
return doneRefs, throttleErr
}
if finalError == nil {
if len(notDone) != 0 {
log.CErrorf(ctx, "batchDowngradeReferences finished successfully with outstanding refs? all=%v done=%v notDone=%v\n", contexts, doneRefs, notDone)
return doneRefs,
errors.New("batchDowngradeReferences inconsistent result")
}
}
return doneRefs, finalError
} | [
"func",
"BatchDowngradeReferences",
"(",
"ctx",
"context",
".",
"Context",
",",
"log",
"logger",
".",
"Logger",
",",
"tlfID",
"tlf",
".",
"ID",
",",
"contexts",
"ContextMap",
",",
"archive",
"bool",
",",
"server",
"keybase1",
".",
"BlockInterface",
")",
"(",
"doneRefs",
"map",
"[",
"ID",
"]",
"map",
"[",
"RefNonce",
"]",
"int",
",",
"finalError",
"error",
")",
"{",
"doneRefs",
"=",
"make",
"(",
"map",
"[",
"ID",
"]",
"map",
"[",
"RefNonce",
"]",
"int",
")",
"\n",
"notDone",
":=",
"getNotDone",
"(",
"contexts",
",",
"doneRefs",
")",
"\n\n",
"throttleErr",
":=",
"backoff",
".",
"Retry",
"(",
"func",
"(",
")",
"error",
"{",
"var",
"res",
"keybase1",
".",
"DowngradeReferenceRes",
"\n",
"var",
"err",
"error",
"\n",
"if",
"archive",
"{",
"res",
",",
"err",
"=",
"server",
".",
"ArchiveReferenceWithCount",
"(",
"ctx",
",",
"keybase1",
".",
"ArchiveReferenceWithCountArg",
"{",
"Refs",
":",
"notDone",
",",
"Folder",
":",
"tlfID",
".",
"String",
"(",
")",
",",
"}",
")",
"\n",
"}",
"else",
"{",
"res",
",",
"err",
"=",
"server",
".",
"DelReferenceWithCount",
"(",
"ctx",
",",
"keybase1",
".",
"DelReferenceWithCountArg",
"{",
"Refs",
":",
"notDone",
",",
"Folder",
":",
"tlfID",
".",
"String",
"(",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"// log errors",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"CWarningf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"archive",
",",
"notDone",
",",
"res",
".",
"Completed",
",",
"res",
".",
"Failed",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"archive",
",",
"notDone",
")",
"\n",
"}",
"\n\n",
"// update the set of completed reference",
"for",
"_",
",",
"ref",
":=",
"range",
"res",
".",
"Completed",
"{",
"bid",
",",
"err",
":=",
"IDFromString",
"(",
"ref",
".",
"Ref",
".",
"Bid",
".",
"BlockHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"nonces",
",",
"ok",
":=",
"doneRefs",
"[",
"bid",
"]",
"\n",
"if",
"!",
"ok",
"{",
"nonces",
"=",
"make",
"(",
"map",
"[",
"RefNonce",
"]",
"int",
")",
"\n",
"doneRefs",
"[",
"bid",
"]",
"=",
"nonces",
"\n",
"}",
"\n",
"nonces",
"[",
"RefNonce",
"(",
"ref",
".",
"Ref",
".",
"Nonce",
")",
"]",
"=",
"ref",
".",
"LiveCount",
"\n",
"}",
"\n",
"// update the list of references to downgrade",
"notDone",
"=",
"getNotDone",
"(",
"contexts",
",",
"doneRefs",
")",
"\n\n",
"//if context is cancelled, return immediately",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"finalError",
"=",
"ctx",
".",
"Err",
"(",
")",
"\n",
"return",
"nil",
"\n",
"default",
":",
"}",
"\n\n",
"// check whether to backoff and retry",
"if",
"err",
"!=",
"nil",
"{",
"// if error is of type throttle, retry",
"if",
"IsThrottleError",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// non-throttle error, do not retry here",
"finalError",
"=",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
",",
"backoff",
".",
"NewExponentialBackOff",
"(",
")",
")",
"\n\n",
"// if backoff has given up retrying, return error",
"if",
"throttleErr",
"!=",
"nil",
"{",
"return",
"doneRefs",
",",
"throttleErr",
"\n",
"}",
"\n\n",
"if",
"finalError",
"==",
"nil",
"{",
"if",
"len",
"(",
"notDone",
")",
"!=",
"0",
"{",
"log",
".",
"CErrorf",
"(",
"ctx",
",",
"\"",
"\\n",
"\"",
",",
"contexts",
",",
"doneRefs",
",",
"notDone",
")",
"\n",
"return",
"doneRefs",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"doneRefs",
",",
"finalError",
"\n",
"}"
] | // BatchDowngradeReferences archives or deletes a batch of references,
// handling all batching and throttles. | [
"BatchDowngradeReferences",
"archives",
"or",
"deletes",
"a",
"batch",
"of",
"references",
"handling",
"all",
"batching",
"and",
"throttles",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L123-L205 |
158,897 | keybase/client | go/kbfs/kbfsblock/protocol_utils.go | GetLiveCounts | func GetLiveCounts(doneRefs map[ID]map[RefNonce]int) map[ID]int {
liveCounts := make(map[ID]int)
for id, nonces := range doneRefs {
for _, count := range nonces {
if existing, ok := liveCounts[id]; !ok || existing > count {
liveCounts[id] = count
}
}
}
return liveCounts
} | go | func GetLiveCounts(doneRefs map[ID]map[RefNonce]int) map[ID]int {
liveCounts := make(map[ID]int)
for id, nonces := range doneRefs {
for _, count := range nonces {
if existing, ok := liveCounts[id]; !ok || existing > count {
liveCounts[id] = count
}
}
}
return liveCounts
} | [
"func",
"GetLiveCounts",
"(",
"doneRefs",
"map",
"[",
"ID",
"]",
"map",
"[",
"RefNonce",
"]",
"int",
")",
"map",
"[",
"ID",
"]",
"int",
"{",
"liveCounts",
":=",
"make",
"(",
"map",
"[",
"ID",
"]",
"int",
")",
"\n",
"for",
"id",
",",
"nonces",
":=",
"range",
"doneRefs",
"{",
"for",
"_",
",",
"count",
":=",
"range",
"nonces",
"{",
"if",
"existing",
",",
"ok",
":=",
"liveCounts",
"[",
"id",
"]",
";",
"!",
"ok",
"||",
"existing",
">",
"count",
"{",
"liveCounts",
"[",
"id",
"]",
"=",
"count",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"liveCounts",
"\n",
"}"
] | // GetLiveCounts computes the maximum live count for each ID over its
// RefNonces. | [
"GetLiveCounts",
"computes",
"the",
"maximum",
"live",
"count",
"for",
"each",
"ID",
"over",
"its",
"RefNonces",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsblock/protocol_utils.go#L209-L219 |
158,898 | keybase/client | go/chat/supersedes.go | transformDelete | func (t *basicSupersedesTransform) transformDelete(msg chat1.MessageUnboxed, superMsg chat1.MessageUnboxed) *chat1.MessageUnboxed {
mvalid := msg.Valid()
if !mvalid.IsEphemeral() {
return nil
}
explodedBy := superMsg.Valid().SenderUsername
mvalid.ClientHeader.EphemeralMetadata.ExplodedBy = &explodedBy
newMsg := chat1.NewMessageUnboxedWithValid(mvalid)
return &newMsg
} | go | func (t *basicSupersedesTransform) transformDelete(msg chat1.MessageUnboxed, superMsg chat1.MessageUnboxed) *chat1.MessageUnboxed {
mvalid := msg.Valid()
if !mvalid.IsEphemeral() {
return nil
}
explodedBy := superMsg.Valid().SenderUsername
mvalid.ClientHeader.EphemeralMetadata.ExplodedBy = &explodedBy
newMsg := chat1.NewMessageUnboxedWithValid(mvalid)
return &newMsg
} | [
"func",
"(",
"t",
"*",
"basicSupersedesTransform",
")",
"transformDelete",
"(",
"msg",
"chat1",
".",
"MessageUnboxed",
",",
"superMsg",
"chat1",
".",
"MessageUnboxed",
")",
"*",
"chat1",
".",
"MessageUnboxed",
"{",
"mvalid",
":=",
"msg",
".",
"Valid",
"(",
")",
"\n",
"if",
"!",
"mvalid",
".",
"IsEphemeral",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"explodedBy",
":=",
"superMsg",
".",
"Valid",
"(",
")",
".",
"SenderUsername",
"\n",
"mvalid",
".",
"ClientHeader",
".",
"EphemeralMetadata",
".",
"ExplodedBy",
"=",
"&",
"explodedBy",
"\n",
"newMsg",
":=",
"chat1",
".",
"NewMessageUnboxedWithValid",
"(",
"mvalid",
")",
"\n",
"return",
"&",
"newMsg",
"\n",
"}"
] | // This is only relevant for ephemeralMessages that are deleted since we want
// these to show up in the gui as "explode now" | [
"This",
"is",
"only",
"relevant",
"for",
"ephemeralMessages",
"that",
"are",
"deleted",
"since",
"we",
"want",
"these",
"to",
"show",
"up",
"in",
"the",
"gui",
"as",
"explode",
"now"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/supersedes.go#L48-L57 |
158,899 | keybase/client | go/tools/runquiet/runquiet.go | makeCmdLine | func makeCmdLine(args []string) string {
var s string
for _, v := range args {
if s != "" {
s += " "
}
s += syscall.EscapeArg(v)
}
return s
} | go | func makeCmdLine(args []string) string {
var s string
for _, v := range args {
if s != "" {
s += " "
}
s += syscall.EscapeArg(v)
}
return s
} | [
"func",
"makeCmdLine",
"(",
"args",
"[",
"]",
"string",
")",
"string",
"{",
"var",
"s",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"args",
"{",
"if",
"s",
"!=",
"\"",
"\"",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
"+=",
"syscall",
".",
"EscapeArg",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // makeCmdLine builds a command line out of args by escaping "special"
// characters and joining the arguments with spaces. | [
"makeCmdLine",
"builds",
"a",
"command",
"line",
"out",
"of",
"args",
"by",
"escaping",
"special",
"characters",
"and",
"joining",
"the",
"arguments",
"with",
"spaces",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/tools/runquiet/runquiet.go#L70-L79 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.