repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
gopasspw/gopass
pkg/tree/simple/folder.go
FindFolder
func (f *Folder) FindFolder(name string) (tree.Tree, error) { sub := f.findFolder(strings.Split(strings.TrimSuffix(name, sep), sep)) if sub == nil { return nil, errors.Errorf("Entry not found") } return sub, nil }
go
func (f *Folder) FindFolder(name string) (tree.Tree, error) { sub := f.findFolder(strings.Split(strings.TrimSuffix(name, sep), sep)) if sub == nil { return nil, errors.Errorf("Entry not found") } return sub, nil }
[ "func", "(", "f", "*", "Folder", ")", "FindFolder", "(", "name", "string", ")", "(", "tree", ".", "Tree", ",", "error", ")", "{", "sub", ":=", "f", ".", "findFolder", "(", "strings", ".", "Split", "(", "strings", ".", "TrimSuffix", "(", "name", ",", "sep", ")", ",", "sep", ")", ")", "\n", "if", "sub", "==", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"Entry not found\"", ")", "\n", "}", "\n", "return", "sub", ",", "nil", "\n", "}" ]
// FindFolder returns a sub-tree or nil, if the subtree does not exist
[ "FindFolder", "returns", "a", "sub", "-", "tree", "or", "nil", "if", "the", "subtree", "does", "not", "exist" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L203-L209
train
gopasspw/gopass
pkg/tree/simple/folder.go
findFolder
func (f *Folder) findFolder(path []string) *Folder { if len(path) < 1 { return f } name := path[0] if next, found := f.Folders[name]; found { return next.findFolder(path[1:]) } return nil }
go
func (f *Folder) findFolder(path []string) *Folder { if len(path) < 1 { return f } name := path[0] if next, found := f.Folders[name]; found { return next.findFolder(path[1:]) } return nil }
[ "func", "(", "f", "*", "Folder", ")", "findFolder", "(", "path", "[", "]", "string", ")", "*", "Folder", "{", "if", "len", "(", "path", ")", "<", "1", "{", "return", "f", "\n", "}", "\n", "name", ":=", "path", "[", "0", "]", "\n", "if", "next", ",", "found", ":=", "f", ".", "Folders", "[", "name", "]", ";", "found", "{", "return", "next", ".", "findFolder", "(", "path", "[", "1", ":", "]", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// findFolder recursively tries to find the named sub-folder
[ "findFolder", "recursively", "tries", "to", "find", "the", "named", "sub", "-", "folder" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L212-L221
train
gopasspw/gopass
pkg/tree/simple/folder.go
addFile
func (f *Folder) addFile(path []string, contentType string) error { if len(path) < 1 { return errors.Errorf("Path must not be empty") } name := path[0] if len(path) == 1 { if _, found := f.Files[name]; found { return errors.Errorf("File %s exists", name) } f.Files[name] = &File{ Name: name, Metadata: map[string]string{ "Content-Type": contentType, }, } return nil } next := f.getFolder(name) return next.addFile(path[1:], contentType) }
go
func (f *Folder) addFile(path []string, contentType string) error { if len(path) < 1 { return errors.Errorf("Path must not be empty") } name := path[0] if len(path) == 1 { if _, found := f.Files[name]; found { return errors.Errorf("File %s exists", name) } f.Files[name] = &File{ Name: name, Metadata: map[string]string{ "Content-Type": contentType, }, } return nil } next := f.getFolder(name) return next.addFile(path[1:], contentType) }
[ "func", "(", "f", "*", "Folder", ")", "addFile", "(", "path", "[", "]", "string", ",", "contentType", "string", ")", "error", "{", "if", "len", "(", "path", ")", "<", "1", "{", "return", "errors", ".", "Errorf", "(", "\"Path must not be empty\"", ")", "\n", "}", "\n", "name", ":=", "path", "[", "0", "]", "\n", "if", "len", "(", "path", ")", "==", "1", "{", "if", "_", ",", "found", ":=", "f", ".", "Files", "[", "name", "]", ";", "found", "{", "return", "errors", ".", "Errorf", "(", "\"File %s exists\"", ",", "name", ")", "\n", "}", "\n", "f", ".", "Files", "[", "name", "]", "=", "&", "File", "{", "Name", ":", "name", ",", "Metadata", ":", "map", "[", "string", "]", "string", "{", "\"Content-Type\"", ":", "contentType", ",", "}", ",", "}", "\n", "return", "nil", "\n", "}", "\n", "next", ":=", "f", ".", "getFolder", "(", "name", ")", "\n", "return", "next", ".", "addFile", "(", "path", "[", "1", ":", "]", ",", "contentType", ")", "\n", "}" ]
// addFile adds new file
[ "addFile", "adds", "new", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L224-L243
train
gopasspw/gopass
pkg/jsonapi/api.go
ReadAndRespond
func (api *API) ReadAndRespond(ctx context.Context) error { silentCtx := out.WithHidden(ctx, true) message, err := readMessage(api.Reader) if message == nil || err != nil { return err } return api.respondMessage(silentCtx, message) }
go
func (api *API) ReadAndRespond(ctx context.Context) error { silentCtx := out.WithHidden(ctx, true) message, err := readMessage(api.Reader) if message == nil || err != nil { return err } return api.respondMessage(silentCtx, message) }
[ "func", "(", "api", "*", "API", ")", "ReadAndRespond", "(", "ctx", "context", ".", "Context", ")", "error", "{", "silentCtx", ":=", "out", ".", "WithHidden", "(", "ctx", ",", "true", ")", "\n", "message", ",", "err", ":=", "readMessage", "(", "api", ".", "Reader", ")", "\n", "if", "message", "==", "nil", "||", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "api", ".", "respondMessage", "(", "silentCtx", ",", "message", ")", "\n", "}" ]
// ReadAndRespond a single message
[ "ReadAndRespond", "a", "single", "message" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/api.go#L21-L29
train
gopasspw/gopass
pkg/jsonapi/api.go
RespondError
func (api *API) RespondError(err error) error { var response errorResponse response.Error = err.Error() return sendSerializedJSONMessage(response, api.Writer) }
go
func (api *API) RespondError(err error) error { var response errorResponse response.Error = err.Error() return sendSerializedJSONMessage(response, api.Writer) }
[ "func", "(", "api", "*", "API", ")", "RespondError", "(", "err", "error", ")", "error", "{", "var", "response", "errorResponse", "\n", "response", ".", "Error", "=", "err", ".", "Error", "(", ")", "\n", "return", "sendSerializedJSONMessage", "(", "response", ",", "api", ".", "Writer", ")", "\n", "}" ]
// RespondError sends err as JSON response
[ "RespondError", "sends", "err", "as", "JSON", "response" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/api.go#L32-L37
train
gopasspw/gopass
pkg/pinentry/pinentry.go
New
func New() (*Client, error) { cmd := exec.Command(GetBinary()) stdin, err := cmd.StdinPipe() if err != nil { return nil, err } stdout, err := cmd.StdoutPipe() if err != nil { return nil, err } br := bufio.NewReader(stdout) if err := cmd.Start(); err != nil { return nil, err } // check welcome message banner, _, err := br.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(banner, []byte("OK")) { return nil, fmt.Errorf("wrong banner: %s", banner) } cl := &Client{ cmd: cmd, in: stdin, out: br, } return cl, nil }
go
func New() (*Client, error) { cmd := exec.Command(GetBinary()) stdin, err := cmd.StdinPipe() if err != nil { return nil, err } stdout, err := cmd.StdoutPipe() if err != nil { return nil, err } br := bufio.NewReader(stdout) if err := cmd.Start(); err != nil { return nil, err } // check welcome message banner, _, err := br.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(banner, []byte("OK")) { return nil, fmt.Errorf("wrong banner: %s", banner) } cl := &Client{ cmd: cmd, in: stdin, out: br, } return cl, nil }
[ "func", "New", "(", ")", "(", "*", "Client", ",", "error", ")", "{", "cmd", ":=", "exec", ".", "Command", "(", "GetBinary", "(", ")", ")", "\n", "stdin", ",", "err", ":=", "cmd", ".", "StdinPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "stdout", ",", "err", ":=", "cmd", ".", "StdoutPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "br", ":=", "bufio", ".", "NewReader", "(", "stdout", ")", "\n", "if", "err", ":=", "cmd", ".", "Start", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "banner", ",", "_", ",", "err", ":=", "br", ".", "ReadLine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "bytes", ".", "HasPrefix", "(", "banner", ",", "[", "]", "byte", "(", "\"OK\"", ")", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"wrong banner: %s\"", ",", "banner", ")", "\n", "}", "\n", "cl", ":=", "&", "Client", "{", "cmd", ":", "cmd", ",", "in", ":", "stdin", ",", "out", ":", "br", ",", "}", "\n", "return", "cl", ",", "nil", "\n", "}" ]
// New creates a new pinentry client
[ "New", "creates", "a", "new", "pinentry", "client" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L22-L55
train
gopasspw/gopass
pkg/pinentry/pinentry.go
Confirm
func (c *Client) Confirm() bool { if err := c.Set("confirm", ""); err == nil { return true } return false }
go
func (c *Client) Confirm() bool { if err := c.Set("confirm", ""); err == nil { return true } return false }
[ "func", "(", "c", "*", "Client", ")", "Confirm", "(", ")", "bool", "{", "if", "err", ":=", "c", ".", "Set", "(", "\"confirm\"", ",", "\"\"", ")", ";", "err", "==", "nil", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Confirm sends the confirm message
[ "Confirm", "sends", "the", "confirm", "message" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L63-L68
train
gopasspw/gopass
pkg/pinentry/pinentry.go
Set
func (c *Client) Set(key, value string) error { key = strings.ToUpper(key) if value != "" { value = " " + value } val := "SET" + key + value + "\n" if _, err := c.in.Write([]byte(val)); err != nil { return err } line, _, _ := c.out.ReadLine() if string(line) != "OK" { return errors.Errorf("error: %s", line) } return nil }
go
func (c *Client) Set(key, value string) error { key = strings.ToUpper(key) if value != "" { value = " " + value } val := "SET" + key + value + "\n" if _, err := c.in.Write([]byte(val)); err != nil { return err } line, _, _ := c.out.ReadLine() if string(line) != "OK" { return errors.Errorf("error: %s", line) } return nil }
[ "func", "(", "c", "*", "Client", ")", "Set", "(", "key", ",", "value", "string", ")", "error", "{", "key", "=", "strings", ".", "ToUpper", "(", "key", ")", "\n", "if", "value", "!=", "\"\"", "{", "value", "=", "\" \"", "+", "value", "\n", "}", "\n", "val", ":=", "\"SET\"", "+", "key", "+", "value", "+", "\"\\n\"", "\n", "\\n", "\n", "if", "_", ",", "err", ":=", "c", ".", "in", ".", "Write", "(", "[", "]", "byte", "(", "val", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "line", ",", "_", ",", "_", ":=", "c", ".", "out", ".", "ReadLine", "(", ")", "\n", "if", "string", "(", "line", ")", "!=", "\"OK\"", "{", "return", "errors", ".", "Errorf", "(", "\"error: %s\"", ",", "line", ")", "\n", "}", "\n", "}" ]
// Set sets a key
[ "Set", "sets", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L71-L85
train
gopasspw/gopass
pkg/pinentry/pinentry.go
GetPin
func (c *Client) GetPin() ([]byte, error) { if _, err := c.in.Write([]byte("GETPIN\n")); err != nil { return nil, err } pin, _, err := c.out.ReadLine() if err != nil { return nil, err } if bytes.HasPrefix(pin, []byte("OK")) { return nil, nil } if !bytes.HasPrefix(pin, []byte("D ")) { return nil, fmt.Errorf("unexpected response: %s", pin) } ok, _, err := c.out.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(ok, []byte("OK")) { return nil, fmt.Errorf("unexpected response: %s", ok) } return pin[2:], nil }
go
func (c *Client) GetPin() ([]byte, error) { if _, err := c.in.Write([]byte("GETPIN\n")); err != nil { return nil, err } pin, _, err := c.out.ReadLine() if err != nil { return nil, err } if bytes.HasPrefix(pin, []byte("OK")) { return nil, nil } if !bytes.HasPrefix(pin, []byte("D ")) { return nil, fmt.Errorf("unexpected response: %s", pin) } ok, _, err := c.out.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(ok, []byte("OK")) { return nil, fmt.Errorf("unexpected response: %s", ok) } return pin[2:], nil }
[ "func", "(", "c", "*", "Client", ")", "GetPin", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "c", ".", "in", ".", "Write", "(", "[", "]", "byte", "(", "\"GETPIN\\n\"", ")", ")", ";", "\\n", "err", "!=", "nil", "\n", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pin", ",", "_", ",", "err", ":=", "c", ".", "out", ".", "ReadLine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "bytes", ".", "HasPrefix", "(", "pin", ",", "[", "]", "byte", "(", "\"OK\"", ")", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "if", "!", "bytes", ".", "HasPrefix", "(", "pin", ",", "[", "]", "byte", "(", "\"D \"", ")", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"unexpected response: %s\"", ",", "pin", ")", "\n", "}", "\n", "ok", ",", "_", ",", "err", ":=", "c", ".", "out", ".", "ReadLine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "bytes", ".", "HasPrefix", "(", "ok", ",", "[", "]", "byte", "(", "\"OK\"", ")", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"unexpected response: %s\"", ",", "ok", ")", "\n", "}", "\n", "}" ]
// GetPin asks for the pin
[ "GetPin", "asks", "for", "the", "pin" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L88-L111
train
gopasspw/gopass
pkg/action/config.go
Config
func (s *Action) Config(ctx context.Context, c *cli.Context) error { if len(c.Args()) < 1 { s.printConfigValues(ctx, "") return nil } if len(c.Args()) == 1 { s.printConfigValues(ctx, "", c.Args()[0]) return nil } if len(c.Args()) > 2 { return ExitError(ctx, ExitUsage, nil, "Usage: %s config key value", s.Name) } if err := s.setConfigValue(ctx, c.String("store"), c.Args()[0], c.Args()[1]); err != nil { return ExitError(ctx, ExitUnknown, err, "Error setting config value") } return nil }
go
func (s *Action) Config(ctx context.Context, c *cli.Context) error { if len(c.Args()) < 1 { s.printConfigValues(ctx, "") return nil } if len(c.Args()) == 1 { s.printConfigValues(ctx, "", c.Args()[0]) return nil } if len(c.Args()) > 2 { return ExitError(ctx, ExitUsage, nil, "Usage: %s config key value", s.Name) } if err := s.setConfigValue(ctx, c.String("store"), c.Args()[0], c.Args()[1]); err != nil { return ExitError(ctx, ExitUnknown, err, "Error setting config value") } return nil }
[ "func", "(", "s", "*", "Action", ")", "Config", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "len", "(", "c", ".", "Args", "(", ")", ")", "<", "1", "{", "s", ".", "printConfigValues", "(", "ctx", ",", "\"\"", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "len", "(", "c", ".", "Args", "(", ")", ")", "==", "1", "{", "s", ".", "printConfigValues", "(", "ctx", ",", "\"\"", ",", "c", ".", "Args", "(", ")", "[", "0", "]", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "len", "(", "c", ".", "Args", "(", ")", ")", ">", "2", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s config key value\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "setConfigValue", "(", "ctx", ",", "c", ".", "String", "(", "\"store\"", ")", ",", "c", ".", "Args", "(", ")", "[", "0", "]", ",", "c", ".", "Args", "(", ")", "[", "1", "]", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"Error setting config value\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Config handles changes to the gopass configuration
[ "Config", "handles", "changes", "to", "the", "gopass", "configuration" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/config.go#L15-L34
train
gopasspw/gopass
pkg/action/config.go
ConfigComplete
func (s *Action) ConfigComplete(c *cli.Context) { cm := s.cfg.Root.ConfigMap() keys := make([]string, 0, len(cm)) for k := range cm { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { fmt.Fprintln(stdout, k) } }
go
func (s *Action) ConfigComplete(c *cli.Context) { cm := s.cfg.Root.ConfigMap() keys := make([]string, 0, len(cm)) for k := range cm { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { fmt.Fprintln(stdout, k) } }
[ "func", "(", "s", "*", "Action", ")", "ConfigComplete", "(", "c", "*", "cli", ".", "Context", ")", "{", "cm", ":=", "s", ".", "cfg", ".", "Root", ".", "ConfigMap", "(", ")", "\n", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "cm", ")", ")", "\n", "for", "k", ":=", "range", "cm", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "for", "_", ",", "k", ":=", "range", "keys", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "k", ")", "\n", "}", "\n", "}" ]
// ConfigComplete will print the list of valid config keys
[ "ConfigComplete", "will", "print", "the", "list", "of", "valid", "config", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/config.go#L101-L111
train
gopasspw/gopass
pkg/fsutil/umask.go
Umask
func Umask() int { for _, en := range []string{"GOPASS_UMASK", "PASSWORD_STORE_UMASK"} { if um := os.Getenv(en); um != "" { if iv, err := strconv.ParseInt(um, 8, 32); err == nil && iv >= 0 && iv <= 0777 { return int(iv) } } } return 077 }
go
func Umask() int { for _, en := range []string{"GOPASS_UMASK", "PASSWORD_STORE_UMASK"} { if um := os.Getenv(en); um != "" { if iv, err := strconv.ParseInt(um, 8, 32); err == nil && iv >= 0 && iv <= 0777 { return int(iv) } } } return 077 }
[ "func", "Umask", "(", ")", "int", "{", "for", "_", ",", "en", ":=", "range", "[", "]", "string", "{", "\"GOPASS_UMASK\"", ",", "\"PASSWORD_STORE_UMASK\"", "}", "{", "if", "um", ":=", "os", ".", "Getenv", "(", "en", ")", ";", "um", "!=", "\"\"", "{", "if", "iv", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "um", ",", "8", ",", "32", ")", ";", "err", "==", "nil", "&&", "iv", ">=", "0", "&&", "iv", "<=", "0777", "{", "return", "int", "(", "iv", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "077", "\n", "}" ]
// Umask extracts the umask from env
[ "Umask", "extracts", "the", "umask", "from", "env" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/fsutil/umask.go#L9-L18
train
gopasspw/gopass
pkg/store/root/init.go
Initialized
func (r *Store) Initialized(ctx context.Context) (bool, error) { if r.store == nil { out.Debug(ctx, "initializing store and possible sub-stores") if err := r.initialize(ctx); err != nil { return false, errors.Wrapf(err, "failed to initialized stores: %s", err) } } return r.store.Initialized(ctx), nil }
go
func (r *Store) Initialized(ctx context.Context) (bool, error) { if r.store == nil { out.Debug(ctx, "initializing store and possible sub-stores") if err := r.initialize(ctx); err != nil { return false, errors.Wrapf(err, "failed to initialized stores: %s", err) } } return r.store.Initialized(ctx), nil }
[ "func", "(", "r", "*", "Store", ")", "Initialized", "(", "ctx", "context", ".", "Context", ")", "(", "bool", ",", "error", ")", "{", "if", "r", ".", "store", "==", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"initializing store and possible sub-stores\"", ")", "\n", "if", "err", ":=", "r", ".", "initialize", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to initialized stores: %s\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "r", ".", "store", ".", "Initialized", "(", "ctx", ")", ",", "nil", "\n", "}" ]
// Initialized checks on disk if .gpg-id was generated and thus returns true.
[ "Initialized", "checks", "on", "disk", "if", ".", "gpg", "-", "id", "was", "generated", "and", "thus", "returns", "true", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/init.go#L16-L24
train
gopasspw/gopass
pkg/hibp/api/client.go
Lookup
func Lookup(ctx context.Context, shaSum string) (uint64, error) { if len(shaSum) != 40 { return 0, errors.Errorf("invalid shasum") } shaSum = strings.ToUpper(shaSum) prefix := shaSum[:5] suffix := shaSum[5:] var count uint64 url := fmt.Sprintf("%s/range/%s", URL, prefix) op := func() error { out.Debug(ctx, "[%s] HTTP Request: %s", shaSum, url) resp, err := http.Get(url) if err != nil { return err } defer func() { _ = resp.Body.Close() }() if resp.StatusCode == http.StatusNotFound { return nil } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } if resp.StatusCode != http.StatusOK { return fmt.Errorf("HTTP request failed: %s %s", resp.Status, body) } for _, line := range strings.Split(string(body), "\n") { line = strings.TrimSpace(line) if len(line) < 37 { continue } if line[:35] != suffix { continue } if iv, err := strconv.ParseUint(line[36:], 10, 64); err == nil { count = iv return nil } } return nil } bo := backoff.NewExponentialBackOff() bo.MaxElapsedTime = 10 * time.Second err := backoff.Retry(op, bo) return count, err }
go
func Lookup(ctx context.Context, shaSum string) (uint64, error) { if len(shaSum) != 40 { return 0, errors.Errorf("invalid shasum") } shaSum = strings.ToUpper(shaSum) prefix := shaSum[:5] suffix := shaSum[5:] var count uint64 url := fmt.Sprintf("%s/range/%s", URL, prefix) op := func() error { out.Debug(ctx, "[%s] HTTP Request: %s", shaSum, url) resp, err := http.Get(url) if err != nil { return err } defer func() { _ = resp.Body.Close() }() if resp.StatusCode == http.StatusNotFound { return nil } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } if resp.StatusCode != http.StatusOK { return fmt.Errorf("HTTP request failed: %s %s", resp.Status, body) } for _, line := range strings.Split(string(body), "\n") { line = strings.TrimSpace(line) if len(line) < 37 { continue } if line[:35] != suffix { continue } if iv, err := strconv.ParseUint(line[36:], 10, 64); err == nil { count = iv return nil } } return nil } bo := backoff.NewExponentialBackOff() bo.MaxElapsedTime = 10 * time.Second err := backoff.Retry(op, bo) return count, err }
[ "func", "Lookup", "(", "ctx", "context", ".", "Context", ",", "shaSum", "string", ")", "(", "uint64", ",", "error", ")", "{", "if", "len", "(", "shaSum", ")", "!=", "40", "{", "return", "0", ",", "errors", ".", "Errorf", "(", "\"invalid shasum\"", ")", "\n", "}", "\n", "shaSum", "=", "strings", ".", "ToUpper", "(", "shaSum", ")", "\n", "prefix", ":=", "shaSum", "[", ":", "5", "]", "\n", "suffix", ":=", "shaSum", "[", "5", ":", "]", "\n", "var", "count", "uint64", "\n", "url", ":=", "fmt", ".", "Sprintf", "(", "\"%s/range/%s\"", ",", "URL", ",", "prefix", ")", "\n", "op", ":=", "func", "(", ")", "error", "{", "out", ".", "Debug", "(", "ctx", ",", "\"[%s] HTTP Request: %s\"", ",", "shaSum", ",", "url", ")", "\n", "resp", ",", "err", ":=", "http", ".", "Get", "(", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "_", "=", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "}", "(", ")", "\n", "if", "resp", ".", "StatusCode", "==", "http", ".", "StatusNotFound", "{", "return", "nil", "\n", "}", "\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "resp", ".", "StatusCode", "!=", "http", ".", "StatusOK", "{", "return", "fmt", ".", "Errorf", "(", "\"HTTP request failed: %s %s\"", ",", "resp", ".", "Status", ",", "body", ")", "\n", "}", "\n", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "string", "(", "body", ")", ",", "\"\\n\"", ")", "\\n", "\n", "{", "line", "=", "strings", ".", "TrimSpace", "(", "line", ")", "\n", "if", "len", "(", "line", ")", "<", "37", "{", "continue", "\n", "}", "\n", "if", "line", "[", ":", "35", "]", "!=", "suffix", "{", "continue", "\n", "}", "\n", "if", "iv", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "line", "[", "36", ":", "]", ",", "10", ",", "64", ")", ";", "err", "==", "nil", "{", "count", "=", "iv", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "bo", ":=", "backoff", ".", "NewExponentialBackOff", "(", ")", "\n", "bo", ".", "MaxElapsedTime", "=", "10", "*", "time", ".", "Second", "\n", "err", ":=", "backoff", ".", "Retry", "(", "op", ",", "bo", ")", "\n", "}" ]
// Lookup performs a lookup against the HIBP v2 API
[ "Lookup", "performs", "a", "lookup", "against", "the", "HIBP", "v2", "API" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/hibp/api/client.go#L22-L78
train
gopasspw/gopass
pkg/action/git.go
GitInit
func (s *Action) GitInit(ctx context.Context, c *cli.Context) error { store := c.String("store") un := c.String("username") ue := c.String("useremail") ctx = backend.WithRCSBackendString(ctx, c.String("rcs")) // default to git if !backend.HasRCSBackend(ctx) { ctx = backend.WithRCSBackend(ctx, backend.GitCLI) } if err := s.rcsInit(ctx, store, un, ue); err != nil { return ExitError(ctx, ExitGit, err, "failed to initialize git: %s", err) } return nil }
go
func (s *Action) GitInit(ctx context.Context, c *cli.Context) error { store := c.String("store") un := c.String("username") ue := c.String("useremail") ctx = backend.WithRCSBackendString(ctx, c.String("rcs")) // default to git if !backend.HasRCSBackend(ctx) { ctx = backend.WithRCSBackend(ctx, backend.GitCLI) } if err := s.rcsInit(ctx, store, un, ue); err != nil { return ExitError(ctx, ExitGit, err, "failed to initialize git: %s", err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "GitInit", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"store\"", ")", "\n", "un", ":=", "c", ".", "String", "(", "\"username\"", ")", "\n", "ue", ":=", "c", ".", "String", "(", "\"useremail\"", ")", "\n", "ctx", "=", "backend", ".", "WithRCSBackendString", "(", "ctx", ",", "c", ".", "String", "(", "\"rcs\"", ")", ")", "\n", "if", "!", "backend", ".", "HasRCSBackend", "(", "ctx", ")", "{", "ctx", "=", "backend", ".", "WithRCSBackend", "(", "ctx", ",", "backend", ".", "GitCLI", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "rcsInit", "(", "ctx", ",", "store", ",", "un", ",", "ue", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitGit", ",", "err", ",", "\"failed to initialize git: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GitInit initializes a git repo including basic configuration
[ "GitInit", "initializes", "a", "git", "repo", "including", "basic", "configuration" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L18-L33
train
gopasspw/gopass
pkg/action/git.go
GitAddRemote
func (s *Action) GitAddRemote(ctx context.Context, c *cli.Context) error { store := c.String("store") remote := c.Args().Get(0) url := c.Args().Get(1) if remote == "" || url == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git remote add <REMOTE> <URL>", s.Name) } return s.Store.GitAddRemote(ctx, store, remote, url) }
go
func (s *Action) GitAddRemote(ctx context.Context, c *cli.Context) error { store := c.String("store") remote := c.Args().Get(0) url := c.Args().Get(1) if remote == "" || url == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git remote add <REMOTE> <URL>", s.Name) } return s.Store.GitAddRemote(ctx, store, remote, url) }
[ "func", "(", "s", "*", "Action", ")", "GitAddRemote", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"store\"", ")", "\n", "remote", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "url", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n", "if", "remote", "==", "\"\"", "||", "url", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s git remote add <REMOTE> <URL>\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "return", "s", ".", "Store", ".", "GitAddRemote", "(", "ctx", ",", "store", ",", "remote", ",", "url", ")", "\n", "}" ]
// GitAddRemote adds a new git remote
[ "GitAddRemote", "adds", "a", "new", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L79-L89
train
gopasspw/gopass
pkg/action/git.go
GitPull
func (s *Action) GitPull(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" { origin = "origin" } if branch == "" { branch = "master" } return s.Store.GitPull(ctx, store, origin, branch) }
go
func (s *Action) GitPull(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" { origin = "origin" } if branch == "" { branch = "master" } return s.Store.GitPull(ctx, store, origin, branch) }
[ "func", "(", "s", "*", "Action", ")", "GitPull", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"store\"", ")", "\n", "origin", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "branch", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n", "if", "origin", "==", "\"\"", "{", "origin", "=", "\"origin\"", "\n", "}", "\n", "if", "branch", "==", "\"\"", "{", "branch", "=", "\"master\"", "\n", "}", "\n", "return", "s", ".", "Store", ".", "GitPull", "(", "ctx", ",", "store", ",", "origin", ",", "branch", ")", "\n", "}" ]
// GitPull pulls from a git remote
[ "GitPull", "pulls", "from", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L104-L116
train
gopasspw/gopass
pkg/action/git.go
GitPush
func (s *Action) GitPush(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" || branch == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git push <ORIGIN> <BRANCH>", s.Name) } return s.Store.GitPush(ctx, store, origin, branch) }
go
func (s *Action) GitPush(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" || branch == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git push <ORIGIN> <BRANCH>", s.Name) } return s.Store.GitPush(ctx, store, origin, branch) }
[ "func", "(", "s", "*", "Action", ")", "GitPush", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"store\"", ")", "\n", "origin", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "branch", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n", "if", "origin", "==", "\"\"", "||", "branch", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s git push <ORIGIN> <BRANCH>\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "return", "s", ".", "Store", ".", "GitPush", "(", "ctx", ",", "store", ",", "origin", ",", "branch", ")", "\n", "}" ]
// GitPush pushes to a git remote
[ "GitPush", "pushes", "to", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L119-L128
train
gopasspw/gopass
pkg/store/sub/store.go
New
func New(ctx context.Context, sc recipientHashStorer, alias string, u *backend.URL, cfgdir string, agent *client.Client) (*Store, error) { out.Debug(ctx, "sub.New - URL: %s", u.String()) s := &Store{ alias: alias, url: u, rcs: noop.New(), cfgdir: cfgdir, agent: agent, sc: sc, } // init store backend if backend.HasStorageBackend(ctx) { s.url.Storage = backend.GetStorageBackend(ctx) out.Debug(ctx, "sub.New - Using storage backend from ctx: %s", backend.StorageBackendName(s.url.Storage)) } if err := s.initStorageBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init storage backend: %s", err) } // init sync backend if backend.HasRCSBackend(ctx) { s.url.RCS = backend.GetRCSBackend(ctx) out.Debug(ctx, "sub.New - Using RCS backend from ctx: %s", backend.RCSBackendName(s.url.RCS)) } if err := s.initRCSBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init RCS backend: %s", err) } // init crypto backend if backend.HasCryptoBackend(ctx) { s.url.Crypto = backend.GetCryptoBackend(ctx) out.Debug(ctx, "sub.New - Using Crypto backend from ctx: %s", backend.CryptoBackendName(s.url.Crypto)) } if err := s.initCryptoBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init crypto backend: %s", err) } out.Debug(ctx, "sub.New - initialized - storage: %s (%p) - rcs: %s (%p) - crypto: %s (%p)", s.storage.Name(), s.storage, s.rcs.Name(), s.rcs, s.crypto.Name(), s.crypto) return s, nil }
go
func New(ctx context.Context, sc recipientHashStorer, alias string, u *backend.URL, cfgdir string, agent *client.Client) (*Store, error) { out.Debug(ctx, "sub.New - URL: %s", u.String()) s := &Store{ alias: alias, url: u, rcs: noop.New(), cfgdir: cfgdir, agent: agent, sc: sc, } // init store backend if backend.HasStorageBackend(ctx) { s.url.Storage = backend.GetStorageBackend(ctx) out.Debug(ctx, "sub.New - Using storage backend from ctx: %s", backend.StorageBackendName(s.url.Storage)) } if err := s.initStorageBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init storage backend: %s", err) } // init sync backend if backend.HasRCSBackend(ctx) { s.url.RCS = backend.GetRCSBackend(ctx) out.Debug(ctx, "sub.New - Using RCS backend from ctx: %s", backend.RCSBackendName(s.url.RCS)) } if err := s.initRCSBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init RCS backend: %s", err) } // init crypto backend if backend.HasCryptoBackend(ctx) { s.url.Crypto = backend.GetCryptoBackend(ctx) out.Debug(ctx, "sub.New - Using Crypto backend from ctx: %s", backend.CryptoBackendName(s.url.Crypto)) } if err := s.initCryptoBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init crypto backend: %s", err) } out.Debug(ctx, "sub.New - initialized - storage: %s (%p) - rcs: %s (%p) - crypto: %s (%p)", s.storage.Name(), s.storage, s.rcs.Name(), s.rcs, s.crypto.Name(), s.crypto) return s, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "sc", "recipientHashStorer", ",", "alias", "string", ",", "u", "*", "backend", ".", "URL", ",", "cfgdir", "string", ",", "agent", "*", "client", ".", "Client", ")", "(", "*", "Store", ",", "error", ")", "{", "out", ".", "Debug", "(", "ctx", ",", "\"sub.New - URL: %s\"", ",", "u", ".", "String", "(", ")", ")", "\n", "s", ":=", "&", "Store", "{", "alias", ":", "alias", ",", "url", ":", "u", ",", "rcs", ":", "noop", ".", "New", "(", ")", ",", "cfgdir", ":", "cfgdir", ",", "agent", ":", "agent", ",", "sc", ":", "sc", ",", "}", "\n", "if", "backend", ".", "HasStorageBackend", "(", "ctx", ")", "{", "s", ".", "url", ".", "Storage", "=", "backend", ".", "GetStorageBackend", "(", "ctx", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"sub.New - Using storage backend from ctx: %s\"", ",", "backend", ".", "StorageBackendName", "(", "s", ".", "url", ".", "Storage", ")", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "initStorageBackend", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to init storage backend: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "backend", ".", "HasRCSBackend", "(", "ctx", ")", "{", "s", ".", "url", ".", "RCS", "=", "backend", ".", "GetRCSBackend", "(", "ctx", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"sub.New - Using RCS backend from ctx: %s\"", ",", "backend", ".", "RCSBackendName", "(", "s", ".", "url", ".", "RCS", ")", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "initRCSBackend", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to init RCS backend: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "backend", ".", "HasCryptoBackend", "(", "ctx", ")", "{", "s", ".", "url", ".", "Crypto", "=", "backend", ".", "GetCryptoBackend", "(", "ctx", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"sub.New - Using Crypto backend from ctx: %s\"", ",", "backend", ".", "CryptoBackendName", "(", "s", ".", "url", ".", "Crypto", ")", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "initCryptoBackend", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to init crypto backend: %s\"", ",", "err", ")", "\n", "}", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"sub.New - initialized - storage: %s (%p) - rcs: %s (%p) - crypto: %s (%p)\"", ",", "s", ".", "storage", ".", "Name", "(", ")", ",", "s", ".", "storage", ",", "s", ".", "rcs", ".", "Name", "(", ")", ",", "s", ".", "rcs", ",", "s", ".", "crypto", ".", "Name", "(", ")", ",", "s", ".", "crypto", ")", "\n", "return", "s", ",", "nil", "\n", "}" ]
// New creates a new store, copying settings from the given root store
[ "New", "creates", "a", "new", "store", "copying", "settings", "from", "the", "given", "root", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L42-L83
train
gopasspw/gopass
pkg/store/sub/store.go
idFile
func (s *Store) idFile(ctx context.Context, name string) string { fn := name var cnt uint8 for { cnt++ if cnt > 100 { break } if fn == "" || fn == sep { break } gfn := filepath.Join(fn, s.crypto.IDFile()) if s.storage.Exists(ctx, gfn) { return gfn } fn = filepath.Dir(fn) } return s.crypto.IDFile() }
go
func (s *Store) idFile(ctx context.Context, name string) string { fn := name var cnt uint8 for { cnt++ if cnt > 100 { break } if fn == "" || fn == sep { break } gfn := filepath.Join(fn, s.crypto.IDFile()) if s.storage.Exists(ctx, gfn) { return gfn } fn = filepath.Dir(fn) } return s.crypto.IDFile() }
[ "func", "(", "s", "*", "Store", ")", "idFile", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "string", "{", "fn", ":=", "name", "\n", "var", "cnt", "uint8", "\n", "for", "{", "cnt", "++", "\n", "if", "cnt", ">", "100", "{", "break", "\n", "}", "\n", "if", "fn", "==", "\"\"", "||", "fn", "==", "sep", "{", "break", "\n", "}", "\n", "gfn", ":=", "filepath", ".", "Join", "(", "fn", ",", "s", ".", "crypto", ".", "IDFile", "(", ")", ")", "\n", "if", "s", ".", "storage", ".", "Exists", "(", "ctx", ",", "gfn", ")", "{", "return", "gfn", "\n", "}", "\n", "fn", "=", "filepath", ".", "Dir", "(", "fn", ")", "\n", "}", "\n", "return", "s", ".", "crypto", ".", "IDFile", "(", ")", "\n", "}" ]
// idFile returns the path to the recipient list for this.storage // it walks up from the given filename until it finds a directory containing // a gpg id file or it leaves the scope of this.storage.
[ "idFile", "returns", "the", "path", "to", "the", "recipient", "list", "for", "this", ".", "storage", "it", "walks", "up", "from", "the", "given", "filename", "until", "it", "finds", "a", "directory", "containing", "a", "gpg", "id", "file", "or", "it", "leaves", "the", "scope", "of", "this", ".", "storage", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L88-L106
train
gopasspw/gopass
pkg/store/sub/store.go
Equals
func (s *Store) Equals(other store.Store) bool { if other == nil { return false } return s.URL() == other.URL() }
go
func (s *Store) Equals(other store.Store) bool { if other == nil { return false } return s.URL() == other.URL() }
[ "func", "(", "s", "*", "Store", ")", "Equals", "(", "other", "store", ".", "Store", ")", "bool", "{", "if", "other", "==", "nil", "{", "return", "false", "\n", "}", "\n", "return", "s", ".", "URL", "(", ")", "==", "other", ".", "URL", "(", ")", "\n", "}" ]
// Equals returns true if this.storage has the same on-disk path as the other
[ "Equals", "returns", "true", "if", "this", ".", "storage", "has", "the", "same", "on", "-", "disk", "path", "as", "the", "other" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L109-L114
train
gopasspw/gopass
pkg/store/sub/store.go
IsDir
func (s *Store) IsDir(ctx context.Context, name string) bool { return s.storage.IsDir(ctx, name) }
go
func (s *Store) IsDir(ctx context.Context, name string) bool { return s.storage.IsDir(ctx, name) }
[ "func", "(", "s", "*", "Store", ")", "IsDir", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "bool", "{", "return", "s", ".", "storage", ".", "IsDir", "(", "ctx", ",", "name", ")", "\n", "}" ]
// IsDir returns true if the entry is folder inside the store
[ "IsDir", "returns", "true", "if", "the", "entry", "is", "folder", "inside", "the", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L117-L119
train
gopasspw/gopass
pkg/store/sub/store.go
Path
func (s *Store) Path() string { if s.url == nil { return "" } return s.url.Path }
go
func (s *Store) Path() string { if s.url == nil { return "" } return s.url.Path }
[ "func", "(", "s", "*", "Store", ")", "Path", "(", ")", "string", "{", "if", "s", ".", "url", "==", "nil", "{", "return", "\"\"", "\n", "}", "\n", "return", "s", ".", "url", ".", "Path", "\n", "}" ]
// Path returns the value of path
[ "Path", "returns", "the", "value", "of", "path" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L283-L288
train
gopasspw/gopass
pkg/action/xc/xc.go
ListPrivateKeys
func ListPrivateKeys(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } kl, err := crypto.ListPrivateKeyIDs(ctx) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to list private keys") } out.Print(ctx, "XC Private Keys:") for _, key := range kl { out.Print(ctx, "%s - %s", key, crypto.FormatKey(ctx, key)) } return nil }
go
func ListPrivateKeys(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } kl, err := crypto.ListPrivateKeyIDs(ctx) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to list private keys") } out.Print(ctx, "XC Private Keys:") for _, key := range kl { out.Print(ctx, "%s - %s", key, crypto.FormatKey(ctx, key)) } return nil }
[ "func", "ListPrivateKeys", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "kl", ",", "err", ":=", "crypto", ".", "ListPrivateKeyIDs", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to list private keys\"", ")", "\n", "}", "\n", "out", ".", "Print", "(", "ctx", ",", "\"XC Private Keys:\"", ")", "\n", "for", "_", ",", "key", ":=", "range", "kl", "{", "out", ".", "Print", "(", "ctx", ",", "\"%s - %s\"", ",", "key", ",", "crypto", ".", "FormatKey", "(", "ctx", ",", "key", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ListPrivateKeys list the XC private keys
[ "ListPrivateKeys", "list", "the", "XC", "private", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L38-L54
train
gopasspw/gopass
pkg/action/xc/xc.go
GenerateKeypair
func GenerateKeypair(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } name := c.String("name") email := c.String("email") pw := c.String("passphrase") if name == "" { var err error name, err = termio.AskForString(ctx, "What is your full name?", "") if err != nil || name == "" { return action.ExitError(ctx, action.ExitNoName, err, "please provide a name") } } if email == "" { var err error email, err = termio.AskForString(ctx, "What is your email?", "") if err != nil || email == "" { return action.ExitError(ctx, action.ExitNoName, err, "please provide an email") } } if pw == "" { var err error pw, err = termio.AskForPassword(ctx, "") if err != nil || pw == "" { return action.ExitError(ctx, action.ExitIO, err, "failed to ask for password: %s", err) } } if err := crypto.CreatePrivateKeyBatch(ctx, name, email, pw); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to create private key: %s", err) } return nil }
go
func GenerateKeypair(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } name := c.String("name") email := c.String("email") pw := c.String("passphrase") if name == "" { var err error name, err = termio.AskForString(ctx, "What is your full name?", "") if err != nil || name == "" { return action.ExitError(ctx, action.ExitNoName, err, "please provide a name") } } if email == "" { var err error email, err = termio.AskForString(ctx, "What is your email?", "") if err != nil || email == "" { return action.ExitError(ctx, action.ExitNoName, err, "please provide an email") } } if pw == "" { var err error pw, err = termio.AskForPassword(ctx, "") if err != nil || pw == "" { return action.ExitError(ctx, action.ExitIO, err, "failed to ask for password: %s", err) } } if err := crypto.CreatePrivateKeyBatch(ctx, name, email, pw); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to create private key: %s", err) } return nil }
[ "func", "GenerateKeypair", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "name", ":=", "c", ".", "String", "(", "\"name\"", ")", "\n", "email", ":=", "c", ".", "String", "(", "\"email\"", ")", "\n", "pw", ":=", "c", ".", "String", "(", "\"passphrase\"", ")", "\n", "if", "name", "==", "\"\"", "{", "var", "err", "error", "\n", "name", ",", "err", "=", "termio", ".", "AskForString", "(", "ctx", ",", "\"What is your full name?\"", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "||", "name", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitNoName", ",", "err", ",", "\"please provide a name\"", ")", "\n", "}", "\n", "}", "\n", "if", "email", "==", "\"\"", "{", "var", "err", "error", "\n", "email", ",", "err", "=", "termio", ".", "AskForString", "(", "ctx", ",", "\"What is your email?\"", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "||", "email", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitNoName", ",", "err", ",", "\"please provide an email\"", ")", "\n", "}", "\n", "}", "\n", "if", "pw", "==", "\"\"", "{", "var", "err", "error", "\n", "pw", ",", "err", "=", "termio", ".", "AskForPassword", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "||", "pw", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to ask for password: %s\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "crypto", ".", "CreatePrivateKeyBatch", "(", "ctx", ",", "name", ",", "email", ",", "pw", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to create private key: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GenerateKeypair generates a new XC keypair
[ "GenerateKeypair", "generates", "a", "new", "XC", "keypair" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L76-L111
train
gopasspw/gopass
pkg/action/xc/xc.go
ExportPrivateKey
func ExportPrivateKey(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } id := c.String("id") file := c.String("file") if id == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need id") } if file == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if fsutil.IsFile(file) { return action.ExitError(ctx, action.ExitUnknown, nil, "output file already exists") } pk, err := crypto.ExportPrivateKey(ctx, id) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to export key: %s", err) } if err := ioutil.WriteFile(file, pk, 0600); err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to write file") } return nil }
go
func ExportPrivateKey(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } id := c.String("id") file := c.String("file") if id == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need id") } if file == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if fsutil.IsFile(file) { return action.ExitError(ctx, action.ExitUnknown, nil, "output file already exists") } pk, err := crypto.ExportPrivateKey(ctx, id) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to export key: %s", err) } if err := ioutil.WriteFile(file, pk, 0600); err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to write file") } return nil }
[ "func", "ExportPrivateKey", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "id", ":=", "c", ".", "String", "(", "\"id\"", ")", "\n", "file", ":=", "c", ".", "String", "(", "\"file\"", ")", "\n", "if", "id", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"need id\"", ")", "\n", "}", "\n", "if", "file", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"need file\"", ")", "\n", "}", "\n", "if", "fsutil", ".", "IsFile", "(", "file", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "nil", ",", "\"output file already exists\"", ")", "\n", "}", "\n", "pk", ",", "err", ":=", "crypto", ".", "ExportPrivateKey", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to export key: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "file", ",", "pk", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to write file\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ExportPrivateKey exports an XC key
[ "ExportPrivateKey", "exports", "an", "XC", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L183-L211
train
gopasspw/gopass
pkg/action/xc/xc.go
ImportPrivateKey
func ImportPrivateKey(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } file := c.String("file") if file == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if !fsutil.IsFile(file) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } buf, err := ioutil.ReadFile(file) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } return crypto.ImportPrivateKey(ctx, buf) }
go
func ImportPrivateKey(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } file := c.String("file") if file == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if !fsutil.IsFile(file) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } buf, err := ioutil.ReadFile(file) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } return crypto.ImportPrivateKey(ctx, buf) }
[ "func", "ImportPrivateKey", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "file", ":=", "c", ".", "String", "(", "\"file\"", ")", "\n", "if", "file", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"need file\"", ")", "\n", "}", "\n", "if", "!", "fsutil", ".", "IsFile", "(", "file", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitNotFound", ",", "nil", ",", "\"input file not found\"", ")", "\n", "}", "\n", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to read file\"", ")", "\n", "}", "\n", "return", "crypto", ".", "ImportPrivateKey", "(", "ctx", ",", "buf", ")", "\n", "}" ]
// ImportPrivateKey imports an XC key
[ "ImportPrivateKey", "imports", "an", "XC", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L214-L234
train
gopasspw/gopass
pkg/action/xc/xc.go
EncryptFile
func EncryptFile(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } if c.Bool("stream") { return EncryptFileStream(ctx, c) } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } recipients := c.StringSlice("recipients") outFile := inFile + ".xc" if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } plaintext, err := ioutil.ReadFile(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } ciphertext, err := crypto.Encrypt(ctx, plaintext, recipients) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to encrypt file: %s", err) } if err := ioutil.WriteFile(outFile, ciphertext, 0600); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to write ciphertext") } return nil }
go
func EncryptFile(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } if c.Bool("stream") { return EncryptFileStream(ctx, c) } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } recipients := c.StringSlice("recipients") outFile := inFile + ".xc" if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } plaintext, err := ioutil.ReadFile(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } ciphertext, err := crypto.Encrypt(ctx, plaintext, recipients) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to encrypt file: %s", err) } if err := ioutil.WriteFile(outFile, ciphertext, 0600); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to write ciphertext") } return nil }
[ "func", "EncryptFile", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "if", "c", ".", "Bool", "(", "\"stream\"", ")", "{", "return", "EncryptFileStream", "(", "ctx", ",", "c", ")", "\n", "}", "\n", "inFile", ":=", "c", ".", "String", "(", "\"file\"", ")", "\n", "if", "inFile", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"need file\"", ")", "\n", "}", "\n", "recipients", ":=", "c", ".", "StringSlice", "(", "\"recipients\"", ")", "\n", "outFile", ":=", "inFile", "+", "\".xc\"", "\n", "if", "!", "fsutil", ".", "IsFile", "(", "inFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitNotFound", ",", "nil", ",", "\"input file not found\"", ")", "\n", "}", "\n", "if", "fsutil", ".", "IsFile", "(", "outFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "nil", ",", "\"output file already exists\"", ")", "\n", "}", "\n", "plaintext", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "inFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to read file\"", ")", "\n", "}", "\n", "ciphertext", ",", "err", ":=", "crypto", ".", "Encrypt", "(", "ctx", ",", "plaintext", ",", "recipients", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to encrypt file: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "outFile", ",", "ciphertext", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to write ciphertext\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// EncryptFile encrypts a single file
[ "EncryptFile", "encrypts", "a", "single", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L237-L273
train
gopasspw/gopass
pkg/action/xc/xc.go
DecryptFile
func DecryptFile(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } if c.Bool("stream") { return DecryptFileStream(ctx, c) } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if !strings.HasSuffix(inFile, ".xc") { return action.ExitError(ctx, action.ExitUsage, nil, "unknown extension. expecting .xc") } outFile := strings.TrimSuffix(inFile, ".xc") if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } ciphertext, err := ioutil.ReadFile(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } plaintext, err := crypto.Decrypt(ctx, ciphertext) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to decrypt file: %s", err) } if err := ioutil.WriteFile(outFile, plaintext, 0600); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to write plaintext") } return nil }
go
func DecryptFile(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } if c.Bool("stream") { return DecryptFileStream(ctx, c) } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if !strings.HasSuffix(inFile, ".xc") { return action.ExitError(ctx, action.ExitUsage, nil, "unknown extension. expecting .xc") } outFile := strings.TrimSuffix(inFile, ".xc") if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } ciphertext, err := ioutil.ReadFile(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } plaintext, err := crypto.Decrypt(ctx, ciphertext) if err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to decrypt file: %s", err) } if err := ioutil.WriteFile(outFile, plaintext, 0600); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to write plaintext") } return nil }
[ "func", "DecryptFile", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "if", "c", ".", "Bool", "(", "\"stream\"", ")", "{", "return", "DecryptFileStream", "(", "ctx", ",", "c", ")", "\n", "}", "\n", "inFile", ":=", "c", ".", "String", "(", "\"file\"", ")", "\n", "if", "inFile", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"need file\"", ")", "\n", "}", "\n", "if", "!", "strings", ".", "HasSuffix", "(", "inFile", ",", "\".xc\"", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"unknown extension. expecting .xc\"", ")", "\n", "}", "\n", "outFile", ":=", "strings", ".", "TrimSuffix", "(", "inFile", ",", "\".xc\"", ")", "\n", "if", "!", "fsutil", ".", "IsFile", "(", "inFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitNotFound", ",", "nil", ",", "\"input file not found\"", ")", "\n", "}", "\n", "if", "fsutil", ".", "IsFile", "(", "outFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "nil", ",", "\"output file already exists\"", ")", "\n", "}", "\n", "ciphertext", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "inFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to read file\"", ")", "\n", "}", "\n", "plaintext", ",", "err", ":=", "crypto", ".", "Decrypt", "(", "ctx", ",", "ciphertext", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to decrypt file: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "outFile", ",", "plaintext", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to write plaintext\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DecryptFile decrypts a single file
[ "DecryptFile", "decrypts", "a", "single", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L276-L315
train
gopasspw/gopass
pkg/action/xc/xc.go
EncryptFileStream
func EncryptFileStream(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } recipients := c.StringSlice("recipients") outFile := inFile + ".xc" if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } plaintext, err := os.Open(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to open file") } defer func() { _ = plaintext.Close() }() ciphertext, err := os.OpenFile(outFile, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to open file") } defer func() { _ = ciphertext.Close() }() if err := crypto.EncryptStream(ctx, plaintext, recipients, ciphertext); err != nil { _ = os.Remove(outFile) return action.ExitError(ctx, action.ExitUnknown, err, "failed to encrypt file: %s", err) } return nil }
go
func EncryptFileStream(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } recipients := c.StringSlice("recipients") outFile := inFile + ".xc" if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } plaintext, err := os.Open(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to open file") } defer func() { _ = plaintext.Close() }() ciphertext, err := os.OpenFile(outFile, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to open file") } defer func() { _ = ciphertext.Close() }() if err := crypto.EncryptStream(ctx, plaintext, recipients, ciphertext); err != nil { _ = os.Remove(outFile) return action.ExitError(ctx, action.ExitUnknown, err, "failed to encrypt file: %s", err) } return nil }
[ "func", "EncryptFileStream", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "inFile", ":=", "c", ".", "String", "(", "\"file\"", ")", "\n", "if", "inFile", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"need file\"", ")", "\n", "}", "\n", "recipients", ":=", "c", ".", "StringSlice", "(", "\"recipients\"", ")", "\n", "outFile", ":=", "inFile", "+", "\".xc\"", "\n", "if", "!", "fsutil", ".", "IsFile", "(", "inFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitNotFound", ",", "nil", ",", "\"input file not found\"", ")", "\n", "}", "\n", "if", "fsutil", ".", "IsFile", "(", "outFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "nil", ",", "\"output file already exists\"", ")", "\n", "}", "\n", "plaintext", ",", "err", ":=", "os", ".", "Open", "(", "inFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to open file\"", ")", "\n", "}", "\n", "defer", "func", "(", ")", "{", "_", "=", "plaintext", ".", "Close", "(", ")", "}", "(", ")", "\n", "ciphertext", ",", "err", ":=", "os", ".", "OpenFile", "(", "outFile", ",", "os", ".", "O_CREATE", "|", "os", ".", "O_WRONLY", ",", "0600", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to open file\"", ")", "\n", "}", "\n", "defer", "func", "(", ")", "{", "_", "=", "ciphertext", ".", "Close", "(", ")", "}", "(", ")", "\n", "if", "err", ":=", "crypto", ".", "EncryptStream", "(", "ctx", ",", "plaintext", ",", "recipients", ",", "ciphertext", ")", ";", "err", "!=", "nil", "{", "_", "=", "os", ".", "Remove", "(", "outFile", ")", "\n", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to encrypt file: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// EncryptFileStream encrypts a single file
[ "EncryptFileStream", "encrypts", "a", "single", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L318-L356
train
gopasspw/gopass
pkg/action/xc/xc.go
DecryptFileStream
func DecryptFileStream(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if !strings.HasSuffix(inFile, ".xc") { return action.ExitError(ctx, action.ExitUsage, nil, "unknown extension. expecting .xc") } outFile := strings.TrimSuffix(inFile, ".xc") if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } ciphertext, err := os.Open(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } defer func() { _ = ciphertext.Close() }() plaintext, err := os.OpenFile(outFile, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } defer func() { _ = plaintext.Close() }() if err := crypto.DecryptStream(ctx, ciphertext, plaintext); err != nil { _ = os.Remove(outFile) return action.ExitError(ctx, action.ExitUnknown, err, "failed to decrypt file: %s", err) } return nil }
go
func DecryptFileStream(ctx context.Context, c *cli.Context) error { if err := initCrypto(); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "failed to init XC") } inFile := c.String("file") if inFile == "" { return action.ExitError(ctx, action.ExitUsage, nil, "need file") } if !strings.HasSuffix(inFile, ".xc") { return action.ExitError(ctx, action.ExitUsage, nil, "unknown extension. expecting .xc") } outFile := strings.TrimSuffix(inFile, ".xc") if !fsutil.IsFile(inFile) { return action.ExitError(ctx, action.ExitNotFound, nil, "input file not found") } if fsutil.IsFile(outFile) { return action.ExitError(ctx, action.ExitIO, nil, "output file already exists") } ciphertext, err := os.Open(inFile) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } defer func() { _ = ciphertext.Close() }() plaintext, err := os.OpenFile(outFile, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { return action.ExitError(ctx, action.ExitIO, err, "failed to read file") } defer func() { _ = plaintext.Close() }() if err := crypto.DecryptStream(ctx, ciphertext, plaintext); err != nil { _ = os.Remove(outFile) return action.ExitError(ctx, action.ExitUnknown, err, "failed to decrypt file: %s", err) } return nil }
[ "func", "DecryptFileStream", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "err", ":=", "initCrypto", "(", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to init XC\"", ")", "\n", "}", "\n", "inFile", ":=", "c", ".", "String", "(", "\"file\"", ")", "\n", "if", "inFile", "==", "\"\"", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"need file\"", ")", "\n", "}", "\n", "if", "!", "strings", ".", "HasSuffix", "(", "inFile", ",", "\".xc\"", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUsage", ",", "nil", ",", "\"unknown extension. expecting .xc\"", ")", "\n", "}", "\n", "outFile", ":=", "strings", ".", "TrimSuffix", "(", "inFile", ",", "\".xc\"", ")", "\n", "if", "!", "fsutil", ".", "IsFile", "(", "inFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitNotFound", ",", "nil", ",", "\"input file not found\"", ")", "\n", "}", "\n", "if", "fsutil", ".", "IsFile", "(", "outFile", ")", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "nil", ",", "\"output file already exists\"", ")", "\n", "}", "\n", "ciphertext", ",", "err", ":=", "os", ".", "Open", "(", "inFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to read file\"", ")", "\n", "}", "\n", "defer", "func", "(", ")", "{", "_", "=", "ciphertext", ".", "Close", "(", ")", "}", "(", ")", "\n", "plaintext", ",", "err", ":=", "os", ".", "OpenFile", "(", "outFile", ",", "os", ".", "O_CREATE", "|", "os", ".", "O_WRONLY", ",", "0600", ")", "\n", "if", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitIO", ",", "err", ",", "\"failed to read file\"", ")", "\n", "}", "\n", "defer", "func", "(", ")", "{", "_", "=", "plaintext", ".", "Close", "(", ")", "}", "(", ")", "\n", "if", "err", ":=", "crypto", ".", "DecryptStream", "(", "ctx", ",", "ciphertext", ",", "plaintext", ")", ";", "err", "!=", "nil", "{", "_", "=", "os", ".", "Remove", "(", "outFile", ")", "\n", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"failed to decrypt file: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DecryptFileStream decrypts a single file
[ "DecryptFileStream", "decrypts", "a", "single", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/xc/xc.go#L359-L397
train
gopasspw/gopass
pkg/action/git-credential.go
WriteTo
func (c *gitCredentials) WriteTo(w io.Writer) (int64, error) { var n int64 if c.Protocol != "" { i, err := io.WriteString(w, "protocol="+c.Protocol+"\n") n += int64(i) if err != nil { return n, err } } if c.Host != "" { i, err := io.WriteString(w, "host="+c.Host+"\n") n += int64(i) if err != nil { return n, err } } if c.Path != "" { i, err := io.WriteString(w, "path="+c.Path+"\n") n += int64(i) if err != nil { return n, err } } if c.Username != "" { i, err := io.WriteString(w, "username="+c.Username+"\n") n += int64(i) if err != nil { return n, err } } if c.Password != "" { i, err := io.WriteString(w, "password="+c.Password+"\n") n += int64(i) if err != nil { return n, err } } return n, nil }
go
func (c *gitCredentials) WriteTo(w io.Writer) (int64, error) { var n int64 if c.Protocol != "" { i, err := io.WriteString(w, "protocol="+c.Protocol+"\n") n += int64(i) if err != nil { return n, err } } if c.Host != "" { i, err := io.WriteString(w, "host="+c.Host+"\n") n += int64(i) if err != nil { return n, err } } if c.Path != "" { i, err := io.WriteString(w, "path="+c.Path+"\n") n += int64(i) if err != nil { return n, err } } if c.Username != "" { i, err := io.WriteString(w, "username="+c.Username+"\n") n += int64(i) if err != nil { return n, err } } if c.Password != "" { i, err := io.WriteString(w, "password="+c.Password+"\n") n += int64(i) if err != nil { return n, err } } return n, nil }
[ "func", "(", "c", "*", "gitCredentials", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "var", "n", "int64", "\n", "if", "c", ".", "Protocol", "!=", "\"\"", "{", "i", ",", "err", ":=", "io", ".", "WriteString", "(", "w", ",", "\"protocol=\"", "+", "c", ".", "Protocol", "+", "\"\\n\"", ")", "\n", "\\n", "\n", "n", "+=", "int64", "(", "i", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "n", ",", "err", "\n", "}", "\n", "if", "c", ".", "Host", "!=", "\"\"", "{", "i", ",", "err", ":=", "io", ".", "WriteString", "(", "w", ",", "\"host=\"", "+", "c", ".", "Host", "+", "\"\\n\"", ")", "\n", "\\n", "\n", "n", "+=", "int64", "(", "i", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "n", ",", "err", "\n", "}", "\n", "if", "c", ".", "Path", "!=", "\"\"", "{", "i", ",", "err", ":=", "io", ".", "WriteString", "(", "w", ",", "\"path=\"", "+", "c", ".", "Path", "+", "\"\\n\"", ")", "\n", "\\n", "\n", "n", "+=", "int64", "(", "i", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "n", ",", "err", "\n", "}", "\n", "}" ]
// WriteTo writes the given credentials to the given io.Writer in the git-credential format
[ "WriteTo", "writes", "the", "given", "credentials", "to", "the", "given", "io", ".", "Writer", "in", "the", "git", "-", "credential", "format" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git-credential.go#L31-L69
train
gopasspw/gopass
pkg/action/git-credential.go
GitCredentialBefore
func (s *Action) GitCredentialBefore(ctx context.Context, c *cli.Context) error { err := s.Initialized(ctx, c) if err != nil { return err } if !ctxutil.IsStdin(ctx) { return ExitError(ctx, ExitUsage, nil, "missing stdin from git") } return nil }
go
func (s *Action) GitCredentialBefore(ctx context.Context, c *cli.Context) error { err := s.Initialized(ctx, c) if err != nil { return err } if !ctxutil.IsStdin(ctx) { return ExitError(ctx, ExitUsage, nil, "missing stdin from git") } return nil }
[ "func", "(", "s", "*", "Action", ")", "GitCredentialBefore", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "err", ":=", "s", ".", "Initialized", "(", "ctx", ",", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "ctxutil", ".", "IsStdin", "(", "ctx", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"missing stdin from git\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GitCredentialBefore is executed before another git-credential command
[ "GitCredentialBefore", "is", "executed", "before", "another", "git", "-", "credential", "command" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git-credential.go#L110-L119
train
gopasspw/gopass
pkg/action/git-credential.go
GitCredentialGet
func (s *Action) GitCredentialGet(ctx context.Context, c *cli.Context) error { ctx = sub.WithAutoSync(ctx, false) cred, err := parseGitCredentials(termio.Stdin) if err != nil { return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) } // try git/host/username... If username is empty, simply try git/host path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) if !s.Store.Exists(ctx, path) { // if the looked up path is a directory with only one entry (e.g. one user per host), take the subentry instead if !s.Store.IsDir(ctx, path) { return nil } tree, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitDecrypt, err, "Error: %v while listing the storage", err) } sub, err := tree.FindFolder(path) if err != nil { // no entry found... this is not an error return nil } entries := sub.List(0) if len(entries) != 1 { fmt.Fprintln(os.Stderr, "gopass error: too many entries") return nil } path = "git/" + entries[0] } secret, err := s.Store.Get(ctx, path) if err != nil { return ExitError(ctx, ExitDecrypt, err, "") } cred.Password = secret.Password() username, err := secret.Value("login") if err == nil { // leave the username as is otherwise cred.Username = username } _, err = cred.WriteTo(out.Stdout) if err != nil { return ExitError(ctx, ExitIO, err, "Could not write to stdout") } return nil }
go
func (s *Action) GitCredentialGet(ctx context.Context, c *cli.Context) error { ctx = sub.WithAutoSync(ctx, false) cred, err := parseGitCredentials(termio.Stdin) if err != nil { return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) } // try git/host/username... If username is empty, simply try git/host path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) if !s.Store.Exists(ctx, path) { // if the looked up path is a directory with only one entry (e.g. one user per host), take the subentry instead if !s.Store.IsDir(ctx, path) { return nil } tree, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitDecrypt, err, "Error: %v while listing the storage", err) } sub, err := tree.FindFolder(path) if err != nil { // no entry found... this is not an error return nil } entries := sub.List(0) if len(entries) != 1 { fmt.Fprintln(os.Stderr, "gopass error: too many entries") return nil } path = "git/" + entries[0] } secret, err := s.Store.Get(ctx, path) if err != nil { return ExitError(ctx, ExitDecrypt, err, "") } cred.Password = secret.Password() username, err := secret.Value("login") if err == nil { // leave the username as is otherwise cred.Username = username } _, err = cred.WriteTo(out.Stdout) if err != nil { return ExitError(ctx, ExitIO, err, "Could not write to stdout") } return nil }
[ "func", "(", "s", "*", "Action", ")", "GitCredentialGet", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "ctx", "=", "sub", ".", "WithAutoSync", "(", "ctx", ",", "false", ")", "\n", "cred", ",", "err", ":=", "parseGitCredentials", "(", "termio", ".", "Stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnsupported", ",", "err", ",", "\"Error: %v while parsing git-credential\"", ",", "err", ")", "\n", "}", "\n", "path", ":=", "\"git/\"", "+", "fsutil", ".", "CleanFilename", "(", "cred", ".", "Host", ")", "+", "\"/\"", "+", "fsutil", ".", "CleanFilename", "(", "cred", ".", "Username", ")", "\n", "if", "!", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "path", ")", "{", "if", "!", "s", ".", "Store", ".", "IsDir", "(", "ctx", ",", "path", ")", "{", "return", "nil", "\n", "}", "\n", "tree", ",", "err", ":=", "s", ".", "Store", ".", "Tree", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitDecrypt", ",", "err", ",", "\"Error: %v while listing the storage\"", ",", "err", ")", "\n", "}", "\n", "sub", ",", "err", ":=", "tree", ".", "FindFolder", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "entries", ":=", "sub", ".", "List", "(", "0", ")", "\n", "if", "len", "(", "entries", ")", "!=", "1", "{", "fmt", ".", "Fprintln", "(", "os", ".", "Stderr", ",", "\"gopass error: too many entries\"", ")", "\n", "return", "nil", "\n", "}", "\n", "path", "=", "\"git/\"", "+", "entries", "[", "0", "]", "\n", "}", "\n", "secret", ",", "err", ":=", "s", ".", "Store", ".", "Get", "(", "ctx", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitDecrypt", ",", "err", ",", "\"\"", ")", "\n", "}", "\n", "cred", ".", "Password", "=", "secret", ".", "Password", "(", ")", "\n", "username", ",", "err", ":=", "secret", ".", "Value", "(", "\"login\"", ")", "\n", "if", "err", "==", "nil", "{", "cred", ".", "Username", "=", "username", "\n", "}", "\n", "_", ",", "err", "=", "cred", ".", "WriteTo", "(", "out", ".", "Stdout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"Could not write to stdout\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GitCredentialGet returns a credential to git
[ "GitCredentialGet", "returns", "a", "credential", "to", "git" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git-credential.go#L122-L167
train
gopasspw/gopass
pkg/action/git-credential.go
GitCredentialStore
func (s *Action) GitCredentialStore(ctx context.Context, c *cli.Context) error { cred, err := parseGitCredentials(termio.Stdin) if err != nil { return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) } path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) // This should never really be an issue because git automatically removes invalid credentials first if s.Store.Exists(ctx, path) { fmt.Fprintf(os.Stderr, ""+ "gopass: did not store \"%s\" because it already exists. "+ "If you want to overwrite it, delete it first by doing: "+ "\"gopass rm %s\"\n", path, path, ) return nil } secret := secret.New(cred.Password, "") if cred.Username != "" { _ = secret.SetValue("login", cred.Username) } err = s.Store.Set(ctx, path, secret) if err != nil { fmt.Fprintf(os.Stderr, "gopass error: error while writing to store: %v\n", err) } return nil }
go
func (s *Action) GitCredentialStore(ctx context.Context, c *cli.Context) error { cred, err := parseGitCredentials(termio.Stdin) if err != nil { return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) } path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) // This should never really be an issue because git automatically removes invalid credentials first if s.Store.Exists(ctx, path) { fmt.Fprintf(os.Stderr, ""+ "gopass: did not store \"%s\" because it already exists. "+ "If you want to overwrite it, delete it first by doing: "+ "\"gopass rm %s\"\n", path, path, ) return nil } secret := secret.New(cred.Password, "") if cred.Username != "" { _ = secret.SetValue("login", cred.Username) } err = s.Store.Set(ctx, path, secret) if err != nil { fmt.Fprintf(os.Stderr, "gopass error: error while writing to store: %v\n", err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "GitCredentialStore", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "cred", ",", "err", ":=", "parseGitCredentials", "(", "termio", ".", "Stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnsupported", ",", "err", ",", "\"Error: %v while parsing git-credential\"", ",", "err", ")", "\n", "}", "\n", "path", ":=", "\"git/\"", "+", "fsutil", ".", "CleanFilename", "(", "cred", ".", "Host", ")", "+", "\"/\"", "+", "fsutil", ".", "CleanFilename", "(", "cred", ".", "Username", ")", "\n", "if", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "path", ")", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"\"", "+", "\"gopass: did not store \\\"%s\\\" because it already exists. \"", "+", "\\\"", "+", "\\\"", ",", "\"If you want to overwrite it, delete it first by doing: \"", ",", "\"\\\"gopass rm %s\\\"\\n\"", ",", ")", "\n", "\\\"", "\n", "}", "\n", "\\\"", "\n", "\\n", "\n", "path", "\n", "path", "\n", "return", "nil", "\n", "}" ]
// GitCredentialStore stores a credential got from git
[ "GitCredentialStore", "stores", "a", "credential", "got", "from", "git" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git-credential.go#L170-L195
train
gopasspw/gopass
pkg/action/git-credential.go
GitCredentialErase
func (s *Action) GitCredentialErase(ctx context.Context, c *cli.Context) error { cred, err := parseGitCredentials(termio.Stdin) if err != nil { return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) } path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) err = s.Store.Delete(ctx, path) if err != nil { fmt.Fprintln(os.Stderr, "gopass error: error while writing to store") } return nil }
go
func (s *Action) GitCredentialErase(ctx context.Context, c *cli.Context) error { cred, err := parseGitCredentials(termio.Stdin) if err != nil { return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) } path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) err = s.Store.Delete(ctx, path) if err != nil { fmt.Fprintln(os.Stderr, "gopass error: error while writing to store") } return nil }
[ "func", "(", "s", "*", "Action", ")", "GitCredentialErase", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "cred", ",", "err", ":=", "parseGitCredentials", "(", "termio", ".", "Stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnsupported", ",", "err", ",", "\"Error: %v while parsing git-credential\"", ",", "err", ")", "\n", "}", "\n", "path", ":=", "\"git/\"", "+", "fsutil", ".", "CleanFilename", "(", "cred", ".", "Host", ")", "+", "\"/\"", "+", "fsutil", ".", "CleanFilename", "(", "cred", ".", "Username", ")", "\n", "err", "=", "s", ".", "Store", ".", "Delete", "(", "ctx", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintln", "(", "os", ".", "Stderr", ",", "\"gopass error: error while writing to store\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GitCredentialErase removes a credential got from git
[ "GitCredentialErase", "removes", "a", "credential", "got", "from", "git" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git-credential.go#L198-L209
train
gopasspw/gopass
pkg/action/git-credential.go
GitCredentialConfigure
func (s *Action) GitCredentialConfigure(ctx context.Context, c *cli.Context) error { flags := 0 flag := "--global" if c.Bool("local") { flag = "--local" flags++ } if c.Bool("global") { flag = "--global" flags++ } if c.Bool("system") { flag = "--system" flags++ } if flags >= 2 { return ExitError(ctx, ExitUnsupported, nil, "Error: only specify one target of installation!") } if flags == 0 { log.Println("No target given, assuming --global.") } cmd := exec.Command("git", "config", flag, "credential.helper", `"!gopass git-credential $@"`) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() }
go
func (s *Action) GitCredentialConfigure(ctx context.Context, c *cli.Context) error { flags := 0 flag := "--global" if c.Bool("local") { flag = "--local" flags++ } if c.Bool("global") { flag = "--global" flags++ } if c.Bool("system") { flag = "--system" flags++ } if flags >= 2 { return ExitError(ctx, ExitUnsupported, nil, "Error: only specify one target of installation!") } if flags == 0 { log.Println("No target given, assuming --global.") } cmd := exec.Command("git", "config", flag, "credential.helper", `"!gopass git-credential $@"`) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() }
[ "func", "(", "s", "*", "Action", ")", "GitCredentialConfigure", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "flags", ":=", "0", "\n", "flag", ":=", "\"--global\"", "\n", "if", "c", ".", "Bool", "(", "\"local\"", ")", "{", "flag", "=", "\"--local\"", "\n", "flags", "++", "\n", "}", "\n", "if", "c", ".", "Bool", "(", "\"global\"", ")", "{", "flag", "=", "\"--global\"", "\n", "flags", "++", "\n", "}", "\n", "if", "c", ".", "Bool", "(", "\"system\"", ")", "{", "flag", "=", "\"--system\"", "\n", "flags", "++", "\n", "}", "\n", "if", "flags", ">=", "2", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnsupported", ",", "nil", ",", "\"Error: only specify one target of installation!\"", ")", "\n", "}", "\n", "if", "flags", "==", "0", "{", "log", ".", "Println", "(", "\"No target given, assuming --global.\"", ")", "\n", "}", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"git\"", ",", "\"config\"", ",", "flag", ",", "\"credential.helper\"", ",", "`\"!gopass git-credential $@\"`", ")", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "return", "cmd", ".", "Run", "(", ")", "\n", "}" ]
// GitCredentialConfigure configures gopass as git's credential.helper
[ "GitCredentialConfigure", "configures", "gopass", "as", "git", "s", "credential", ".", "helper" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git-credential.go#L212-L237
train
gopasspw/gopass
pkg/tree/simple/file.go
format
func (f File) format(prefix string, last bool, _, _ int) string { sym := symBranch if last { sym = symLeaf } ft := "" if f.Metadata != nil { switch f.Metadata["Content-Type"] { case "application/octet-stream": ft = " " + colBin("(binary)") case "text/yaml": ft = " " + colYaml("(yaml)") } } return prefix + sym + f.Name + ft + "\n" }
go
func (f File) format(prefix string, last bool, _, _ int) string { sym := symBranch if last { sym = symLeaf } ft := "" if f.Metadata != nil { switch f.Metadata["Content-Type"] { case "application/octet-stream": ft = " " + colBin("(binary)") case "text/yaml": ft = " " + colYaml("(yaml)") } } return prefix + sym + f.Name + ft + "\n" }
[ "func", "(", "f", "File", ")", "format", "(", "prefix", "string", ",", "last", "bool", ",", "_", ",", "_", "int", ")", "string", "{", "sym", ":=", "symBranch", "\n", "if", "last", "{", "sym", "=", "symLeaf", "\n", "}", "\n", "ft", ":=", "\"\"", "\n", "if", "f", ".", "Metadata", "!=", "nil", "{", "switch", "f", ".", "Metadata", "[", "\"Content-Type\"", "]", "{", "case", "\"application/octet-stream\"", ":", "ft", "=", "\" \"", "+", "colBin", "(", "\"(binary)\"", ")", "\n", "case", "\"text/yaml\"", ":", "ft", "=", "\" \"", "+", "colYaml", "(", "\"(yaml)\"", ")", "\n", "}", "\n", "}", "\n", "return", "prefix", "+", "sym", "+", "f", ".", "Name", "+", "ft", "+", "\"\\n\"", "\n", "}" ]
// format will format this leaf node for pretty printing
[ "format", "will", "format", "this", "leaf", "node", "for", "pretty", "printing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/file.go#L15-L30
train
gopasspw/gopass
pkg/cui/actions.go
Selection
func (ca Actions) Selection() []string { keys := make([]string, 0, len(ca)) for _, a := range ca { keys = append(keys, a.Name) } return keys }
go
func (ca Actions) Selection() []string { keys := make([]string, 0, len(ca)) for _, a := range ca { keys = append(keys, a.Name) } return keys }
[ "func", "(", "ca", "Actions", ")", "Selection", "(", ")", "[", "]", "string", "{", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "ca", ")", ")", "\n", "for", "_", ",", "a", ":=", "range", "ca", "{", "keys", "=", "append", "(", "keys", ",", "a", ".", "Name", ")", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// Selection return the list of actions
[ "Selection", "return", "the", "list", "of", "actions" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/cui/actions.go#L20-L26
train
gopasspw/gopass
pkg/cui/actions.go
Run
func (ca Actions) Run(ctx context.Context, c *cli.Context, i int) error { if len(ca) < i || i >= len(ca) { return errors.New("action not found") } if ca[i].Fn == nil { return errors.New("action invalid") } return ca[i].Fn(ctx, c) }
go
func (ca Actions) Run(ctx context.Context, c *cli.Context, i int) error { if len(ca) < i || i >= len(ca) { return errors.New("action not found") } if ca[i].Fn == nil { return errors.New("action invalid") } return ca[i].Fn(ctx, c) }
[ "func", "(", "ca", "Actions", ")", "Run", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ",", "i", "int", ")", "error", "{", "if", "len", "(", "ca", ")", "<", "i", "||", "i", ">=", "len", "(", "ca", ")", "{", "return", "errors", ".", "New", "(", "\"action not found\"", ")", "\n", "}", "\n", "if", "ca", "[", "i", "]", ".", "Fn", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"action invalid\"", ")", "\n", "}", "\n", "return", "ca", "[", "i", "]", ".", "Fn", "(", "ctx", ",", "c", ")", "\n", "}" ]
// Run executes the selected action
[ "Run", "executes", "the", "selected", "action" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/cui/actions.go#L29-L37
train
gopasspw/gopass
pkg/hibp/dump/scanner.go
New
func New(dumps ...string) (*Scanner, error) { ok := make([]string, 0, len(dumps)) for _, dump := range dumps { if !fsutil.IsFile(dump) { continue } ok = append(ok, dump) } if len(ok) < 1 { return nil, fmt.Errorf("no valid dumps given") } return &Scanner{ dumps: ok, }, nil }
go
func New(dumps ...string) (*Scanner, error) { ok := make([]string, 0, len(dumps)) for _, dump := range dumps { if !fsutil.IsFile(dump) { continue } ok = append(ok, dump) } if len(ok) < 1 { return nil, fmt.Errorf("no valid dumps given") } return &Scanner{ dumps: ok, }, nil }
[ "func", "New", "(", "dumps", "...", "string", ")", "(", "*", "Scanner", ",", "error", ")", "{", "ok", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "dumps", ")", ")", "\n", "for", "_", ",", "dump", ":=", "range", "dumps", "{", "if", "!", "fsutil", ".", "IsFile", "(", "dump", ")", "{", "continue", "\n", "}", "\n", "ok", "=", "append", "(", "ok", ",", "dump", ")", "\n", "}", "\n", "if", "len", "(", "ok", ")", "<", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"no valid dumps given\"", ")", "\n", "}", "\n", "return", "&", "Scanner", "{", "dumps", ":", "ok", ",", "}", ",", "nil", "\n", "}" ]
// New creates a new scanner
[ "New", "creates", "a", "new", "scanner" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/hibp/dump/scanner.go#L24-L38
train
gopasspw/gopass
pkg/hibp/dump/scanner.go
LookupBatch
func (s *Scanner) LookupBatch(ctx context.Context, in []string) []string { if len(in) < 1 { return nil } sort.Strings(in) for i, hash := range in { in[i] = strings.ToUpper(hash) } out := make([]string, 0, len(in)) results := make(chan string, len(in)) done := make(chan struct{}, len(s.dumps)) for _, fn := range s.dumps { go s.scanFile(ctx, fn, in, results, done) } go func() { for result := range results { out = append(out, result) } done <- struct{}{} }() for range s.dumps { <-done } close(results) <-done return out }
go
func (s *Scanner) LookupBatch(ctx context.Context, in []string) []string { if len(in) < 1 { return nil } sort.Strings(in) for i, hash := range in { in[i] = strings.ToUpper(hash) } out := make([]string, 0, len(in)) results := make(chan string, len(in)) done := make(chan struct{}, len(s.dumps)) for _, fn := range s.dumps { go s.scanFile(ctx, fn, in, results, done) } go func() { for result := range results { out = append(out, result) } done <- struct{}{} }() for range s.dumps { <-done } close(results) <-done return out }
[ "func", "(", "s", "*", "Scanner", ")", "LookupBatch", "(", "ctx", "context", ".", "Context", ",", "in", "[", "]", "string", ")", "[", "]", "string", "{", "if", "len", "(", "in", ")", "<", "1", "{", "return", "nil", "\n", "}", "\n", "sort", ".", "Strings", "(", "in", ")", "\n", "for", "i", ",", "hash", ":=", "range", "in", "{", "in", "[", "i", "]", "=", "strings", ".", "ToUpper", "(", "hash", ")", "\n", "}", "\n", "out", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "in", ")", ")", "\n", "results", ":=", "make", "(", "chan", "string", ",", "len", "(", "in", ")", ")", "\n", "done", ":=", "make", "(", "chan", "struct", "{", "}", ",", "len", "(", "s", ".", "dumps", ")", ")", "\n", "for", "_", ",", "fn", ":=", "range", "s", ".", "dumps", "{", "go", "s", ".", "scanFile", "(", "ctx", ",", "fn", ",", "in", ",", "results", ",", "done", ")", "\n", "}", "\n", "go", "func", "(", ")", "{", "for", "result", ":=", "range", "results", "{", "out", "=", "append", "(", "out", ",", "result", ")", "\n", "}", "\n", "done", "<-", "struct", "{", "}", "{", "}", "\n", "}", "(", ")", "\n", "for", "range", "s", ".", "dumps", "{", "<-", "done", "\n", "}", "\n", "close", "(", "results", ")", "\n", "<-", "done", "\n", "return", "out", "\n", "}" ]
// LookupBatch takes a slice SHA1 hashes and matches them against // the provided dumps
[ "LookupBatch", "takes", "a", "slice", "SHA1", "hashes", "and", "matches", "them", "against", "the", "provided", "dumps" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/hibp/dump/scanner.go#L42-L72
train
gopasspw/gopass
pkg/backend/rcs/noop/backend.go
Add
func (g *Noop) Add(ctx context.Context, args ...string) error { return nil }
go
func (g *Noop) Add(ctx context.Context, args ...string) error { return nil }
[ "func", "(", "g", "*", "Noop", ")", "Add", "(", "ctx", "context", ".", "Context", ",", "args", "...", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// Add does nothing
[ "Add", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/noop/backend.go#L21-L23
train
gopasspw/gopass
pkg/backend/rcs/noop/backend.go
Commit
func (g *Noop) Commit(ctx context.Context, msg string) error { return nil }
go
func (g *Noop) Commit(ctx context.Context, msg string) error { return nil }
[ "func", "(", "g", "*", "Noop", ")", "Commit", "(", "ctx", "context", ".", "Context", ",", "msg", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// Commit does nothing
[ "Commit", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/noop/backend.go#L26-L28
train
gopasspw/gopass
pkg/backend/rcs/noop/backend.go
Push
func (g *Noop) Push(ctx context.Context, origin, branch string) error { return nil }
go
func (g *Noop) Push(ctx context.Context, origin, branch string) error { return nil }
[ "func", "(", "g", "*", "Noop", ")", "Push", "(", "ctx", "context", ".", "Context", ",", "origin", ",", "branch", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// Push does nothing
[ "Push", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/noop/backend.go#L31-L33
train
gopasspw/gopass
pkg/backend/rcs/noop/backend.go
Cmd
func (g *Noop) Cmd(ctx context.Context, name string, args ...string) error { return nil }
go
func (g *Noop) Cmd(ctx context.Context, name string, args ...string) error { return nil }
[ "func", "(", "g", "*", "Noop", ")", "Cmd", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "args", "...", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// Cmd does nothing
[ "Cmd", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/noop/backend.go#L41-L43
train
gopasspw/gopass
pkg/backend/rcs/noop/backend.go
AddRemote
func (g *Noop) AddRemote(ctx context.Context, remote, url string) error { return nil }
go
func (g *Noop) AddRemote(ctx context.Context, remote, url string) error { return nil }
[ "func", "(", "g", "*", "Noop", ")", "AddRemote", "(", "ctx", "context", ".", "Context", ",", "remote", ",", "url", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// AddRemote does nothing
[ "AddRemote", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/noop/backend.go#L66-L68
train
gopasspw/gopass
pkg/backend/rcs/noop/backend.go
RemoveRemote
func (g *Noop) RemoveRemote(ctx context.Context, remote string) error { return nil }
go
func (g *Noop) RemoveRemote(ctx context.Context, remote string) error { return nil }
[ "func", "(", "g", "*", "Noop", ")", "RemoveRemote", "(", "ctx", "context", ".", "Context", ",", "remote", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// RemoveRemote does nothing
[ "RemoveRemote", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/noop/backend.go#L71-L73
train
gopasspw/gopass
pkg/backend/rcs/noop/backend.go
Revisions
func (g *Noop) Revisions(context.Context, string) ([]backend.Revision, error) { return nil, fmt.Errorf("not yet implemented for %s", g.Name()) }
go
func (g *Noop) Revisions(context.Context, string) ([]backend.Revision, error) { return nil, fmt.Errorf("not yet implemented for %s", g.Name()) }
[ "func", "(", "g", "*", "Noop", ")", "Revisions", "(", "context", ".", "Context", ",", "string", ")", "(", "[", "]", "backend", ".", "Revision", ",", "error", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"not yet implemented for %s\"", ",", "g", ".", "Name", "(", ")", ")", "\n", "}" ]
// Revisions is not implemented
[ "Revisions", "is", "not", "implemented" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/noop/backend.go#L76-L78
train
gopasspw/gopass
pkg/termio/context.go
WithPassPromptFunc
func WithPassPromptFunc(ctx context.Context, ppf PassPromptFunc) context.Context { return context.WithValue(ctx, ctxKeyPassPromptFunc, ppf) }
go
func WithPassPromptFunc(ctx context.Context, ppf PassPromptFunc) context.Context { return context.WithValue(ctx, ctxKeyPassPromptFunc, ppf) }
[ "func", "WithPassPromptFunc", "(", "ctx", "context", ".", "Context", ",", "ppf", "PassPromptFunc", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyPassPromptFunc", ",", "ppf", ")", "\n", "}" ]
// WithPassPromptFunc returns a context with the password prompt function set
[ "WithPassPromptFunc", "returns", "a", "context", "with", "the", "password", "prompt", "function", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/context.go#L15-L17
train
gopasspw/gopass
pkg/termio/context.go
HasPassPromptFunc
func HasPassPromptFunc(ctx context.Context) bool { ppf, ok := ctx.Value(ctxKeyPassPromptFunc).(PassPromptFunc) return ok && ppf != nil }
go
func HasPassPromptFunc(ctx context.Context) bool { ppf, ok := ctx.Value(ctxKeyPassPromptFunc).(PassPromptFunc) return ok && ppf != nil }
[ "func", "HasPassPromptFunc", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "ppf", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyPassPromptFunc", ")", ".", "(", "PassPromptFunc", ")", "\n", "return", "ok", "&&", "ppf", "!=", "nil", "\n", "}" ]
// HasPassPromptFunc returns true if a value for the pass prompt func has been // set in this context
[ "HasPassPromptFunc", "returns", "true", "if", "a", "value", "for", "the", "pass", "prompt", "func", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/context.go#L21-L24
train
gopasspw/gopass
pkg/store/sub/templates.go
ListTemplates
func (s *Store) ListTemplates(ctx context.Context, prefix string) []string { lst, err := s.storage.List(ctx, "") if err != nil { out.Debug(ctx, "failed to list templates: %s", err) return nil } tpls := make(map[string]struct{}, len(lst)) for _, path := range lst { if !strings.HasSuffix(path, TemplateFile) { continue } path = strings.TrimSuffix(path, sep+TemplateFile) if prefix != "" { path = prefix + sep + path } tpls[path] = struct{}{} } out := make([]string, 0, len(tpls)) for k := range tpls { out = append(out, k) } sort.Strings(out) return out }
go
func (s *Store) ListTemplates(ctx context.Context, prefix string) []string { lst, err := s.storage.List(ctx, "") if err != nil { out.Debug(ctx, "failed to list templates: %s", err) return nil } tpls := make(map[string]struct{}, len(lst)) for _, path := range lst { if !strings.HasSuffix(path, TemplateFile) { continue } path = strings.TrimSuffix(path, sep+TemplateFile) if prefix != "" { path = prefix + sep + path } tpls[path] = struct{}{} } out := make([]string, 0, len(tpls)) for k := range tpls { out = append(out, k) } sort.Strings(out) return out }
[ "func", "(", "s", "*", "Store", ")", "ListTemplates", "(", "ctx", "context", ".", "Context", ",", "prefix", "string", ")", "[", "]", "string", "{", "lst", ",", "err", ":=", "s", ".", "storage", ".", "List", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"failed to list templates: %s\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "tpls", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ",", "len", "(", "lst", ")", ")", "\n", "for", "_", ",", "path", ":=", "range", "lst", "{", "if", "!", "strings", ".", "HasSuffix", "(", "path", ",", "TemplateFile", ")", "{", "continue", "\n", "}", "\n", "path", "=", "strings", ".", "TrimSuffix", "(", "path", ",", "sep", "+", "TemplateFile", ")", "\n", "if", "prefix", "!=", "\"\"", "{", "path", "=", "prefix", "+", "sep", "+", "path", "\n", "}", "\n", "tpls", "[", "path", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "out", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "tpls", ")", ")", "\n", "for", "k", ":=", "range", "tpls", "{", "out", "=", "append", "(", "out", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// ListTemplates will list all templates in this store
[ "ListTemplates", "will", "list", "all", "templates", "in", "this", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/templates.go#L46-L69
train
gopasspw/gopass
pkg/store/sub/templates.go
templatefile
func (s *Store) templatefile(name string) string { return strings.TrimPrefix(filepath.Join(name, TemplateFile), string(filepath.Separator)) }
go
func (s *Store) templatefile(name string) string { return strings.TrimPrefix(filepath.Join(name, TemplateFile), string(filepath.Separator)) }
[ "func", "(", "s", "*", "Store", ")", "templatefile", "(", "name", "string", ")", "string", "{", "return", "strings", ".", "TrimPrefix", "(", "filepath", ".", "Join", "(", "name", ",", "TemplateFile", ")", ",", "string", "(", "filepath", ".", "Separator", ")", ")", "\n", "}" ]
// templatefile returns the name of the given template on disk
[ "templatefile", "returns", "the", "name", "of", "the", "given", "template", "on", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/templates.go#L84-L86
train
gopasspw/gopass
pkg/store/sub/templates.go
HasTemplate
func (s *Store) HasTemplate(ctx context.Context, name string) bool { return s.storage.Exists(ctx, s.templatefile(name)) }
go
func (s *Store) HasTemplate(ctx context.Context, name string) bool { return s.storage.Exists(ctx, s.templatefile(name)) }
[ "func", "(", "s", "*", "Store", ")", "HasTemplate", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "bool", "{", "return", "s", ".", "storage", ".", "Exists", "(", "ctx", ",", "s", ".", "templatefile", "(", "name", ")", ")", "\n", "}" ]
// HasTemplate returns true if the template exists
[ "HasTemplate", "returns", "true", "if", "the", "template", "exists" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/templates.go#L89-L91
train
gopasspw/gopass
pkg/store/sub/templates.go
GetTemplate
func (s *Store) GetTemplate(ctx context.Context, name string) ([]byte, error) { return s.storage.Get(ctx, s.templatefile(name)) }
go
func (s *Store) GetTemplate(ctx context.Context, name string) ([]byte, error) { return s.storage.Get(ctx, s.templatefile(name)) }
[ "func", "(", "s", "*", "Store", ")", "GetTemplate", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "s", ".", "storage", ".", "Get", "(", "ctx", ",", "s", ".", "templatefile", "(", "name", ")", ")", "\n", "}" ]
// GetTemplate will return the content of the named template
[ "GetTemplate", "will", "return", "the", "content", "of", "the", "named", "template" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/templates.go#L94-L96
train
gopasspw/gopass
pkg/backend/url.go
ParseURL
func ParseURL(us string) (*URL, error) { // if it's no URL build file URL and parse that nu, err := url.Parse(us) if err != nil { nu, err = url.Parse("gpgcli-gitcli-fs+file://" + us) if err != nil { return nil, err } } u := &URL{ url: nu, } if err := u.parseScheme(); err != nil { return u, err } u.Path = nu.Path if nu.User != nil { u.Username = nu.User.Username() u.Password, _ = nu.User.Password() } if nu.Host == "~" { hd, err := homedir.Dir() if err != nil { return u, err } u.Path = filepath.Join(hd, u.Path) nu.Host = "" } u.Query = nu.Query() if nu.Host != "" { h, p, err := net.SplitHostPort(nu.Host) if err == nil { u.Host = h u.Port = p } } else if runtime.GOOS == "windows" { // only trim if this is a local path, e. g. file:///C:/Users/... // (specified in https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/) // In that case, u.Path will contain a leading slash. // (correctly, as per RFC 3986, see https://github.com/golang/go/issues/6027) u.Path = strings.TrimPrefix(u.Path, "/") } return u, nil }
go
func ParseURL(us string) (*URL, error) { // if it's no URL build file URL and parse that nu, err := url.Parse(us) if err != nil { nu, err = url.Parse("gpgcli-gitcli-fs+file://" + us) if err != nil { return nil, err } } u := &URL{ url: nu, } if err := u.parseScheme(); err != nil { return u, err } u.Path = nu.Path if nu.User != nil { u.Username = nu.User.Username() u.Password, _ = nu.User.Password() } if nu.Host == "~" { hd, err := homedir.Dir() if err != nil { return u, err } u.Path = filepath.Join(hd, u.Path) nu.Host = "" } u.Query = nu.Query() if nu.Host != "" { h, p, err := net.SplitHostPort(nu.Host) if err == nil { u.Host = h u.Port = p } } else if runtime.GOOS == "windows" { // only trim if this is a local path, e. g. file:///C:/Users/... // (specified in https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/) // In that case, u.Path will contain a leading slash. // (correctly, as per RFC 3986, see https://github.com/golang/go/issues/6027) u.Path = strings.TrimPrefix(u.Path, "/") } return u, nil }
[ "func", "ParseURL", "(", "us", "string", ")", "(", "*", "URL", ",", "error", ")", "{", "nu", ",", "err", ":=", "url", ".", "Parse", "(", "us", ")", "\n", "if", "err", "!=", "nil", "{", "nu", ",", "err", "=", "url", ".", "Parse", "(", "\"gpgcli-gitcli-fs+file://\"", "+", "us", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "u", ":=", "&", "URL", "{", "url", ":", "nu", ",", "}", "\n", "if", "err", ":=", "u", ".", "parseScheme", "(", ")", ";", "err", "!=", "nil", "{", "return", "u", ",", "err", "\n", "}", "\n", "u", ".", "Path", "=", "nu", ".", "Path", "\n", "if", "nu", ".", "User", "!=", "nil", "{", "u", ".", "Username", "=", "nu", ".", "User", ".", "Username", "(", ")", "\n", "u", ".", "Password", ",", "_", "=", "nu", ".", "User", ".", "Password", "(", ")", "\n", "}", "\n", "if", "nu", ".", "Host", "==", "\"~\"", "{", "hd", ",", "err", ":=", "homedir", ".", "Dir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "u", ",", "err", "\n", "}", "\n", "u", ".", "Path", "=", "filepath", ".", "Join", "(", "hd", ",", "u", ".", "Path", ")", "\n", "nu", ".", "Host", "=", "\"\"", "\n", "}", "\n", "u", ".", "Query", "=", "nu", ".", "Query", "(", ")", "\n", "if", "nu", ".", "Host", "!=", "\"\"", "{", "h", ",", "p", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "nu", ".", "Host", ")", "\n", "if", "err", "==", "nil", "{", "u", ".", "Host", "=", "h", "\n", "u", ".", "Port", "=", "p", "\n", "}", "\n", "}", "else", "if", "runtime", ".", "GOOS", "==", "\"windows\"", "{", "u", ".", "Path", "=", "strings", ".", "TrimPrefix", "(", "u", ".", "Path", ",", "\"/\"", ")", "\n", "}", "\n", "return", "u", ",", "nil", "\n", "}" ]
// ParseURL attempts to parse an backend URL
[ "ParseURL", "attempts", "to", "parse", "an", "backend", "URL" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/url.go#L43-L86
train
gopasspw/gopass
pkg/backend/url.go
UnmarshalYAML
func (u *URL) UnmarshalYAML(umf func(interface{}) error) error { path := "" if err := umf(&path); err != nil { return err } um, err := ParseURL(path) if err != nil { return err } *u = *um return nil }
go
func (u *URL) UnmarshalYAML(umf func(interface{}) error) error { path := "" if err := umf(&path); err != nil { return err } um, err := ParseURL(path) if err != nil { return err } *u = *um return nil }
[ "func", "(", "u", "*", "URL", ")", "UnmarshalYAML", "(", "umf", "func", "(", "interface", "{", "}", ")", "error", ")", "error", "{", "path", ":=", "\"\"", "\n", "if", "err", ":=", "umf", "(", "&", "path", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "um", ",", "err", ":=", "ParseURL", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "u", "=", "*", "um", "\n", "return", "nil", "\n", "}" ]
// UnmarshalYAML implements yaml.Unmarshaler
[ "UnmarshalYAML", "implements", "yaml", ".", "Unmarshaler" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/url.go#L143-L154
train
gopasspw/gopass
pkg/store/sub/git.go
GitInit
func (s *Store) GitInit(ctx context.Context, un, ue string) error { rcs, err := backend.InitRCS(ctx, backend.GetRCSBackend(ctx), s.url.Path, un, ue) if err != nil { return err } s.rcs = rcs return nil }
go
func (s *Store) GitInit(ctx context.Context, un, ue string) error { rcs, err := backend.InitRCS(ctx, backend.GetRCSBackend(ctx), s.url.Path, un, ue) if err != nil { return err } s.rcs = rcs return nil }
[ "func", "(", "s", "*", "Store", ")", "GitInit", "(", "ctx", "context", ".", "Context", ",", "un", ",", "ue", "string", ")", "error", "{", "rcs", ",", "err", ":=", "backend", ".", "InitRCS", "(", "ctx", ",", "backend", ".", "GetRCSBackend", "(", "ctx", ")", ",", "s", ".", "url", ".", "Path", ",", "un", ",", "ue", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "s", ".", "rcs", "=", "rcs", "\n", "return", "nil", "\n", "}" ]
// GitInit initializes the the git repo in the store
[ "GitInit", "initializes", "the", "the", "git", "repo", "in", "the", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/git.go#L21-L28
train
gopasspw/gopass
pkg/store/sub/git.go
ListRevisions
func (s *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) { p := s.passfile(name) return s.rcs.Revisions(ctx, p) }
go
func (s *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) { p := s.passfile(name) return s.rcs.Revisions(ctx, p) }
[ "func", "(", "s", "*", "Store", ")", "ListRevisions", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "[", "]", "backend", ".", "Revision", ",", "error", ")", "{", "p", ":=", "s", ".", "passfile", "(", "name", ")", "\n", "return", "s", ".", "rcs", ".", "Revisions", "(", "ctx", ",", "p", ")", "\n", "}" ]
// ListRevisions will list all revisions for a secret
[ "ListRevisions", "will", "list", "all", "revisions", "for", "a", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/git.go#L31-L34
train
gopasspw/gopass
pkg/store/sub/git.go
GetRevision
func (s *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) { p := s.passfile(name) ciphertext, err := s.rcs.GetRevision(ctx, p, revision) if err != nil { return nil, errors.Wrapf(err, "failed to get ciphertext of '%s'@'%s'", name, revision) } content, err := s.crypto.Decrypt(ctx, ciphertext) if err != nil { out.Debug(ctx, "Decryption failed: %s", err) return nil, store.ErrDecrypt } sec, err := secret.Parse(content) if err != nil { out.Debug(ctx, "Failed to parse YAML: %s", err) } return sec, nil }
go
func (s *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) { p := s.passfile(name) ciphertext, err := s.rcs.GetRevision(ctx, p, revision) if err != nil { return nil, errors.Wrapf(err, "failed to get ciphertext of '%s'@'%s'", name, revision) } content, err := s.crypto.Decrypt(ctx, ciphertext) if err != nil { out.Debug(ctx, "Decryption failed: %s", err) return nil, store.ErrDecrypt } sec, err := secret.Parse(content) if err != nil { out.Debug(ctx, "Failed to parse YAML: %s", err) } return sec, nil }
[ "func", "(", "s", "*", "Store", ")", "GetRevision", "(", "ctx", "context", ".", "Context", ",", "name", ",", "revision", "string", ")", "(", "store", ".", "Secret", ",", "error", ")", "{", "p", ":=", "s", ".", "passfile", "(", "name", ")", "\n", "ciphertext", ",", "err", ":=", "s", ".", "rcs", ".", "GetRevision", "(", "ctx", ",", "p", ",", "revision", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to get ciphertext of '%s'@'%s'\"", ",", "name", ",", "revision", ")", "\n", "}", "\n", "content", ",", "err", ":=", "s", ".", "crypto", ".", "Decrypt", "(", "ctx", ",", "ciphertext", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"Decryption failed: %s\"", ",", "err", ")", "\n", "return", "nil", ",", "store", ".", "ErrDecrypt", "\n", "}", "\n", "sec", ",", "err", ":=", "secret", ".", "Parse", "(", "content", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"Failed to parse YAML: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "sec", ",", "nil", "\n", "}" ]
// GetRevision will retrieve a single revision from the backend
[ "GetRevision", "will", "retrieve", "a", "single", "revision", "from", "the", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/git.go#L37-L55
train
gopasspw/gopass
pkg/backend/crypto/gpg/key.go
IsUseable
func (k Key) IsUseable() bool { if !k.ExpirationDate.IsZero() && k.ExpirationDate.Before(time.Now()) { return false } switch k.Validity { case "m": return true case "f": return true case "u": return true } return false }
go
func (k Key) IsUseable() bool { if !k.ExpirationDate.IsZero() && k.ExpirationDate.Before(time.Now()) { return false } switch k.Validity { case "m": return true case "f": return true case "u": return true } return false }
[ "func", "(", "k", "Key", ")", "IsUseable", "(", ")", "bool", "{", "if", "!", "k", ".", "ExpirationDate", ".", "IsZero", "(", ")", "&&", "k", ".", "ExpirationDate", ".", "Before", "(", "time", ".", "Now", "(", ")", ")", "{", "return", "false", "\n", "}", "\n", "switch", "k", ".", "Validity", "{", "case", "\"m\"", ":", "return", "true", "\n", "case", "\"f\"", ":", "return", "true", "\n", "case", "\"u\"", ":", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsUseable returns true if GPG would assume this key is useable for encryption
[ "IsUseable", "returns", "true", "if", "GPG", "would", "assume", "this", "key", "is", "useable", "for", "encryption" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/key.go#L23-L36
train
gopasspw/gopass
pkg/backend/crypto/gpg/key.go
String
func (k Key) String() string { fp := "" if len(k.Fingerprint) > 24 { fp = k.Fingerprint[24:] } out := fmt.Sprintf("%s %dD/0x%s %s", k.KeyType, k.KeyLength, fp, k.CreationDate.Format("2006-01-02")) if !k.ExpirationDate.IsZero() { out += fmt.Sprintf(" [expires: %s]", k.ExpirationDate.Format("2006-01-02")) } out += "\n Key fingerprint = " + k.Fingerprint for _, id := range k.Identities { out += fmt.Sprintf("\n" + id.String()) } return out }
go
func (k Key) String() string { fp := "" if len(k.Fingerprint) > 24 { fp = k.Fingerprint[24:] } out := fmt.Sprintf("%s %dD/0x%s %s", k.KeyType, k.KeyLength, fp, k.CreationDate.Format("2006-01-02")) if !k.ExpirationDate.IsZero() { out += fmt.Sprintf(" [expires: %s]", k.ExpirationDate.Format("2006-01-02")) } out += "\n Key fingerprint = " + k.Fingerprint for _, id := range k.Identities { out += fmt.Sprintf("\n" + id.String()) } return out }
[ "func", "(", "k", "Key", ")", "String", "(", ")", "string", "{", "fp", ":=", "\"\"", "\n", "if", "len", "(", "k", ".", "Fingerprint", ")", ">", "24", "{", "fp", "=", "k", ".", "Fingerprint", "[", "24", ":", "]", "\n", "}", "\n", "out", ":=", "fmt", ".", "Sprintf", "(", "\"%s %dD/0x%s %s\"", ",", "k", ".", "KeyType", ",", "k", ".", "KeyLength", ",", "fp", ",", "k", ".", "CreationDate", ".", "Format", "(", "\"2006-01-02\"", ")", ")", "\n", "if", "!", "k", ".", "ExpirationDate", ".", "IsZero", "(", ")", "{", "out", "+=", "fmt", ".", "Sprintf", "(", "\" [expires: %s]\"", ",", "k", ".", "ExpirationDate", ".", "Format", "(", "\"2006-01-02\"", ")", ")", "\n", "}", "\n", "out", "+=", "\"\\n Key fingerprint = \"", "+", "\\n", "\n", "k", ".", "Fingerprint", "\n", "for", "_", ",", "id", ":=", "range", "k", ".", "Identities", "{", "out", "+=", "fmt", ".", "Sprintf", "(", "\"\\n\"", "+", "\\n", ")", "\n", "}", "\n", "}" ]
// String implement fmt.Stringer. This method produces output that is close to, but // not exactly the same, as the output form GPG itself
[ "String", "implement", "fmt", ".", "Stringer", ".", "This", "method", "produces", "output", "that", "is", "close", "to", "but", "not", "exactly", "the", "same", "as", "the", "output", "form", "GPG", "itself" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/key.go#L40-L54
train
gopasspw/gopass
pkg/backend/crypto/gpg/key.go
Identity
func (k Key) Identity() Identity { ids := make([]Identity, 0, len(k.Identities)) for _, i := range k.Identities { ids = append(ids, i) } sort.Slice(ids, func(i, j int) bool { return ids[i].CreationDate.After(ids[j].CreationDate) }) for _, i := range ids { return i } return Identity{} }
go
func (k Key) Identity() Identity { ids := make([]Identity, 0, len(k.Identities)) for _, i := range k.Identities { ids = append(ids, i) } sort.Slice(ids, func(i, j int) bool { return ids[i].CreationDate.After(ids[j].CreationDate) }) for _, i := range ids { return i } return Identity{} }
[ "func", "(", "k", "Key", ")", "Identity", "(", ")", "Identity", "{", "ids", ":=", "make", "(", "[", "]", "Identity", ",", "0", ",", "len", "(", "k", ".", "Identities", ")", ")", "\n", "for", "_", ",", "i", ":=", "range", "k", ".", "Identities", "{", "ids", "=", "append", "(", "ids", ",", "i", ")", "\n", "}", "\n", "sort", ".", "Slice", "(", "ids", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "ids", "[", "i", "]", ".", "CreationDate", ".", "After", "(", "ids", "[", "j", "]", ".", "CreationDate", ")", "\n", "}", ")", "\n", "for", "_", ",", "i", ":=", "range", "ids", "{", "return", "i", "\n", "}", "\n", "return", "Identity", "{", "}", "\n", "}" ]
// Identity returns the first identity
[ "Identity", "returns", "the", "first", "identity" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/key.go#L66-L78
train
gopasspw/gopass
pkg/backend/crypto/gpg/key.go
ID
func (k Key) ID() string { if len(k.Fingerprint) < 25 { return "" } return fmt.Sprintf("0x%s", k.Fingerprint[24:]) }
go
func (k Key) ID() string { if len(k.Fingerprint) < 25 { return "" } return fmt.Sprintf("0x%s", k.Fingerprint[24:]) }
[ "func", "(", "k", "Key", ")", "ID", "(", ")", "string", "{", "if", "len", "(", "k", ".", "Fingerprint", ")", "<", "25", "{", "return", "\"\"", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"0x%s\"", ",", "k", ".", "Fingerprint", "[", "24", ":", "]", ")", "\n", "}" ]
// ID returns the short fingerprint
[ "ID", "returns", "the", "short", "fingerprint" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/key.go#L81-L86
train
gopasspw/gopass
pkg/action/clone.go
Clone
func (s *Action) Clone(ctx context.Context, c *cli.Context) error { if c.IsSet("crypto") { ctx = backend.WithCryptoBackendString(ctx, c.String("crypto")) } if c.IsSet("sync") { ctx = backend.WithRCSBackendString(ctx, c.String("sync")) } if len(c.Args()) < 1 { return ExitError(ctx, ExitUsage, nil, "Usage: %s clone repo [mount]", s.Name) } repo := c.Args()[0] mount := "" if len(c.Args()) > 1 { mount = c.Args()[1] } path := c.String("path") return s.clone(ctx, repo, mount, path) }
go
func (s *Action) Clone(ctx context.Context, c *cli.Context) error { if c.IsSet("crypto") { ctx = backend.WithCryptoBackendString(ctx, c.String("crypto")) } if c.IsSet("sync") { ctx = backend.WithRCSBackendString(ctx, c.String("sync")) } if len(c.Args()) < 1 { return ExitError(ctx, ExitUsage, nil, "Usage: %s clone repo [mount]", s.Name) } repo := c.Args()[0] mount := "" if len(c.Args()) > 1 { mount = c.Args()[1] } path := c.String("path") return s.clone(ctx, repo, mount, path) }
[ "func", "(", "s", "*", "Action", ")", "Clone", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "c", ".", "IsSet", "(", "\"crypto\"", ")", "{", "ctx", "=", "backend", ".", "WithCryptoBackendString", "(", "ctx", ",", "c", ".", "String", "(", "\"crypto\"", ")", ")", "\n", "}", "\n", "if", "c", ".", "IsSet", "(", "\"sync\"", ")", "{", "ctx", "=", "backend", ".", "WithRCSBackendString", "(", "ctx", ",", "c", ".", "String", "(", "\"sync\"", ")", ")", "\n", "}", "\n", "if", "len", "(", "c", ".", "Args", "(", ")", ")", "<", "1", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s clone repo [mount]\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "repo", ":=", "c", ".", "Args", "(", ")", "[", "0", "]", "\n", "mount", ":=", "\"\"", "\n", "if", "len", "(", "c", ".", "Args", "(", ")", ")", ">", "1", "{", "mount", "=", "c", ".", "Args", "(", ")", "[", "1", "]", "\n", "}", "\n", "path", ":=", "c", ".", "String", "(", "\"path\"", ")", "\n", "return", "s", ".", "clone", "(", "ctx", ",", "repo", ",", "mount", ",", "path", ")", "\n", "}" ]
// Clone will fetch and mount a new password store from a git repo
[ "Clone", "will", "fetch", "and", "mount", "a", "new", "password", "store", "from", "a", "git", "repo" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/clone.go#L21-L42
train
gopasspw/gopass
pkg/backend/crypto/gpg/key_list.go
Recipients
func (kl KeyList) Recipients() []string { l := make([]string, 0, len(kl)) for _, k := range kl { l = append(l, k.ID()) } sort.Strings(l) return l }
go
func (kl KeyList) Recipients() []string { l := make([]string, 0, len(kl)) for _, k := range kl { l = append(l, k.ID()) } sort.Strings(l) return l }
[ "func", "(", "kl", "KeyList", ")", "Recipients", "(", ")", "[", "]", "string", "{", "l", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "kl", ")", ")", "\n", "for", "_", ",", "k", ":=", "range", "kl", "{", "l", "=", "append", "(", "l", ",", "k", ".", "ID", "(", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "l", ")", "\n", "return", "l", "\n", "}" ]
// Recipients returns the KeyList formatted as a recipient list
[ "Recipients", "returns", "the", "KeyList", "formatted", "as", "a", "recipient", "list" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/key_list.go#L14-L21
train
gopasspw/gopass
pkg/backend/crypto/gpg/key_list.go
FindKey
func (kl KeyList) FindKey(id string) (Key, error) { id = strings.TrimPrefix(id, "0x") for _, k := range kl { if k.Fingerprint == id { return k, nil } if strings.HasSuffix(k.Fingerprint, id) { return k, nil } for _, ident := range k.Identities { if ident.Name == id { return k, nil } if ident.Email == id { return k, nil } } for sk := range k.SubKeys { if strings.HasSuffix(sk, id) { return k, nil } } } return Key{}, errors.Errorf("No matching key found") }
go
func (kl KeyList) FindKey(id string) (Key, error) { id = strings.TrimPrefix(id, "0x") for _, k := range kl { if k.Fingerprint == id { return k, nil } if strings.HasSuffix(k.Fingerprint, id) { return k, nil } for _, ident := range k.Identities { if ident.Name == id { return k, nil } if ident.Email == id { return k, nil } } for sk := range k.SubKeys { if strings.HasSuffix(sk, id) { return k, nil } } } return Key{}, errors.Errorf("No matching key found") }
[ "func", "(", "kl", "KeyList", ")", "FindKey", "(", "id", "string", ")", "(", "Key", ",", "error", ")", "{", "id", "=", "strings", ".", "TrimPrefix", "(", "id", ",", "\"0x\"", ")", "\n", "for", "_", ",", "k", ":=", "range", "kl", "{", "if", "k", ".", "Fingerprint", "==", "id", "{", "return", "k", ",", "nil", "\n", "}", "\n", "if", "strings", ".", "HasSuffix", "(", "k", ".", "Fingerprint", ",", "id", ")", "{", "return", "k", ",", "nil", "\n", "}", "\n", "for", "_", ",", "ident", ":=", "range", "k", ".", "Identities", "{", "if", "ident", ".", "Name", "==", "id", "{", "return", "k", ",", "nil", "\n", "}", "\n", "if", "ident", ".", "Email", "==", "id", "{", "return", "k", ",", "nil", "\n", "}", "\n", "}", "\n", "for", "sk", ":=", "range", "k", ".", "SubKeys", "{", "if", "strings", ".", "HasSuffix", "(", "sk", ",", "id", ")", "{", "return", "k", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "Key", "{", "}", ",", "errors", ".", "Errorf", "(", "\"No matching key found\"", ")", "\n", "}" ]
// FindKey will try to find the requested key
[ "FindKey", "will", "try", "to", "find", "the", "requested", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/key_list.go#L50-L74
train
gopasspw/gopass
pkg/backend/crypto/xc/stream.go
EncryptStream
func (x *XC) EncryptStream(ctx context.Context, plaintext io.Reader, recipients []string, ciphertext io.Writer) error { privKeyIDs := x.secring.KeyIDs() if len(privKeyIDs) < 1 { return fmt.Errorf("no signing keys available on our keyring") } privKey := x.secring.Get(privKeyIDs[0]) // generate session / encryption key var sessionKey [32]byte if _, err := crypto_rand.Read(sessionKey[:]); err != nil { return err } // encrypt the session key per recipient header, err := x.encryptHeader(ctx, privKey, sessionKey[:], recipients) if err != nil { return errors.Wrapf(err, "failed to encrypt header: %s", err) } // create the encoder enc := binary.NewEncoder(ciphertext) // write verion if err := enc.Encode(0x1); err != nil { return err } // write header if err := enc.Encode(header); err != nil { return err } // write body num := 0 buf := make([]byte, chunkSizeMax) encbuf := make([]byte, 8) for { n, err := plaintext.Read(buf) if err := x.encryptChunk(sessionKey, num, buf[:n], encbuf, ciphertext); err != nil { return err } if err != nil { if err == io.EOF { return nil } return err } num++ } }
go
func (x *XC) EncryptStream(ctx context.Context, plaintext io.Reader, recipients []string, ciphertext io.Writer) error { privKeyIDs := x.secring.KeyIDs() if len(privKeyIDs) < 1 { return fmt.Errorf("no signing keys available on our keyring") } privKey := x.secring.Get(privKeyIDs[0]) // generate session / encryption key var sessionKey [32]byte if _, err := crypto_rand.Read(sessionKey[:]); err != nil { return err } // encrypt the session key per recipient header, err := x.encryptHeader(ctx, privKey, sessionKey[:], recipients) if err != nil { return errors.Wrapf(err, "failed to encrypt header: %s", err) } // create the encoder enc := binary.NewEncoder(ciphertext) // write verion if err := enc.Encode(0x1); err != nil { return err } // write header if err := enc.Encode(header); err != nil { return err } // write body num := 0 buf := make([]byte, chunkSizeMax) encbuf := make([]byte, 8) for { n, err := plaintext.Read(buf) if err := x.encryptChunk(sessionKey, num, buf[:n], encbuf, ciphertext); err != nil { return err } if err != nil { if err == io.EOF { return nil } return err } num++ } }
[ "func", "(", "x", "*", "XC", ")", "EncryptStream", "(", "ctx", "context", ".", "Context", ",", "plaintext", "io", ".", "Reader", ",", "recipients", "[", "]", "string", ",", "ciphertext", "io", ".", "Writer", ")", "error", "{", "privKeyIDs", ":=", "x", ".", "secring", ".", "KeyIDs", "(", ")", "\n", "if", "len", "(", "privKeyIDs", ")", "<", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"no signing keys available on our keyring\"", ")", "\n", "}", "\n", "privKey", ":=", "x", ".", "secring", ".", "Get", "(", "privKeyIDs", "[", "0", "]", ")", "\n", "var", "sessionKey", "[", "32", "]", "byte", "\n", "if", "_", ",", "err", ":=", "crypto_rand", ".", "Read", "(", "sessionKey", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "header", ",", "err", ":=", "x", ".", "encryptHeader", "(", "ctx", ",", "privKey", ",", "sessionKey", "[", ":", "]", ",", "recipients", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to encrypt header: %s\"", ",", "err", ")", "\n", "}", "\n", "enc", ":=", "binary", ".", "NewEncoder", "(", "ciphertext", ")", "\n", "if", "err", ":=", "enc", ".", "Encode", "(", "0x1", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "enc", ".", "Encode", "(", "header", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "num", ":=", "0", "\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "chunkSizeMax", ")", "\n", "encbuf", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "for", "{", "n", ",", "err", ":=", "plaintext", ".", "Read", "(", "buf", ")", "\n", "if", "err", ":=", "x", ".", "encryptChunk", "(", "sessionKey", ",", "num", ",", "buf", "[", ":", "n", "]", ",", "encbuf", ",", "ciphertext", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "num", "++", "\n", "}", "\n", "}" ]
// EncryptStream encrypts the plaintext using a slightly modified on disk-format // suitable for streaming
[ "EncryptStream", "encrypts", "the", "plaintext", "using", "a", "slightly", "modified", "on", "disk", "-", "format", "suitable", "for", "streaming" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/stream.go#L18-L65
train
gopasspw/gopass
pkg/backend/crypto/xc/stream.go
DecryptStream
func (x *XC) DecryptStream(ctx context.Context, ciphertext io.Reader, plaintext io.Writer) error { dec := binary.NewDecoder(ciphertext) // read version ver := 0 if err := dec.Decode(&ver); err != nil { return err } if ver != 0x1 { return fmt.Errorf("wrong version") } // read header header := &xcpb.Header{} if err := dec.Decode(header); err != nil { return err } // try to find a suiteable decryption key in the header sk, err := x.decryptSessionKey(ctx, header) if err != nil { return err } var secretKey [32]byte copy(secretKey[:], sk) // read body num := 0 var buf []byte br := &byteReader{ciphertext} for { l, err := stdbin.ReadUvarint(br) if err != nil { if err == io.EOF { return nil } return err } buf = make([]byte, l) n, err := br.Read(buf) if err := x.decryptChunk(secretKey, num, buf[:n], plaintext); err != nil { return err } if err != nil { if err == io.EOF { return nil } return err } num++ } }
go
func (x *XC) DecryptStream(ctx context.Context, ciphertext io.Reader, plaintext io.Writer) error { dec := binary.NewDecoder(ciphertext) // read version ver := 0 if err := dec.Decode(&ver); err != nil { return err } if ver != 0x1 { return fmt.Errorf("wrong version") } // read header header := &xcpb.Header{} if err := dec.Decode(header); err != nil { return err } // try to find a suiteable decryption key in the header sk, err := x.decryptSessionKey(ctx, header) if err != nil { return err } var secretKey [32]byte copy(secretKey[:], sk) // read body num := 0 var buf []byte br := &byteReader{ciphertext} for { l, err := stdbin.ReadUvarint(br) if err != nil { if err == io.EOF { return nil } return err } buf = make([]byte, l) n, err := br.Read(buf) if err := x.decryptChunk(secretKey, num, buf[:n], plaintext); err != nil { return err } if err != nil { if err == io.EOF { return nil } return err } num++ } }
[ "func", "(", "x", "*", "XC", ")", "DecryptStream", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "io", ".", "Reader", ",", "plaintext", "io", ".", "Writer", ")", "error", "{", "dec", ":=", "binary", ".", "NewDecoder", "(", "ciphertext", ")", "\n", "ver", ":=", "0", "\n", "if", "err", ":=", "dec", ".", "Decode", "(", "&", "ver", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "ver", "!=", "0x1", "{", "return", "fmt", ".", "Errorf", "(", "\"wrong version\"", ")", "\n", "}", "\n", "header", ":=", "&", "xcpb", ".", "Header", "{", "}", "\n", "if", "err", ":=", "dec", ".", "Decode", "(", "header", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "sk", ",", "err", ":=", "x", ".", "decryptSessionKey", "(", "ctx", ",", "header", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "var", "secretKey", "[", "32", "]", "byte", "\n", "copy", "(", "secretKey", "[", ":", "]", ",", "sk", ")", "\n", "num", ":=", "0", "\n", "var", "buf", "[", "]", "byte", "\n", "br", ":=", "&", "byteReader", "{", "ciphertext", "}", "\n", "for", "{", "l", ",", "err", ":=", "stdbin", ".", "ReadUvarint", "(", "br", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "buf", "=", "make", "(", "[", "]", "byte", ",", "l", ")", "\n", "n", ",", "err", ":=", "br", ".", "Read", "(", "buf", ")", "\n", "if", "err", ":=", "x", ".", "decryptChunk", "(", "secretKey", ",", "num", ",", "buf", "[", ":", "n", "]", ",", "plaintext", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "num", "++", "\n", "}", "\n", "}" ]
// DecryptStream decrypts an stream encrypted with EncryptStream
[ "DecryptStream", "decrypts", "an", "stream", "encrypted", "with", "EncryptStream" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/stream.go#L89-L140
train
gopasspw/gopass
pkg/action/errors.go
ExitError
func ExitError(ctx context.Context, exitCode int, err error, format string, args ...interface{}) error { if err != nil { out.Debug(ctx, "Stacktrace: %+v", err) } return cli.NewExitError(fmt.Sprintf(format, args...), exitCode) }
go
func ExitError(ctx context.Context, exitCode int, err error, format string, args ...interface{}) error { if err != nil { out.Debug(ctx, "Stacktrace: %+v", err) } return cli.NewExitError(fmt.Sprintf(format, args...), exitCode) }
[ "func", "ExitError", "(", "ctx", "context", ".", "Context", ",", "exitCode", "int", ",", "err", "error", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "error", "{", "if", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"Stacktrace: %+v\"", ",", "err", ")", "\n", "}", "\n", "return", "cli", ".", "NewExitError", "(", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", ",", "exitCode", ")", "\n", "}" ]
// ExitError returns a user friendly CLI error
[ "ExitError", "returns", "a", "user", "friendly", "CLI", "error" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/errors.go#L58-L63
train
gopasspw/gopass
pkg/store/sub/write.go
Set
func (s *Store) Set(ctx context.Context, name string, sec store.Secret) error { if strings.Contains(name, "//") { return errors.Errorf("invalid secret name: %s", name) } p := s.passfile(name) if s.IsDir(ctx, name) { return errors.Errorf("a folder named %s already exists", name) } recipients, err := s.useableKeys(ctx, name) if err != nil { return errors.Wrapf(err, "failed to list useable keys for '%s'", p) } // confirm recipients newRecipients, err := GetRecipientFunc(ctx)(ctx, name, recipients) if err != nil { return errors.Wrapf(err, "user aborted") } recipients = newRecipients // make sure the encryptor can decrypt later recipients = s.ensureOurKeyID(ctx, recipients) buf, err := sec.Bytes() if err != nil { return errors.Wrapf(err, "failed to encode secret") } ciphertext, err := s.crypto.Encrypt(ctx, buf, recipients) if err != nil { out.Debug(ctx, "Failed encrypt secret: %s", err) return store.ErrEncrypt } if err := s.storage.Set(ctx, p, ciphertext); err != nil { return errors.Wrapf(err, "failed to write secret") } // It is not possible to perform concurrent git add and git commit commands // so we need to skip this step when using concurrency and perform them // at the end of the batch processing. if ctxutil.HasConcurrency(ctx) { out.Debug(ctx, "sub.Set(%s) - skipping git ops due to concurrency", p) return nil } if err := s.rcs.Add(ctx, p); err != nil { if errors.Cause(err) == store.ErrGitNotInit { return nil } return errors.Wrapf(err, "failed to add '%s' to git", p) } if !ctxutil.IsGitCommit(ctx) { return nil } return s.gitCommitAndPush(ctx, name) }
go
func (s *Store) Set(ctx context.Context, name string, sec store.Secret) error { if strings.Contains(name, "//") { return errors.Errorf("invalid secret name: %s", name) } p := s.passfile(name) if s.IsDir(ctx, name) { return errors.Errorf("a folder named %s already exists", name) } recipients, err := s.useableKeys(ctx, name) if err != nil { return errors.Wrapf(err, "failed to list useable keys for '%s'", p) } // confirm recipients newRecipients, err := GetRecipientFunc(ctx)(ctx, name, recipients) if err != nil { return errors.Wrapf(err, "user aborted") } recipients = newRecipients // make sure the encryptor can decrypt later recipients = s.ensureOurKeyID(ctx, recipients) buf, err := sec.Bytes() if err != nil { return errors.Wrapf(err, "failed to encode secret") } ciphertext, err := s.crypto.Encrypt(ctx, buf, recipients) if err != nil { out.Debug(ctx, "Failed encrypt secret: %s", err) return store.ErrEncrypt } if err := s.storage.Set(ctx, p, ciphertext); err != nil { return errors.Wrapf(err, "failed to write secret") } // It is not possible to perform concurrent git add and git commit commands // so we need to skip this step when using concurrency and perform them // at the end of the batch processing. if ctxutil.HasConcurrency(ctx) { out.Debug(ctx, "sub.Set(%s) - skipping git ops due to concurrency", p) return nil } if err := s.rcs.Add(ctx, p); err != nil { if errors.Cause(err) == store.ErrGitNotInit { return nil } return errors.Wrapf(err, "failed to add '%s' to git", p) } if !ctxutil.IsGitCommit(ctx) { return nil } return s.gitCommitAndPush(ctx, name) }
[ "func", "(", "s", "*", "Store", ")", "Set", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "sec", "store", ".", "Secret", ")", "error", "{", "if", "strings", ".", "Contains", "(", "name", ",", "\"//\"", ")", "{", "return", "errors", ".", "Errorf", "(", "\"invalid secret name: %s\"", ",", "name", ")", "\n", "}", "\n", "p", ":=", "s", ".", "passfile", "(", "name", ")", "\n", "if", "s", ".", "IsDir", "(", "ctx", ",", "name", ")", "{", "return", "errors", ".", "Errorf", "(", "\"a folder named %s already exists\"", ",", "name", ")", "\n", "}", "\n", "recipients", ",", "err", ":=", "s", ".", "useableKeys", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to list useable keys for '%s'\"", ",", "p", ")", "\n", "}", "\n", "newRecipients", ",", "err", ":=", "GetRecipientFunc", "(", "ctx", ")", "(", "ctx", ",", "name", ",", "recipients", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"user aborted\"", ")", "\n", "}", "\n", "recipients", "=", "newRecipients", "\n", "recipients", "=", "s", ".", "ensureOurKeyID", "(", "ctx", ",", "recipients", ")", "\n", "buf", ",", "err", ":=", "sec", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to encode secret\"", ")", "\n", "}", "\n", "ciphertext", ",", "err", ":=", "s", ".", "crypto", ".", "Encrypt", "(", "ctx", ",", "buf", ",", "recipients", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"Failed encrypt secret: %s\"", ",", "err", ")", "\n", "return", "store", ".", "ErrEncrypt", "\n", "}", "\n", "if", "err", ":=", "s", ".", "storage", ".", "Set", "(", "ctx", ",", "p", ",", "ciphertext", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to write secret\"", ")", "\n", "}", "\n", "if", "ctxutil", ".", "HasConcurrency", "(", "ctx", ")", "{", "out", ".", "Debug", "(", "ctx", ",", "\"sub.Set(%s) - skipping git ops due to concurrency\"", ",", "p", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "s", ".", "rcs", ".", "Add", "(", "ctx", ",", "p", ")", ";", "err", "!=", "nil", "{", "if", "errors", ".", "Cause", "(", "err", ")", "==", "store", ".", "ErrGitNotInit", "{", "return", "nil", "\n", "}", "\n", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to add '%s' to git\"", ",", "p", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "IsGitCommit", "(", "ctx", ")", "{", "return", "nil", "\n", "}", "\n", "return", "s", ".", "gitCommitAndPush", "(", "ctx", ",", "name", ")", "\n", "}" ]
// Set encodes and writes the cipertext of one entry to disk
[ "Set", "encodes", "and", "writes", "the", "cipertext", "of", "one", "entry", "to", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/write.go#L16-L77
train
gopasspw/gopass
pkg/store/sub/move.go
Move
func (s *Store) Move(ctx context.Context, from, to string) error { // recursive move? if s.IsDir(ctx, from) { return errors.Errorf("recursive operations are not supported") } content, err := s.Get(ctx, from) if err != nil { return errors.Wrapf(err, "failed to decrypt '%s'", from) } if err := s.Set(WithReason(ctx, fmt.Sprintf("Moved from %s to %s", from, to)), to, content); err != nil { return errors.Wrapf(err, "failed to write '%s'", to) } if err := s.Delete(ctx, from); err != nil { return errors.Wrapf(err, "failed to delete '%s'", from) } return nil }
go
func (s *Store) Move(ctx context.Context, from, to string) error { // recursive move? if s.IsDir(ctx, from) { return errors.Errorf("recursive operations are not supported") } content, err := s.Get(ctx, from) if err != nil { return errors.Wrapf(err, "failed to decrypt '%s'", from) } if err := s.Set(WithReason(ctx, fmt.Sprintf("Moved from %s to %s", from, to)), to, content); err != nil { return errors.Wrapf(err, "failed to write '%s'", to) } if err := s.Delete(ctx, from); err != nil { return errors.Wrapf(err, "failed to delete '%s'", from) } return nil }
[ "func", "(", "s", "*", "Store", ")", "Move", "(", "ctx", "context", ".", "Context", ",", "from", ",", "to", "string", ")", "error", "{", "if", "s", ".", "IsDir", "(", "ctx", ",", "from", ")", "{", "return", "errors", ".", "Errorf", "(", "\"recursive operations are not supported\"", ")", "\n", "}", "\n", "content", ",", "err", ":=", "s", ".", "Get", "(", "ctx", ",", "from", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to decrypt '%s'\"", ",", "from", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Set", "(", "WithReason", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Moved from %s to %s\"", ",", "from", ",", "to", ")", ")", ",", "to", ",", "content", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to write '%s'\"", ",", "to", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Delete", "(", "ctx", ",", "from", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to delete '%s'\"", ",", "from", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Move will move one entry from one location to another. // Moving an entry will decode it from the old location, encode it // for the destination store with the right set of recipients and remove it // from the old location afterwards.
[ "Move", "will", "move", "one", "entry", "from", "one", "location", "to", "another", ".", "Moving", "an", "entry", "will", "decode", "it", "from", "the", "old", "location", "encode", "it", "for", "the", "destination", "store", "with", "the", "right", "set", "of", "recipients", "and", "remove", "it", "from", "the", "old", "location", "afterwards", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/move.go#L39-L56
train
gopasspw/gopass
pkg/store/sub/move.go
delete
func (s *Store) delete(ctx context.Context, name string, recurse bool) error { path := s.passfile(name) if recurse { if err := s.deleteRecurse(ctx, name, path); err != nil { return err } } if err := s.deleteSingle(ctx, path); err != nil { if !recurse { return err } } if !ctxutil.IsGitCommit(ctx) { return nil } if err := s.rcs.Commit(ctx, fmt.Sprintf("Remove %s from store.", name)); err != nil { if errors.Cause(err) == store.ErrGitNotInit { return nil } return errors.Wrapf(err, "failed to commit changes to git") } // abort if auto sync is not set if !IsAutoSync(ctx) { return nil } if err := s.rcs.Push(ctx, "", ""); err != nil { if errors.Cause(err) == store.ErrGitNotInit || errors.Cause(err) == store.ErrGitNoRemote { return nil } return errors.Wrapf(err, "failed to push change to git remote") } return nil }
go
func (s *Store) delete(ctx context.Context, name string, recurse bool) error { path := s.passfile(name) if recurse { if err := s.deleteRecurse(ctx, name, path); err != nil { return err } } if err := s.deleteSingle(ctx, path); err != nil { if !recurse { return err } } if !ctxutil.IsGitCommit(ctx) { return nil } if err := s.rcs.Commit(ctx, fmt.Sprintf("Remove %s from store.", name)); err != nil { if errors.Cause(err) == store.ErrGitNotInit { return nil } return errors.Wrapf(err, "failed to commit changes to git") } // abort if auto sync is not set if !IsAutoSync(ctx) { return nil } if err := s.rcs.Push(ctx, "", ""); err != nil { if errors.Cause(err) == store.ErrGitNotInit || errors.Cause(err) == store.ErrGitNoRemote { return nil } return errors.Wrapf(err, "failed to push change to git remote") } return nil }
[ "func", "(", "s", "*", "Store", ")", "delete", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "recurse", "bool", ")", "error", "{", "path", ":=", "s", ".", "passfile", "(", "name", ")", "\n", "if", "recurse", "{", "if", "err", ":=", "s", ".", "deleteRecurse", "(", "ctx", ",", "name", ",", "path", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "s", ".", "deleteSingle", "(", "ctx", ",", "path", ")", ";", "err", "!=", "nil", "{", "if", "!", "recurse", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "!", "ctxutil", ".", "IsGitCommit", "(", "ctx", ")", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "s", ".", "rcs", ".", "Commit", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Remove %s from store.\"", ",", "name", ")", ")", ";", "err", "!=", "nil", "{", "if", "errors", ".", "Cause", "(", "err", ")", "==", "store", ".", "ErrGitNotInit", "{", "return", "nil", "\n", "}", "\n", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to commit changes to git\"", ")", "\n", "}", "\n", "if", "!", "IsAutoSync", "(", "ctx", ")", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "s", ".", "rcs", ".", "Push", "(", "ctx", ",", "\"\"", ",", "\"\"", ")", ";", "err", "!=", "nil", "{", "if", "errors", ".", "Cause", "(", "err", ")", "==", "store", ".", "ErrGitNotInit", "||", "errors", ".", "Cause", "(", "err", ")", "==", "store", ".", "ErrGitNoRemote", "{", "return", "nil", "\n", "}", "\n", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to push change to git remote\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// delete will either delete one file or an directory tree depending on the // recurse flag
[ "delete", "will", "either", "delete", "one", "file", "or", "an", "directory", "tree", "depending", "on", "the", "recurse", "flag" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/move.go#L70-L108
train
gopasspw/gopass
pkg/action/action.go
New
func New(ctx context.Context, cfg *config.Config, sv semver.Version) (*Action, error) { return newAction(ctx, cfg, sv) }
go
func New(ctx context.Context, cfg *config.Config, sv semver.Version) (*Action, error) { return newAction(ctx, cfg, sv) }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "cfg", "*", "config", ".", "Config", ",", "sv", "semver", ".", "Version", ")", "(", "*", "Action", ",", "error", ")", "{", "return", "newAction", "(", "ctx", ",", "cfg", ",", "sv", ")", "\n", "}" ]
// New returns a new Action wrapper
[ "New", "returns", "a", "new", "Action", "wrapper" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/action.go#L30-L32
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/generate.go
CreatePrivateKeyBatch
func (g *GPG) CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase string) error { buf := &bytes.Buffer{} // https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=doc/DETAILS;h=de0f21ccba60c3037c2a155156202df1cd098507;hb=refs/heads/STABLE-BRANCH-1-4#l716 _, _ = buf.WriteString(`%echo Generating a RSA/RSA key pair Key-Type: RSA Key-Length: 2048 Subkey-Type: RSA Subkey-Length: 2048 Expire-Date: 0 `) _, _ = buf.WriteString("Name-Real: " + name + "\n") _, _ = buf.WriteString("Name-Email: " + email + "\n") _, _ = buf.WriteString("Passphrase: " + passphrase + "\n") args := []string{"--batch", "--gen-key"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf.Bytes()) cmd.Stdout = nil cmd.Stderr = nil out.Debug(ctx, "gpg.CreatePrivateKeyBatch: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return errors.Wrapf(err, "failed to run command: '%s %+v'", cmd.Path, cmd.Args) } g.privKeys = nil g.pubKeys = nil return nil }
go
func (g *GPG) CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase string) error { buf := &bytes.Buffer{} // https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=doc/DETAILS;h=de0f21ccba60c3037c2a155156202df1cd098507;hb=refs/heads/STABLE-BRANCH-1-4#l716 _, _ = buf.WriteString(`%echo Generating a RSA/RSA key pair Key-Type: RSA Key-Length: 2048 Subkey-Type: RSA Subkey-Length: 2048 Expire-Date: 0 `) _, _ = buf.WriteString("Name-Real: " + name + "\n") _, _ = buf.WriteString("Name-Email: " + email + "\n") _, _ = buf.WriteString("Passphrase: " + passphrase + "\n") args := []string{"--batch", "--gen-key"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf.Bytes()) cmd.Stdout = nil cmd.Stderr = nil out.Debug(ctx, "gpg.CreatePrivateKeyBatch: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return errors.Wrapf(err, "failed to run command: '%s %+v'", cmd.Path, cmd.Args) } g.privKeys = nil g.pubKeys = nil return nil }
[ "func", "(", "g", "*", "GPG", ")", "CreatePrivateKeyBatch", "(", "ctx", "context", ".", "Context", ",", "name", ",", "email", ",", "passphrase", "string", ")", "error", "{", "buf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "`%echo Generating a RSA/RSA key pairKey-Type: RSAKey-Length: 2048Subkey-Type: RSASubkey-Length: 2048Expire-Date: 0`", ")", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"Name-Real: \"", "+", "name", "+", "\"\\n\"", ")", "\n", "\\n", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"Name-Email: \"", "+", "email", "+", "\"\\n\"", ")", "\n", "\\n", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"Passphrase: \"", "+", "passphrase", "+", "\"\\n\"", ")", "\n", "\\n", "\n", "args", ":=", "[", "]", "string", "{", "\"--batch\"", ",", "\"--gen-key\"", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "bytes", ".", "NewReader", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "cmd", ".", "Stdout", "=", "nil", "\n", "cmd", ".", "Stderr", "=", "nil", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg.CreatePrivateKeyBatch: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to run command: '%s %+v'\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "}", "\n", "}" ]
// CreatePrivateKeyBatch will create a new GPG keypair in batch mode
[ "CreatePrivateKeyBatch", "will", "create", "a", "new", "GPG", "keypair", "in", "batch", "mode" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/generate.go#L15-L42
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/generate.go
CreatePrivateKey
func (g *GPG) CreatePrivateKey(ctx context.Context) error { args := []string{"--gen-key"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.CreatePrivateKey: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return errors.Wrapf(err, "failed to run command: '%s %+v'", cmd.Path, cmd.Args) } g.privKeys = nil g.pubKeys = nil return nil }
go
func (g *GPG) CreatePrivateKey(ctx context.Context) error { args := []string{"--gen-key"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.CreatePrivateKey: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return errors.Wrapf(err, "failed to run command: '%s %+v'", cmd.Path, cmd.Args) } g.privKeys = nil g.pubKeys = nil return nil }
[ "func", "(", "g", "*", "GPG", ")", "CreatePrivateKey", "(", "ctx", "context", ".", "Context", ")", "error", "{", "args", ":=", "[", "]", "string", "{", "\"--gen-key\"", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "os", ".", "Stdin", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg.CreatePrivateKey: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to run command: '%s %+v'\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "}", "\n", "g", ".", "privKeys", "=", "nil", "\n", "g", ".", "pubKeys", "=", "nil", "\n", "return", "nil", "\n", "}" ]
// CreatePrivateKey will create a new GPG key in interactive mode
[ "CreatePrivateKey", "will", "create", "a", "new", "GPG", "key", "in", "interactive", "mode" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/generate.go#L45-L60
train
gopasspw/gopass
pkg/backend/rcs/git/cli/config.go
InitConfig
func (g *Git) InitConfig(ctx context.Context, userName, userEmail string) error { if userName == "" || userEmail == "" || !strings.Contains(userEmail, "@") { return fmt.Errorf("username and email must not be empty and valid") } // set commit identity if err := g.ConfigSet(ctx, "user.name", userName); err != nil { return errors.Wrapf(err, "failed to set git config user.name") } if err := g.ConfigSet(ctx, "user.email", userEmail); err != nil { return errors.Wrapf(err, "failed to set git config user.email") } // ensure sane git config if err := g.fixConfig(ctx); err != nil { return errors.Wrapf(err, "failed to fix git config") } if err := ioutil.WriteFile(filepath.Join(g.path, ".gitattributes"), []byte("*.gpg diff=gpg\n"), fileMode); err != nil { return errors.Errorf("Failed to initialize git: %s", err) } if err := g.Add(ctx, g.path+"/.gitattributes"); err != nil { out.Yellow(ctx, "Warning: Failed to add .gitattributes to git") } if err := g.Commit(ctx, "Configure git repository for gpg file diff."); err != nil { out.Yellow(ctx, "Warning: Failed to commit .gitattributes to git") } return nil }
go
func (g *Git) InitConfig(ctx context.Context, userName, userEmail string) error { if userName == "" || userEmail == "" || !strings.Contains(userEmail, "@") { return fmt.Errorf("username and email must not be empty and valid") } // set commit identity if err := g.ConfigSet(ctx, "user.name", userName); err != nil { return errors.Wrapf(err, "failed to set git config user.name") } if err := g.ConfigSet(ctx, "user.email", userEmail); err != nil { return errors.Wrapf(err, "failed to set git config user.email") } // ensure sane git config if err := g.fixConfig(ctx); err != nil { return errors.Wrapf(err, "failed to fix git config") } if err := ioutil.WriteFile(filepath.Join(g.path, ".gitattributes"), []byte("*.gpg diff=gpg\n"), fileMode); err != nil { return errors.Errorf("Failed to initialize git: %s", err) } if err := g.Add(ctx, g.path+"/.gitattributes"); err != nil { out.Yellow(ctx, "Warning: Failed to add .gitattributes to git") } if err := g.Commit(ctx, "Configure git repository for gpg file diff."); err != nil { out.Yellow(ctx, "Warning: Failed to commit .gitattributes to git") } return nil }
[ "func", "(", "g", "*", "Git", ")", "InitConfig", "(", "ctx", "context", ".", "Context", ",", "userName", ",", "userEmail", "string", ")", "error", "{", "if", "userName", "==", "\"\"", "||", "userEmail", "==", "\"\"", "||", "!", "strings", ".", "Contains", "(", "userEmail", ",", "\"@\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"username and email must not be empty and valid\"", ")", "\n", "}", "\n", "if", "err", ":=", "g", ".", "ConfigSet", "(", "ctx", ",", "\"user.name\"", ",", "userName", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to set git config user.name\"", ")", "\n", "}", "\n", "if", "err", ":=", "g", ".", "ConfigSet", "(", "ctx", ",", "\"user.email\"", ",", "userEmail", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to set git config user.email\"", ")", "\n", "}", "\n", "if", "err", ":=", "g", ".", "fixConfig", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to fix git config\"", ")", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "filepath", ".", "Join", "(", "g", ".", "path", ",", "\".gitattributes\"", ")", ",", "[", "]", "byte", "(", "\"*.gpg diff=gpg\\n\"", ")", ",", "\\n", ")", ";", "fileMode", "err", "!=", "nil", "\n", "{", "return", "errors", ".", "Errorf", "(", "\"Failed to initialize git: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "g", ".", "Add", "(", "ctx", ",", "g", ".", "path", "+", "\"/.gitattributes\"", ")", ";", "err", "!=", "nil", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"Warning: Failed to add .gitattributes to git\"", ")", "\n", "}", "\n", "if", "err", ":=", "g", ".", "Commit", "(", "ctx", ",", "\"Configure git repository for gpg file diff.\"", ")", ";", "err", "!=", "nil", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"Warning: Failed to commit .gitattributes to git\"", ")", "\n", "}", "\n", "}" ]
// InitConfig initialized and preparse the git config
[ "InitConfig", "initialized", "and", "preparse", "the", "git", "config" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/config.go#L42-L70
train
gopasspw/gopass
pkg/backend/rcs/git/cli/config.go
ConfigSet
func (g *Git) ConfigSet(ctx context.Context, key, value string) error { return g.Cmd(ctx, "gitConfigSet", "config", "--local", key, value) }
go
func (g *Git) ConfigSet(ctx context.Context, key, value string) error { return g.Cmd(ctx, "gitConfigSet", "config", "--local", key, value) }
[ "func", "(", "g", "*", "Git", ")", "ConfigSet", "(", "ctx", "context", ".", "Context", ",", "key", ",", "value", "string", ")", "error", "{", "return", "g", ".", "Cmd", "(", "ctx", ",", "\"gitConfigSet\"", ",", "\"config\"", ",", "\"--local\"", ",", "key", ",", "value", ")", "\n", "}" ]
// ConfigSet sets a local config value
[ "ConfigSet", "sets", "a", "local", "config", "value" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/config.go#L73-L75
train
gopasspw/gopass
pkg/backend/rcs/git/cli/config.go
ConfigGet
func (g *Git) ConfigGet(ctx context.Context, key string) (string, error) { if !g.IsInitialized() { return "", store.ErrGitNotInit } buf := &strings.Builder{} cmd := exec.CommandContext(ctx, "git", "config", "--get", key) cmd.Dir = g.path cmd.Stdout = buf cmd.Stderr = os.Stderr out.Debug(ctx, "store.gitConfigGet: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return "", err } return strings.TrimSpace(buf.String()), nil }
go
func (g *Git) ConfigGet(ctx context.Context, key string) (string, error) { if !g.IsInitialized() { return "", store.ErrGitNotInit } buf := &strings.Builder{} cmd := exec.CommandContext(ctx, "git", "config", "--get", key) cmd.Dir = g.path cmd.Stdout = buf cmd.Stderr = os.Stderr out.Debug(ctx, "store.gitConfigGet: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return "", err } return strings.TrimSpace(buf.String()), nil }
[ "func", "(", "g", "*", "Git", ")", "ConfigGet", "(", "ctx", "context", ".", "Context", ",", "key", "string", ")", "(", "string", ",", "error", ")", "{", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "return", "\"\"", ",", "store", ".", "ErrGitNotInit", "\n", "}", "\n", "buf", ":=", "&", "strings", ".", "Builder", "{", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "\"git\"", ",", "\"config\"", ",", "\"--get\"", ",", "key", ")", "\n", "cmd", ".", "Dir", "=", "g", ".", "path", "\n", "cmd", ".", "Stdout", "=", "buf", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"store.gitConfigGet: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "return", "strings", ".", "TrimSpace", "(", "buf", ".", "String", "(", ")", ")", ",", "nil", "\n", "}" ]
// ConfigGet returns a given config value
[ "ConfigGet", "returns", "a", "given", "config", "value" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/config.go#L78-L96
train
gopasspw/gopass
pkg/backend/rcs/git/cli/config.go
ConfigList
func (g *Git) ConfigList(ctx context.Context) (map[string]string, error) { if !g.IsInitialized() { return nil, store.ErrGitNotInit } buf := &strings.Builder{} cmd := exec.CommandContext(ctx, "git", "config", "--list") cmd.Dir = g.path cmd.Stdout = buf cmd.Stderr = os.Stderr out.Debug(ctx, "store.gitConfigList: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return nil, err } lines := strings.Split(buf.String(), "\n") kv := make(map[string]string, len(lines)) for _, line := range lines { line = strings.TrimSpace(line) p := strings.SplitN(line, "=", 2) if len(p) < 2 { continue } kv[p[0]] = p[1] } return kv, nil }
go
func (g *Git) ConfigList(ctx context.Context) (map[string]string, error) { if !g.IsInitialized() { return nil, store.ErrGitNotInit } buf := &strings.Builder{} cmd := exec.CommandContext(ctx, "git", "config", "--list") cmd.Dir = g.path cmd.Stdout = buf cmd.Stderr = os.Stderr out.Debug(ctx, "store.gitConfigList: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return nil, err } lines := strings.Split(buf.String(), "\n") kv := make(map[string]string, len(lines)) for _, line := range lines { line = strings.TrimSpace(line) p := strings.SplitN(line, "=", 2) if len(p) < 2 { continue } kv[p[0]] = p[1] } return kv, nil }
[ "func", "(", "g", "*", "Git", ")", "ConfigList", "(", "ctx", "context", ".", "Context", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "return", "nil", ",", "store", ".", "ErrGitNotInit", "\n", "}", "\n", "buf", ":=", "&", "strings", ".", "Builder", "{", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "\"git\"", ",", "\"config\"", ",", "\"--list\"", ")", "\n", "cmd", ".", "Dir", "=", "g", ".", "path", "\n", "cmd", ".", "Stdout", "=", "buf", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"store.gitConfigList: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "lines", ":=", "strings", ".", "Split", "(", "buf", ".", "String", "(", ")", ",", "\"\\n\"", ")", "\n", "\\n", "\n", "kv", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "lines", ")", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "line", "=", "strings", ".", "TrimSpace", "(", "line", ")", "\n", "p", ":=", "strings", ".", "SplitN", "(", "line", ",", "\"=\"", ",", "2", ")", "\n", "if", "len", "(", "p", ")", "<", "2", "{", "continue", "\n", "}", "\n", "kv", "[", "p", "[", "0", "]", "]", "=", "p", "[", "1", "]", "\n", "}", "\n", "}" ]
// ConfigList returns all git config settings
[ "ConfigList", "returns", "all", "git", "config", "settings" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/config.go#L99-L127
train
gopasspw/gopass
pkg/action/recipients.go
RecipientsPrint
func (s *Action) RecipientsPrint(ctx context.Context, c *cli.Context) error { out.Cyan(ctx, "Hint: run 'gopass sync' to import any missing public keys") tree, err := s.Store.RecipientsTree(ctx, true) if err != nil { return ExitError(ctx, ExitList, err, "failed to list recipients: %s", err) } fmt.Fprintln(stdout, tree.Format(0)) return nil }
go
func (s *Action) RecipientsPrint(ctx context.Context, c *cli.Context) error { out.Cyan(ctx, "Hint: run 'gopass sync' to import any missing public keys") tree, err := s.Store.RecipientsTree(ctx, true) if err != nil { return ExitError(ctx, ExitList, err, "failed to list recipients: %s", err) } fmt.Fprintln(stdout, tree.Format(0)) return nil }
[ "func", "(", "s", "*", "Action", ")", "RecipientsPrint", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"Hint: run 'gopass sync' to import any missing public keys\"", ")", "\n", "tree", ",", "err", ":=", "s", ".", "Store", ".", "RecipientsTree", "(", "ctx", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitList", ",", "err", ",", "\"failed to list recipients: %s\"", ",", "err", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "stdout", ",", "tree", ".", "Format", "(", "0", ")", ")", "\n", "return", "nil", "\n", "}" ]
// RecipientsPrint prints all recipients per store
[ "RecipientsPrint", "prints", "all", "recipients", "per", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/recipients.go#L38-L48
train
gopasspw/gopass
pkg/action/recipients.go
RecipientsComplete
func (s *Action) RecipientsComplete(ctx context.Context, c *cli.Context) { tree, err := s.Store.RecipientsTree(out.WithHidden(ctx, true), false) if err != nil { fmt.Fprintln(stdout, err) return } for _, v := range tree.List(0) { fmt.Fprintln(stdout, v) } }
go
func (s *Action) RecipientsComplete(ctx context.Context, c *cli.Context) { tree, err := s.Store.RecipientsTree(out.WithHidden(ctx, true), false) if err != nil { fmt.Fprintln(stdout, err) return } for _, v := range tree.List(0) { fmt.Fprintln(stdout, v) } }
[ "func", "(", "s", "*", "Action", ")", "RecipientsComplete", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "{", "tree", ",", "err", ":=", "s", ".", "Store", ".", "RecipientsTree", "(", "out", ".", "WithHidden", "(", "ctx", ",", "true", ")", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "err", ")", "\n", "return", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "tree", ".", "List", "(", "0", ")", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "v", ")", "\n", "}", "\n", "}" ]
// RecipientsComplete will print a list of recipients for bash // completion
[ "RecipientsComplete", "will", "print", "a", "list", "of", "recipients", "for", "bash", "completion" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/recipients.go#L52-L62
train
gopasspw/gopass
pkg/action/recipients.go
RecipientsAdd
func (s *Action) RecipientsAdd(ctx context.Context, c *cli.Context) error { store := c.String("store") force := c.Bool("force") added := 0 // select store if store == "" { store = cui.AskForStore(ctx, s.Store) } crypto := s.Store.Crypto(ctx, store) // select recipient recipients := []string(c.Args()) if len(recipients) < 1 { r, err := s.recipientsSelectForAdd(ctx, store) if err != nil { return err } recipients = r } for _, r := range recipients { keys, err := crypto.FindPublicKeys(ctx, r) if err != nil { out.Cyan(ctx, "WARNING: Failed to list public key '%s': %s", r, err) if !force { continue } keys = []string{r} } if len(keys) < 1 && !force { out.Cyan(ctx, "Warning: No matching valid key found. If the key is in your keyring you may need to validate it.") out.Cyan(ctx, "If this is your key: gpg --edit-key %s; trust (set to ultimate); quit", r) out.Cyan(ctx, "If this is not your key: gpg --edit-key %s; lsign; trust; save; quit", r) out.Cyan(ctx, "You may need to run 'gpg --update-trustdb' afterwards") continue } recp := r if len(keys) > 0 { recp = crypto.Fingerprint(ctx, keys[0]) } if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add '%s' as a recipient to the store '%s'?", crypto.FormatKey(ctx, recp), store)) { continue } if err := s.Store.AddRecipient(ctxutil.WithNoConfirm(ctx, true), store, recp); err != nil { return ExitError(ctx, ExitRecipients, err, "failed to add recipient '%s': %s", r, err) } added++ } if added < 1 { return ExitError(ctx, ExitUnknown, nil, "no key added") } out.Green(ctx, "\nAdded %d recipients", added) out.Cyan(ctx, "You need to run 'gopass sync' to push these changes") return nil }
go
func (s *Action) RecipientsAdd(ctx context.Context, c *cli.Context) error { store := c.String("store") force := c.Bool("force") added := 0 // select store if store == "" { store = cui.AskForStore(ctx, s.Store) } crypto := s.Store.Crypto(ctx, store) // select recipient recipients := []string(c.Args()) if len(recipients) < 1 { r, err := s.recipientsSelectForAdd(ctx, store) if err != nil { return err } recipients = r } for _, r := range recipients { keys, err := crypto.FindPublicKeys(ctx, r) if err != nil { out.Cyan(ctx, "WARNING: Failed to list public key '%s': %s", r, err) if !force { continue } keys = []string{r} } if len(keys) < 1 && !force { out.Cyan(ctx, "Warning: No matching valid key found. If the key is in your keyring you may need to validate it.") out.Cyan(ctx, "If this is your key: gpg --edit-key %s; trust (set to ultimate); quit", r) out.Cyan(ctx, "If this is not your key: gpg --edit-key %s; lsign; trust; save; quit", r) out.Cyan(ctx, "You may need to run 'gpg --update-trustdb' afterwards") continue } recp := r if len(keys) > 0 { recp = crypto.Fingerprint(ctx, keys[0]) } if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add '%s' as a recipient to the store '%s'?", crypto.FormatKey(ctx, recp), store)) { continue } if err := s.Store.AddRecipient(ctxutil.WithNoConfirm(ctx, true), store, recp); err != nil { return ExitError(ctx, ExitRecipients, err, "failed to add recipient '%s': %s", r, err) } added++ } if added < 1 { return ExitError(ctx, ExitUnknown, nil, "no key added") } out.Green(ctx, "\nAdded %d recipients", added) out.Cyan(ctx, "You need to run 'gopass sync' to push these changes") return nil }
[ "func", "(", "s", "*", "Action", ")", "RecipientsAdd", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"store\"", ")", "\n", "force", ":=", "c", ".", "Bool", "(", "\"force\"", ")", "\n", "added", ":=", "0", "\n", "if", "store", "==", "\"\"", "{", "store", "=", "cui", ".", "AskForStore", "(", "ctx", ",", "s", ".", "Store", ")", "\n", "}", "\n", "crypto", ":=", "s", ".", "Store", ".", "Crypto", "(", "ctx", ",", "store", ")", "\n", "recipients", ":=", "[", "]", "string", "(", "c", ".", "Args", "(", ")", ")", "\n", "if", "len", "(", "recipients", ")", "<", "1", "{", "r", ",", "err", ":=", "s", ".", "recipientsSelectForAdd", "(", "ctx", ",", "store", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "recipients", "=", "r", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "recipients", "{", "keys", ",", "err", ":=", "crypto", ".", "FindPublicKeys", "(", "ctx", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"WARNING: Failed to list public key '%s': %s\"", ",", "r", ",", "err", ")", "\n", "if", "!", "force", "{", "continue", "\n", "}", "\n", "keys", "=", "[", "]", "string", "{", "r", "}", "\n", "}", "\n", "if", "len", "(", "keys", ")", "<", "1", "&&", "!", "force", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"Warning: No matching valid key found. If the key is in your keyring you may need to validate it.\"", ")", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"If this is your key: gpg --edit-key %s; trust (set to ultimate); quit\"", ",", "r", ")", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"If this is not your key: gpg --edit-key %s; lsign; trust; save; quit\"", ",", "r", ")", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"You may need to run 'gpg --update-trustdb' afterwards\"", ")", "\n", "continue", "\n", "}", "\n", "recp", ":=", "r", "\n", "if", "len", "(", "keys", ")", ">", "0", "{", "recp", "=", "crypto", ".", "Fingerprint", "(", "ctx", ",", "keys", "[", "0", "]", ")", "\n", "}", "\n", "if", "!", "termio", ".", "AskForConfirmation", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Do you want to add '%s' as a recipient to the store '%s'?\"", ",", "crypto", ".", "FormatKey", "(", "ctx", ",", "recp", ")", ",", "store", ")", ")", "{", "continue", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "AddRecipient", "(", "ctxutil", ".", "WithNoConfirm", "(", "ctx", ",", "true", ")", ",", "store", ",", "recp", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitRecipients", ",", "err", ",", "\"failed to add recipient '%s': %s\"", ",", "r", ",", "err", ")", "\n", "}", "\n", "added", "++", "\n", "}", "\n", "if", "added", "<", "1", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "nil", ",", "\"no key added\"", ")", "\n", "}", "\n", "out", ".", "Green", "(", "ctx", ",", "\"\\nAdded %d recipients\"", ",", "\\n", ")", "\n", "added", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"You need to run 'gopass sync' to push these changes\"", ")", "\n", "}" ]
// RecipientsAdd adds new recipients
[ "RecipientsAdd", "adds", "new", "recipients" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/recipients.go#L65-L125
train
gopasspw/gopass
pkg/action/recipients.go
RecipientsRemove
func (s *Action) RecipientsRemove(ctx context.Context, c *cli.Context) error { store := c.String("store") force := c.Bool("force") removed := 0 // select store if store == "" { store = cui.AskForStore(ctx, s.Store) } crypto := s.Store.Crypto(ctx, store) // select recipient recipients := []string(c.Args()) if len(recipients) < 1 { rs, err := s.recipientsSelectForRemoval(ctx, store) if err != nil { return err } recipients = rs } for _, r := range recipients { kl, err := crypto.FindPrivateKeys(ctx, r) if err == nil { if len(kl) > 0 { if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to remove yourself (%s) from the recipients?", r)) { continue } } } keys, err := crypto.FindPublicKeys(ctx, r) if err != nil { out.Cyan(ctx, "WARNING: Failed to list public key '%s': %s", r, err) if !force { continue } keys = []string{r} } if len(keys) < 1 && !force { out.Cyan(ctx, "Warning: No matching valid key found. If the key is in your keyring you may need to validate it.") out.Cyan(ctx, "If this is your key: gpg --edit-key %s; trust (set to ultimate); quit", r) out.Cyan(ctx, "If this is not your key: gpg --edit-key %s; lsign; trust; save; quit", r) out.Cyan(ctx, "You may need to run 'gpg --update-trustdb' afterwards") continue } recp := r if len(keys) > 0 { recp = crypto.Fingerprint(ctx, keys[0]) } if err := s.Store.RemoveRecipient(ctxutil.WithNoConfirm(ctx, true), store, recp); err != nil { return ExitError(ctx, ExitRecipients, err, "failed to remove recipient '%s': %s", recp, err) } fmt.Fprintf(stdout, removalWarning, r) removed++ } if removed < 1 { return ExitError(ctx, ExitUnknown, nil, "no key removed") } out.Green(ctx, "\nRemoved %d recipients", removed) out.Cyan(ctx, "You need to run 'gopass sync' to push these changes") return nil }
go
func (s *Action) RecipientsRemove(ctx context.Context, c *cli.Context) error { store := c.String("store") force := c.Bool("force") removed := 0 // select store if store == "" { store = cui.AskForStore(ctx, s.Store) } crypto := s.Store.Crypto(ctx, store) // select recipient recipients := []string(c.Args()) if len(recipients) < 1 { rs, err := s.recipientsSelectForRemoval(ctx, store) if err != nil { return err } recipients = rs } for _, r := range recipients { kl, err := crypto.FindPrivateKeys(ctx, r) if err == nil { if len(kl) > 0 { if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to remove yourself (%s) from the recipients?", r)) { continue } } } keys, err := crypto.FindPublicKeys(ctx, r) if err != nil { out.Cyan(ctx, "WARNING: Failed to list public key '%s': %s", r, err) if !force { continue } keys = []string{r} } if len(keys) < 1 && !force { out.Cyan(ctx, "Warning: No matching valid key found. If the key is in your keyring you may need to validate it.") out.Cyan(ctx, "If this is your key: gpg --edit-key %s; trust (set to ultimate); quit", r) out.Cyan(ctx, "If this is not your key: gpg --edit-key %s; lsign; trust; save; quit", r) out.Cyan(ctx, "You may need to run 'gpg --update-trustdb' afterwards") continue } recp := r if len(keys) > 0 { recp = crypto.Fingerprint(ctx, keys[0]) } if err := s.Store.RemoveRecipient(ctxutil.WithNoConfirm(ctx, true), store, recp); err != nil { return ExitError(ctx, ExitRecipients, err, "failed to remove recipient '%s': %s", recp, err) } fmt.Fprintf(stdout, removalWarning, r) removed++ } if removed < 1 { return ExitError(ctx, ExitUnknown, nil, "no key removed") } out.Green(ctx, "\nRemoved %d recipients", removed) out.Cyan(ctx, "You need to run 'gopass sync' to push these changes") return nil }
[ "func", "(", "s", "*", "Action", ")", "RecipientsRemove", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"store\"", ")", "\n", "force", ":=", "c", ".", "Bool", "(", "\"force\"", ")", "\n", "removed", ":=", "0", "\n", "if", "store", "==", "\"\"", "{", "store", "=", "cui", ".", "AskForStore", "(", "ctx", ",", "s", ".", "Store", ")", "\n", "}", "\n", "crypto", ":=", "s", ".", "Store", ".", "Crypto", "(", "ctx", ",", "store", ")", "\n", "recipients", ":=", "[", "]", "string", "(", "c", ".", "Args", "(", ")", ")", "\n", "if", "len", "(", "recipients", ")", "<", "1", "{", "rs", ",", "err", ":=", "s", ".", "recipientsSelectForRemoval", "(", "ctx", ",", "store", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "recipients", "=", "rs", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "recipients", "{", "kl", ",", "err", ":=", "crypto", ".", "FindPrivateKeys", "(", "ctx", ",", "r", ")", "\n", "if", "err", "==", "nil", "{", "if", "len", "(", "kl", ")", ">", "0", "{", "if", "!", "termio", ".", "AskForConfirmation", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Do you want to remove yourself (%s) from the recipients?\"", ",", "r", ")", ")", "{", "continue", "\n", "}", "\n", "}", "\n", "}", "\n", "keys", ",", "err", ":=", "crypto", ".", "FindPublicKeys", "(", "ctx", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"WARNING: Failed to list public key '%s': %s\"", ",", "r", ",", "err", ")", "\n", "if", "!", "force", "{", "continue", "\n", "}", "\n", "keys", "=", "[", "]", "string", "{", "r", "}", "\n", "}", "\n", "if", "len", "(", "keys", ")", "<", "1", "&&", "!", "force", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"Warning: No matching valid key found. If the key is in your keyring you may need to validate it.\"", ")", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"If this is your key: gpg --edit-key %s; trust (set to ultimate); quit\"", ",", "r", ")", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"If this is not your key: gpg --edit-key %s; lsign; trust; save; quit\"", ",", "r", ")", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"You may need to run 'gpg --update-trustdb' afterwards\"", ")", "\n", "continue", "\n", "}", "\n", "recp", ":=", "r", "\n", "if", "len", "(", "keys", ")", ">", "0", "{", "recp", "=", "crypto", ".", "Fingerprint", "(", "ctx", ",", "keys", "[", "0", "]", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "RemoveRecipient", "(", "ctxutil", ".", "WithNoConfirm", "(", "ctx", ",", "true", ")", ",", "store", ",", "recp", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitRecipients", ",", "err", ",", "\"failed to remove recipient '%s': %s\"", ",", "recp", ",", "err", ")", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "removalWarning", ",", "r", ")", "\n", "removed", "++", "\n", "}", "\n", "if", "removed", "<", "1", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "nil", ",", "\"no key removed\"", ")", "\n", "}", "\n", "out", ".", "Green", "(", "ctx", ",", "\"\\nRemoved %d recipients\"", ",", "\\n", ")", "\n", "removed", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"You need to run 'gopass sync' to push these changes\"", ")", "\n", "}" ]
// RecipientsRemove removes recipients
[ "RecipientsRemove", "removes", "recipients" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/recipients.go#L128-L194
train
gopasspw/gopass
pkg/action/recipients.go
RecipientsUpdate
func (s *Action) RecipientsUpdate(ctx context.Context, c *cli.Context) error { changed := 0 mps := s.Store.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range append(mps, "") { subs, err := s.Store.GetSubStore(alias) if err != nil || subs == nil { continue } recp, err := subs.GetRecipients(ctx, "") if err != nil { if err != sub.ErrRecipientChecksumChanged { return err } } if err == nil && s.cfg.GetRecipientHash(alias, subs.Crypto().IDFile()) != "" { continue } if alias == "" { alias = "<root>" } out.Cyan(ctx, "Please confirm Recipients for %s:", alias) for _, r := range recp { out.Print(ctx, "- %s", subs.Crypto().FormatKey(ctx, r)) } if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you trust these recipients for %s?", alias)) { continue } if err := subs.SetRecipients(ctx, recp); err != nil { return err } out.Print(ctx, "") changed++ } if changed > 0 { out.Green(ctx, "Updated %d stores", changed) } else { out.Green(ctx, "Nothing to do") } return nil }
go
func (s *Action) RecipientsUpdate(ctx context.Context, c *cli.Context) error { changed := 0 mps := s.Store.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range append(mps, "") { subs, err := s.Store.GetSubStore(alias) if err != nil || subs == nil { continue } recp, err := subs.GetRecipients(ctx, "") if err != nil { if err != sub.ErrRecipientChecksumChanged { return err } } if err == nil && s.cfg.GetRecipientHash(alias, subs.Crypto().IDFile()) != "" { continue } if alias == "" { alias = "<root>" } out.Cyan(ctx, "Please confirm Recipients for %s:", alias) for _, r := range recp { out.Print(ctx, "- %s", subs.Crypto().FormatKey(ctx, r)) } if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you trust these recipients for %s?", alias)) { continue } if err := subs.SetRecipients(ctx, recp); err != nil { return err } out.Print(ctx, "") changed++ } if changed > 0 { out.Green(ctx, "Updated %d stores", changed) } else { out.Green(ctx, "Nothing to do") } return nil }
[ "func", "(", "s", "*", "Action", ")", "RecipientsUpdate", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "changed", ":=", "0", "\n", "mps", ":=", "s", ".", "Store", ".", "MountPoints", "(", ")", "\n", "sort", ".", "Sort", "(", "store", ".", "ByPathLen", "(", "mps", ")", ")", "\n", "for", "_", ",", "alias", ":=", "range", "append", "(", "mps", ",", "\"\"", ")", "{", "subs", ",", "err", ":=", "s", ".", "Store", ".", "GetSubStore", "(", "alias", ")", "\n", "if", "err", "!=", "nil", "||", "subs", "==", "nil", "{", "continue", "\n", "}", "\n", "recp", ",", "err", ":=", "subs", ".", "GetRecipients", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "sub", ".", "ErrRecipientChecksumChanged", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "err", "==", "nil", "&&", "s", ".", "cfg", ".", "GetRecipientHash", "(", "alias", ",", "subs", ".", "Crypto", "(", ")", ".", "IDFile", "(", ")", ")", "!=", "\"\"", "{", "continue", "\n", "}", "\n", "if", "alias", "==", "\"\"", "{", "alias", "=", "\"<root>\"", "\n", "}", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"Please confirm Recipients for %s:\"", ",", "alias", ")", "\n", "for", "_", ",", "r", ":=", "range", "recp", "{", "out", ".", "Print", "(", "ctx", ",", "\"- %s\"", ",", "subs", ".", "Crypto", "(", ")", ".", "FormatKey", "(", "ctx", ",", "r", ")", ")", "\n", "}", "\n", "if", "!", "termio", ".", "AskForConfirmation", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Do you trust these recipients for %s?\"", ",", "alias", ")", ")", "{", "continue", "\n", "}", "\n", "if", "err", ":=", "subs", ".", "SetRecipients", "(", "ctx", ",", "recp", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "out", ".", "Print", "(", "ctx", ",", "\"\"", ")", "\n", "changed", "++", "\n", "}", "\n", "if", "changed", ">", "0", "{", "out", ".", "Green", "(", "ctx", ",", "\"Updated %d stores\"", ",", "changed", ")", "\n", "}", "else", "{", "out", ".", "Green", "(", "ctx", ",", "\"Nothing to do\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RecipientsUpdate will recompute and update any changed recipients list checksums
[ "RecipientsUpdate", "will", "recompute", "and", "update", "any", "changed", "recipients", "list", "checksums" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/recipients.go#L197-L240
train
gopasspw/gopass
pkg/action/otp.go
OTP
func (s *Action) OTP(ctx context.Context, c *cli.Context) error { name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s otp <NAME>", s.Name) } qrf := c.String("qr") clip := c.Bool("clip") return s.otp(ctx, c, name, qrf, clip, true) }
go
func (s *Action) OTP(ctx context.Context, c *cli.Context) error { name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s otp <NAME>", s.Name) } qrf := c.String("qr") clip := c.Bool("clip") return s.otp(ctx, c, name, qrf, clip, true) }
[ "func", "(", "s", "*", "Action", ")", "OTP", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "name", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "if", "name", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s otp <NAME>\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "qrf", ":=", "c", ".", "String", "(", "\"qr\"", ")", "\n", "clip", ":=", "c", ".", "Bool", "(", "\"clip\"", ")", "\n", "return", "s", ".", "otp", "(", "ctx", ",", "c", ",", "name", ",", "qrf", ",", "clip", ",", "true", ")", "\n", "}" ]
// OTP implements OTP token handling for TOTP and HOTP
[ "OTP", "implements", "OTP", "token", "handling", "for", "TOTP", "and", "HOTP" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/otp.go#L26-L36
train
gopasspw/gopass
pkg/backend/crypto/xc/decrypt.go
Decrypt
func (x *XC) Decrypt(ctx context.Context, buf []byte) ([]byte, error) { // unmarshal the protobuf message, the header and body are still encrypted // afterwards (parts of the header are plaintext!) msg := &xcpb.Message{} if err := proto.Unmarshal(buf, msg); err != nil { return nil, err } // try to find a suiteable decryption key in the header sk, err := x.decryptSessionKey(ctx, msg.Header) if err != nil { return nil, err } var secretKey [32]byte copy(secretKey[:], sk) plainBuf := &bytes.Buffer{} for i, chunk := range msg.Chunks { // reconstruct nonce from chunk number // in case chunks have been reordered by some adversary // decryption will fail var nonce [24]byte binary.BigEndian.PutUint64(nonce[:], uint64(i)) // decrypt and verify the ciphertext //plaintext, err := cp.Open(nil, nonce, chunk.Body, nil) plaintext, ok := secretbox.Open(nil, chunk.Body, &nonce, &secretKey) if !ok { return nil, fmt.Errorf("failed to decrypt") } plainBuf.Write(plaintext) } if !msg.Compressed { return plainBuf.Bytes(), nil } return decompress(plainBuf.Bytes()) }
go
func (x *XC) Decrypt(ctx context.Context, buf []byte) ([]byte, error) { // unmarshal the protobuf message, the header and body are still encrypted // afterwards (parts of the header are plaintext!) msg := &xcpb.Message{} if err := proto.Unmarshal(buf, msg); err != nil { return nil, err } // try to find a suiteable decryption key in the header sk, err := x.decryptSessionKey(ctx, msg.Header) if err != nil { return nil, err } var secretKey [32]byte copy(secretKey[:], sk) plainBuf := &bytes.Buffer{} for i, chunk := range msg.Chunks { // reconstruct nonce from chunk number // in case chunks have been reordered by some adversary // decryption will fail var nonce [24]byte binary.BigEndian.PutUint64(nonce[:], uint64(i)) // decrypt and verify the ciphertext //plaintext, err := cp.Open(nil, nonce, chunk.Body, nil) plaintext, ok := secretbox.Open(nil, chunk.Body, &nonce, &secretKey) if !ok { return nil, fmt.Errorf("failed to decrypt") } plainBuf.Write(plaintext) } if !msg.Compressed { return plainBuf.Bytes(), nil } return decompress(plainBuf.Bytes()) }
[ "func", "(", "x", "*", "XC", ")", "Decrypt", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "msg", ":=", "&", "xcpb", ".", "Message", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "msg", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "sk", ",", "err", ":=", "x", ".", "decryptSessionKey", "(", "ctx", ",", "msg", ".", "Header", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "secretKey", "[", "32", "]", "byte", "\n", "copy", "(", "secretKey", "[", ":", "]", ",", "sk", ")", "\n", "plainBuf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "for", "i", ",", "chunk", ":=", "range", "msg", ".", "Chunks", "{", "var", "nonce", "[", "24", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "nonce", "[", ":", "]", ",", "uint64", "(", "i", ")", ")", "\n", "plaintext", ",", "ok", ":=", "secretbox", ".", "Open", "(", "nil", ",", "chunk", ".", "Body", ",", "&", "nonce", ",", "&", "secretKey", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"failed to decrypt\"", ")", "\n", "}", "\n", "plainBuf", ".", "Write", "(", "plaintext", ")", "\n", "}", "\n", "if", "!", "msg", ".", "Compressed", "{", "return", "plainBuf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}", "\n", "return", "decompress", "(", "plainBuf", ".", "Bytes", "(", ")", ")", "\n", "}" ]
// Decrypt tries to decrypt the given ciphertext and returns the plaintext
[ "Decrypt", "tries", "to", "decrypt", "the", "given", "ciphertext", "and", "returns", "the", "plaintext" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/decrypt.go#L25-L66
train
gopasspw/gopass
pkg/backend/crypto/xc/decrypt.go
findDecryptionKey
func (x *XC) findDecryptionKey(hdr *xcpb.Header) (*keyring.PrivateKey, error) { for _, pk := range x.secring.KeyIDs() { if _, found := hdr.Recipients[pk]; found { return x.secring.Get(pk), nil } } return nil, fmt.Errorf("no decryption key found for: %+v", hdr.Recipients) }
go
func (x *XC) findDecryptionKey(hdr *xcpb.Header) (*keyring.PrivateKey, error) { for _, pk := range x.secring.KeyIDs() { if _, found := hdr.Recipients[pk]; found { return x.secring.Get(pk), nil } } return nil, fmt.Errorf("no decryption key found for: %+v", hdr.Recipients) }
[ "func", "(", "x", "*", "XC", ")", "findDecryptionKey", "(", "hdr", "*", "xcpb", ".", "Header", ")", "(", "*", "keyring", ".", "PrivateKey", ",", "error", ")", "{", "for", "_", ",", "pk", ":=", "range", "x", ".", "secring", ".", "KeyIDs", "(", ")", "{", "if", "_", ",", "found", ":=", "hdr", ".", "Recipients", "[", "pk", "]", ";", "found", "{", "return", "x", ".", "secring", ".", "Get", "(", "pk", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"no decryption key found for: %+v\"", ",", "hdr", ".", "Recipients", ")", "\n", "}" ]
// findDecryptionKey tries to find a suiteable decryption key from the available // decryption keys and the recipients
[ "findDecryptionKey", "tries", "to", "find", "a", "suiteable", "decryption", "key", "from", "the", "available", "decryption", "keys", "and", "the", "recipients" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/decrypt.go#L70-L77
train
gopasspw/gopass
pkg/backend/crypto/xc/decrypt.go
findPublicKey
func (x *XC) findPublicKey(needle string) (*keyring.PublicKey, error) { for _, id := range x.pubring.KeyIDs() { if id == needle { return x.pubring.Get(id), nil } } return nil, fmt.Errorf("no sender found for id '%s'", needle) }
go
func (x *XC) findPublicKey(needle string) (*keyring.PublicKey, error) { for _, id := range x.pubring.KeyIDs() { if id == needle { return x.pubring.Get(id), nil } } return nil, fmt.Errorf("no sender found for id '%s'", needle) }
[ "func", "(", "x", "*", "XC", ")", "findPublicKey", "(", "needle", "string", ")", "(", "*", "keyring", ".", "PublicKey", ",", "error", ")", "{", "for", "_", ",", "id", ":=", "range", "x", ".", "pubring", ".", "KeyIDs", "(", ")", "{", "if", "id", "==", "needle", "{", "return", "x", ".", "pubring", ".", "Get", "(", "id", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"no sender found for id '%s'\"", ",", "needle", ")", "\n", "}" ]
// findPublicKey tries to find a given public key in the keyring
[ "findPublicKey", "tries", "to", "find", "a", "given", "public", "key", "in", "the", "keyring" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/decrypt.go#L80-L87
train
gopasspw/gopass
pkg/backend/crypto/xc/decrypt.go
decryptPrivateKey
func (x *XC) decryptPrivateKey(ctx context.Context, recp *keyring.PrivateKey) error { fp := recp.Fingerprint() for i := 0; i < maxUnlockAttempts; i++ { // retry asking for key in case it's wrong passphrase, err := x.client.Passphrase(ctx, fp, fmt.Sprintf("Unlock private key %s", recp.Fingerprint())) if err != nil { return errors.Wrapf(err, "failed to get passphrase from agent: %s", err) } if err = recp.Decrypt(passphrase); err == nil { // passphrase is correct, the key should now be decrypted return nil } // decryption failed, clear cache and wait a moment before trying again if err := x.client.Remove(ctx, fp); err != nil { return errors.Wrapf(err, "failed to clear cache") } time.Sleep(10 * time.Millisecond) } return fmt.Errorf("failed to unlock private key '%s' after %d retries", fp, maxUnlockAttempts) }
go
func (x *XC) decryptPrivateKey(ctx context.Context, recp *keyring.PrivateKey) error { fp := recp.Fingerprint() for i := 0; i < maxUnlockAttempts; i++ { // retry asking for key in case it's wrong passphrase, err := x.client.Passphrase(ctx, fp, fmt.Sprintf("Unlock private key %s", recp.Fingerprint())) if err != nil { return errors.Wrapf(err, "failed to get passphrase from agent: %s", err) } if err = recp.Decrypt(passphrase); err == nil { // passphrase is correct, the key should now be decrypted return nil } // decryption failed, clear cache and wait a moment before trying again if err := x.client.Remove(ctx, fp); err != nil { return errors.Wrapf(err, "failed to clear cache") } time.Sleep(10 * time.Millisecond) } return fmt.Errorf("failed to unlock private key '%s' after %d retries", fp, maxUnlockAttempts) }
[ "func", "(", "x", "*", "XC", ")", "decryptPrivateKey", "(", "ctx", "context", ".", "Context", ",", "recp", "*", "keyring", ".", "PrivateKey", ")", "error", "{", "fp", ":=", "recp", ".", "Fingerprint", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "maxUnlockAttempts", ";", "i", "++", "{", "passphrase", ",", "err", ":=", "x", ".", "client", ".", "Passphrase", "(", "ctx", ",", "fp", ",", "fmt", ".", "Sprintf", "(", "\"Unlock private key %s\"", ",", "recp", ".", "Fingerprint", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to get passphrase from agent: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "err", "=", "recp", ".", "Decrypt", "(", "passphrase", ")", ";", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "x", ".", "client", ".", "Remove", "(", "ctx", ",", "fp", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to clear cache\"", ")", "\n", "}", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"failed to unlock private key '%s' after %d retries\"", ",", "fp", ",", "maxUnlockAttempts", ")", "\n", "}" ]
// decryptPrivateKey will ask the agent to unlock the private key
[ "decryptPrivateKey", "will", "ask", "the", "agent", "to", "unlock", "the", "private", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/decrypt.go#L90-L113
train
gopasspw/gopass
pkg/backend/crypto/xc/decrypt.go
decryptSessionKey
func (x *XC) decryptSessionKey(ctx context.Context, hdr *xcpb.Header) ([]byte, error) { // find a suiteable decryption key, i.e. a recipient entry which was encrypted // for one of our private keys recp, err := x.findDecryptionKey(hdr) if err != nil { return nil, errors.Wrapf(err, "unable to find decryption key") } // we need the senders public key to decrypt/verify the message, since the // box algorithm ties successful decryption to successful verification sender, err := x.findPublicKey(hdr.Sender) if err != nil { return nil, errors.Wrapf(err, "unable to find sender pub key for signature verification: %s", hdr.Sender) } // unlock recipient key if err := x.decryptPrivateKey(ctx, recp); err != nil { return nil, err } // this is the per recipient ciphertext, we need to decrypt it to extract // the session key ciphertext := hdr.Recipients[recp.Fingerprint()] // since box works with byte arrays (or: pointers thereof) we need to copy // the slice to fixed arrays var nonce [24]byte copy(nonce[:], ciphertext[:24]) var privKey [32]byte pk := recp.PrivateKey() copy(privKey[:], pk[:]) // now we can try to decrypt/verify the ciphertext. unfortunately box doesn't give // us any diagnostic information in case it fails, i.e. we can't discern between // a failed decryption and a failed verification decrypted, ok := box.Open(nil, ciphertext[24:], &nonce, &sender.PublicKey, &privKey) if !ok { return nil, fmt.Errorf("failed to decrypt session key") } return decrypted, nil }
go
func (x *XC) decryptSessionKey(ctx context.Context, hdr *xcpb.Header) ([]byte, error) { // find a suiteable decryption key, i.e. a recipient entry which was encrypted // for one of our private keys recp, err := x.findDecryptionKey(hdr) if err != nil { return nil, errors.Wrapf(err, "unable to find decryption key") } // we need the senders public key to decrypt/verify the message, since the // box algorithm ties successful decryption to successful verification sender, err := x.findPublicKey(hdr.Sender) if err != nil { return nil, errors.Wrapf(err, "unable to find sender pub key for signature verification: %s", hdr.Sender) } // unlock recipient key if err := x.decryptPrivateKey(ctx, recp); err != nil { return nil, err } // this is the per recipient ciphertext, we need to decrypt it to extract // the session key ciphertext := hdr.Recipients[recp.Fingerprint()] // since box works with byte arrays (or: pointers thereof) we need to copy // the slice to fixed arrays var nonce [24]byte copy(nonce[:], ciphertext[:24]) var privKey [32]byte pk := recp.PrivateKey() copy(privKey[:], pk[:]) // now we can try to decrypt/verify the ciphertext. unfortunately box doesn't give // us any diagnostic information in case it fails, i.e. we can't discern between // a failed decryption and a failed verification decrypted, ok := box.Open(nil, ciphertext[24:], &nonce, &sender.PublicKey, &privKey) if !ok { return nil, fmt.Errorf("failed to decrypt session key") } return decrypted, nil }
[ "func", "(", "x", "*", "XC", ")", "decryptSessionKey", "(", "ctx", "context", ".", "Context", ",", "hdr", "*", "xcpb", ".", "Header", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "recp", ",", "err", ":=", "x", ".", "findDecryptionKey", "(", "hdr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"unable to find decryption key\"", ")", "\n", "}", "\n", "sender", ",", "err", ":=", "x", ".", "findPublicKey", "(", "hdr", ".", "Sender", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"unable to find sender pub key for signature verification: %s\"", ",", "hdr", ".", "Sender", ")", "\n", "}", "\n", "if", "err", ":=", "x", ".", "decryptPrivateKey", "(", "ctx", ",", "recp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ciphertext", ":=", "hdr", ".", "Recipients", "[", "recp", ".", "Fingerprint", "(", ")", "]", "\n", "var", "nonce", "[", "24", "]", "byte", "\n", "copy", "(", "nonce", "[", ":", "]", ",", "ciphertext", "[", ":", "24", "]", ")", "\n", "var", "privKey", "[", "32", "]", "byte", "\n", "pk", ":=", "recp", ".", "PrivateKey", "(", ")", "\n", "copy", "(", "privKey", "[", ":", "]", ",", "pk", "[", ":", "]", ")", "\n", "decrypted", ",", "ok", ":=", "box", ".", "Open", "(", "nil", ",", "ciphertext", "[", "24", ":", "]", ",", "&", "nonce", ",", "&", "sender", ".", "PublicKey", ",", "&", "privKey", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"failed to decrypt session key\"", ")", "\n", "}", "\n", "return", "decrypted", ",", "nil", "\n", "}" ]
// decryptSessionKey will attempt to find a readable recipient entry in the // header and decrypt it's session key
[ "decryptSessionKey", "will", "attempt", "to", "find", "a", "readable", "recipient", "entry", "in", "the", "header", "and", "decrypt", "it", "s", "session", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/decrypt.go#L117-L158
train
gopasspw/gopass
pkg/action/mount.go
MountRemove
func (s *Action) MountRemove(ctx context.Context, c *cli.Context) error { if len(c.Args()) != 1 { return ExitError(ctx, ExitUsage, nil, "Usage: %s mount remove [alias]", s.Name) } if err := s.Store.RemoveMount(ctx, c.Args()[0]); err != nil { out.Error(ctx, "Failed to remove mount: %s", err) } if err := s.cfg.Save(); err != nil { return ExitError(ctx, ExitConfig, err, "failed to write config: %s", err) } out.Green(ctx, "Password Store %s umounted", c.Args()[0]) return nil }
go
func (s *Action) MountRemove(ctx context.Context, c *cli.Context) error { if len(c.Args()) != 1 { return ExitError(ctx, ExitUsage, nil, "Usage: %s mount remove [alias]", s.Name) } if err := s.Store.RemoveMount(ctx, c.Args()[0]); err != nil { out.Error(ctx, "Failed to remove mount: %s", err) } if err := s.cfg.Save(); err != nil { return ExitError(ctx, ExitConfig, err, "failed to write config: %s", err) } out.Green(ctx, "Password Store %s umounted", c.Args()[0]) return nil }
[ "func", "(", "s", "*", "Action", ")", "MountRemove", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "len", "(", "c", ".", "Args", "(", ")", ")", "!=", "1", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s mount remove [alias]\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "RemoveMount", "(", "ctx", ",", "c", ".", "Args", "(", ")", "[", "0", "]", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Failed to remove mount: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "cfg", ".", "Save", "(", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitConfig", ",", "err", ",", "\"failed to write config: %s\"", ",", "err", ")", "\n", "}", "\n", "out", ".", "Green", "(", "ctx", ",", "\"Password Store %s umounted\"", ",", "c", ".", "Args", "(", ")", "[", "0", "]", ")", "\n", "return", "nil", "\n", "}" ]
// MountRemove removes an existing mount
[ "MountRemove", "removes", "an", "existing", "mount" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/mount.go#L20-L35
train
gopasspw/gopass
pkg/action/mount.go
MountsPrint
func (s *Action) MountsPrint(ctx context.Context, c *cli.Context) error { if len(s.Store.Mounts()) < 1 { out.Cyan(ctx, "No mounts") return nil } root := simple.New(color.GreenString(fmt.Sprintf("gopass (%s)", s.Store.Path()))) mounts := s.Store.Mounts() mps := s.Store.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { path := mounts[alias] if err := root.AddMount(alias, path); err != nil { out.Error(ctx, "Failed to add mount to tree: %s", err) } } fmt.Fprintln(stdout, root.Format(0)) return nil }
go
func (s *Action) MountsPrint(ctx context.Context, c *cli.Context) error { if len(s.Store.Mounts()) < 1 { out.Cyan(ctx, "No mounts") return nil } root := simple.New(color.GreenString(fmt.Sprintf("gopass (%s)", s.Store.Path()))) mounts := s.Store.Mounts() mps := s.Store.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { path := mounts[alias] if err := root.AddMount(alias, path); err != nil { out.Error(ctx, "Failed to add mount to tree: %s", err) } } fmt.Fprintln(stdout, root.Format(0)) return nil }
[ "func", "(", "s", "*", "Action", ")", "MountsPrint", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "len", "(", "s", ".", "Store", ".", "Mounts", "(", ")", ")", "<", "1", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"No mounts\"", ")", "\n", "return", "nil", "\n", "}", "\n", "root", ":=", "simple", ".", "New", "(", "color", ".", "GreenString", "(", "fmt", ".", "Sprintf", "(", "\"gopass (%s)\"", ",", "s", ".", "Store", ".", "Path", "(", ")", ")", ")", ")", "\n", "mounts", ":=", "s", ".", "Store", ".", "Mounts", "(", ")", "\n", "mps", ":=", "s", ".", "Store", ".", "MountPoints", "(", ")", "\n", "sort", ".", "Sort", "(", "store", ".", "ByPathLen", "(", "mps", ")", ")", "\n", "for", "_", ",", "alias", ":=", "range", "mps", "{", "path", ":=", "mounts", "[", "alias", "]", "\n", "if", "err", ":=", "root", ".", "AddMount", "(", "alias", ",", "path", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Failed to add mount to tree: %s\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "stdout", ",", "root", ".", "Format", "(", "0", ")", ")", "\n", "return", "nil", "\n", "}" ]
// MountsPrint prints all existing mounts
[ "MountsPrint", "prints", "all", "existing", "mounts" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/mount.go#L38-L57
train
gopasspw/gopass
pkg/action/mount.go
MountsComplete
func (s *Action) MountsComplete(*cli.Context) { for alias := range s.Store.Mounts() { fmt.Fprintln(stdout, alias) } }
go
func (s *Action) MountsComplete(*cli.Context) { for alias := range s.Store.Mounts() { fmt.Fprintln(stdout, alias) } }
[ "func", "(", "s", "*", "Action", ")", "MountsComplete", "(", "*", "cli", ".", "Context", ")", "{", "for", "alias", ":=", "range", "s", ".", "Store", ".", "Mounts", "(", ")", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "alias", ")", "\n", "}", "\n", "}" ]
// MountsComplete will print a list of existings mount points for bash // completion
[ "MountsComplete", "will", "print", "a", "list", "of", "existings", "mount", "points", "for", "bash", "completion" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/mount.go#L61-L65
train
gopasspw/gopass
pkg/action/mount.go
MountAdd
func (s *Action) MountAdd(ctx context.Context, c *cli.Context) error { alias := c.Args().Get(0) localPath := c.Args().Get(1) if alias == "" { return ExitError(ctx, ExitUsage, nil, "usage: %s mounts add <alias> [local path]", s.Name) } if localPath == "" { localPath = config.PwStoreDir(alias) } keys := make([]string, 0, 1) if k := c.String("init"); k != "" { keys = append(keys, k) } if s.Store.Exists(ctx, alias) { out.Yellow(ctx, "WARNING: shadowing %s entry", alias) } if err := s.Store.AddMount(ctx, alias, localPath, keys...); err != nil { switch e := errors.Cause(err).(type) { case root.AlreadyMountedError: out.Print(ctx, "Store is already mounted") return nil case root.NotInitializedError: out.Print(ctx, "Mount %s is not yet initialized. Initializing ...", e.Alias()) if err := s.init(ctx, e.Alias(), e.Path()); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to add mount '%s': failed to initialize store: %s", e.Alias(), err) } default: return ExitError(ctx, ExitMount, err, "failed to add mount '%s' to '%s': %s", alias, localPath, err) } } if err := s.cfg.Save(); err != nil { return ExitError(ctx, ExitConfig, err, "failed to save config: %s", err) } out.Green(ctx, "Mounted %s as %s", alias, localPath) return nil }
go
func (s *Action) MountAdd(ctx context.Context, c *cli.Context) error { alias := c.Args().Get(0) localPath := c.Args().Get(1) if alias == "" { return ExitError(ctx, ExitUsage, nil, "usage: %s mounts add <alias> [local path]", s.Name) } if localPath == "" { localPath = config.PwStoreDir(alias) } keys := make([]string, 0, 1) if k := c.String("init"); k != "" { keys = append(keys, k) } if s.Store.Exists(ctx, alias) { out.Yellow(ctx, "WARNING: shadowing %s entry", alias) } if err := s.Store.AddMount(ctx, alias, localPath, keys...); err != nil { switch e := errors.Cause(err).(type) { case root.AlreadyMountedError: out.Print(ctx, "Store is already mounted") return nil case root.NotInitializedError: out.Print(ctx, "Mount %s is not yet initialized. Initializing ...", e.Alias()) if err := s.init(ctx, e.Alias(), e.Path()); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to add mount '%s': failed to initialize store: %s", e.Alias(), err) } default: return ExitError(ctx, ExitMount, err, "failed to add mount '%s' to '%s': %s", alias, localPath, err) } } if err := s.cfg.Save(); err != nil { return ExitError(ctx, ExitConfig, err, "failed to save config: %s", err) } out.Green(ctx, "Mounted %s as %s", alias, localPath) return nil }
[ "func", "(", "s", "*", "Action", ")", "MountAdd", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "alias", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "localPath", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n", "if", "alias", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"usage: %s mounts add <alias> [local path]\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "if", "localPath", "==", "\"\"", "{", "localPath", "=", "config", ".", "PwStoreDir", "(", "alias", ")", "\n", "}", "\n", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "1", ")", "\n", "if", "k", ":=", "c", ".", "String", "(", "\"init\"", ")", ";", "k", "!=", "\"\"", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "if", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "alias", ")", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"WARNING: shadowing %s entry\"", ",", "alias", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "AddMount", "(", "ctx", ",", "alias", ",", "localPath", ",", "keys", "...", ")", ";", "err", "!=", "nil", "{", "switch", "e", ":=", "errors", ".", "Cause", "(", "err", ")", ".", "(", "type", ")", "{", "case", "root", ".", "AlreadyMountedError", ":", "out", ".", "Print", "(", "ctx", ",", "\"Store is already mounted\"", ")", "\n", "return", "nil", "\n", "case", "root", ".", "NotInitializedError", ":", "out", ".", "Print", "(", "ctx", ",", "\"Mount %s is not yet initialized. Initializing ...\"", ",", "e", ".", "Alias", "(", ")", ")", "\n", "if", "err", ":=", "s", ".", "init", "(", "ctx", ",", "e", ".", "Alias", "(", ")", ",", "e", ".", "Path", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"failed to add mount '%s': failed to initialize store: %s\"", ",", "e", ".", "Alias", "(", ")", ",", "err", ")", "\n", "}", "\n", "default", ":", "return", "ExitError", "(", "ctx", ",", "ExitMount", ",", "err", ",", "\"failed to add mount '%s' to '%s': %s\"", ",", "alias", ",", "localPath", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "s", ".", "cfg", ".", "Save", "(", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitConfig", ",", "err", ",", "\"failed to save config: %s\"", ",", "err", ")", "\n", "}", "\n", "out", ".", "Green", "(", "ctx", ",", "\"Mounted %s as %s\"", ",", "alias", ",", "localPath", ")", "\n", "return", "nil", "\n", "}" ]
// MountAdd adds a new mount
[ "MountAdd", "adds", "a", "new", "mount" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/mount.go#L68-L109
train
gopasspw/gopass
pkg/backend/crypto/plain/backend.go
FindPublicKeys
func (m *Mocker) FindPublicKeys(ctx context.Context, keys ...string) ([]string, error) { rs := staticPrivateKeyList.Recipients() res := make([]string, 0, len(rs)) for _, r := range rs { for _, needle := range keys { if strings.HasSuffix(r, needle) { res = append(res, r) } } } return res, nil }
go
func (m *Mocker) FindPublicKeys(ctx context.Context, keys ...string) ([]string, error) { rs := staticPrivateKeyList.Recipients() res := make([]string, 0, len(rs)) for _, r := range rs { for _, needle := range keys { if strings.HasSuffix(r, needle) { res = append(res, r) } } } return res, nil }
[ "func", "(", "m", "*", "Mocker", ")", "FindPublicKeys", "(", "ctx", "context", ".", "Context", ",", "keys", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "rs", ":=", "staticPrivateKeyList", ".", "Recipients", "(", ")", "\n", "res", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "rs", ")", ")", "\n", "for", "_", ",", "r", ":=", "range", "rs", "{", "for", "_", ",", "needle", ":=", "range", "keys", "{", "if", "strings", ".", "HasSuffix", "(", "r", ",", "needle", ")", "{", "res", "=", "append", "(", "res", ",", "r", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "res", ",", "nil", "\n", "}" ]
// FindPublicKeys does nothing
[ "FindPublicKeys", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L61-L72
train
gopasspw/gopass
pkg/backend/crypto/plain/backend.go
RecipientIDs
func (m *Mocker) RecipientIDs(context.Context, []byte) ([]string, error) { return staticPrivateKeyList.Recipients(), nil }
go
func (m *Mocker) RecipientIDs(context.Context, []byte) ([]string, error) { return staticPrivateKeyList.Recipients(), nil }
[ "func", "(", "m", "*", "Mocker", ")", "RecipientIDs", "(", "context", ".", "Context", ",", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "staticPrivateKeyList", ".", "Recipients", "(", ")", ",", "nil", "\n", "}" ]
// RecipientIDs does nothing
[ "RecipientIDs", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L85-L87
train
gopasspw/gopass
pkg/backend/crypto/plain/backend.go
Encrypt
func (m *Mocker) Encrypt(ctx context.Context, content []byte, recipients []string) ([]byte, error) { return content, nil }
go
func (m *Mocker) Encrypt(ctx context.Context, content []byte, recipients []string) ([]byte, error) { return content, nil }
[ "func", "(", "m", "*", "Mocker", ")", "Encrypt", "(", "ctx", "context", ".", "Context", ",", "content", "[", "]", "byte", ",", "recipients", "[", "]", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "content", ",", "nil", "\n", "}" ]
// Encrypt writes the input to disk unaltered
[ "Encrypt", "writes", "the", "input", "to", "disk", "unaltered" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L90-L92
train
gopasspw/gopass
pkg/backend/crypto/plain/backend.go
Decrypt
func (m *Mocker) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) { return ciphertext, nil }
go
func (m *Mocker) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) { return ciphertext, nil }
[ "func", "(", "m", "*", "Mocker", ")", "Decrypt", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "ciphertext", ",", "nil", "\n", "}" ]
// Decrypt read the file from disk unaltered
[ "Decrypt", "read", "the", "file", "from", "disk", "unaltered" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L95-L97
train
gopasspw/gopass
pkg/backend/crypto/plain/backend.go
Sign
func (m *Mocker) Sign(ctx context.Context, in string, sigf string) error { buf, err := ioutil.ReadFile(in) if err != nil { return err } sum := sha256.New() _, _ = sum.Write(buf) hexsum := fmt.Sprintf("%X", sum.Sum(nil)) return ioutil.WriteFile(sigf, []byte(hexsum), 0644) }
go
func (m *Mocker) Sign(ctx context.Context, in string, sigf string) error { buf, err := ioutil.ReadFile(in) if err != nil { return err } sum := sha256.New() _, _ = sum.Write(buf) hexsum := fmt.Sprintf("%X", sum.Sum(nil)) return ioutil.WriteFile(sigf, []byte(hexsum), 0644) }
[ "func", "(", "m", "*", "Mocker", ")", "Sign", "(", "ctx", "context", ".", "Context", ",", "in", "string", ",", "sigf", "string", ")", "error", "{", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "in", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "sum", ":=", "sha256", ".", "New", "(", ")", "\n", "_", ",", "_", "=", "sum", ".", "Write", "(", "buf", ")", "\n", "hexsum", ":=", "fmt", ".", "Sprintf", "(", "\"%X\"", ",", "sum", ".", "Sum", "(", "nil", ")", ")", "\n", "return", "ioutil", ".", "WriteFile", "(", "sigf", ",", "[", "]", "byte", "(", "hexsum", ")", ",", "0644", ")", "\n", "}" ]
// Sign writes the hashsum to the given file
[ "Sign", "writes", "the", "hashsum", "to", "the", "given", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L120-L129
train