repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"kl",
",",
"err",
":=",
"crypto",
".",
"ListPrivateKeyIDs",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"kl",
"{",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
",",
"key",
",",
"crypto",
".",
"FormatKey",
"(",
"ctx",
",",
"key",
")",
")",
"\n",
"}",
"\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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"name",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"email",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"pw",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"name",
"==",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"name",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"name",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitNoName",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"email",
"==",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"email",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"email",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitNoName",
",",
"err",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"crypto",
".",
"CreatePrivateKeyBatch",
"(",
"ctx",
",",
"name",
",",
"email",
",",
"pw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"id",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"file",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"file",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"fsutil",
".",
"IsFile",
"(",
"file",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pk",
",",
"err",
":=",
"crypto",
".",
"ExportPrivateKey",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"file",
",",
"pk",
",",
"0600",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"file",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"file",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"fsutil",
".",
"IsFile",
"(",
"file",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitNotFound",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"{",
"return",
"EncryptFileStream",
"(",
"ctx",
",",
"c",
")",
"\n",
"}",
"\n\n",
"inFile",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"if",
"inFile",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"recipients",
":=",
"c",
".",
"StringSlice",
"(",
"\"",
"\"",
")",
"\n",
"outFile",
":=",
"inFile",
"+",
"\"",
"\"",
"\n\n",
"if",
"!",
"fsutil",
".",
"IsFile",
"(",
"inFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitNotFound",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"fsutil",
".",
"IsFile",
"(",
"outFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"plaintext",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"inFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ciphertext",
",",
"err",
":=",
"crypto",
".",
"Encrypt",
"(",
"ctx",
",",
"plaintext",
",",
"recipients",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"outFile",
",",
"ciphertext",
",",
"0600",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"{",
"return",
"DecryptFileStream",
"(",
"ctx",
",",
"c",
")",
"\n",
"}",
"\n\n",
"inFile",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"if",
"inFile",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"inFile",
",",
"\"",
"\"",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"outFile",
":=",
"strings",
".",
"TrimSuffix",
"(",
"inFile",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"!",
"fsutil",
".",
"IsFile",
"(",
"inFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitNotFound",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"fsutil",
".",
"IsFile",
"(",
"outFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ciphertext",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"inFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"plaintext",
",",
"err",
":=",
"crypto",
".",
"Decrypt",
"(",
"ctx",
",",
"ciphertext",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"outFile",
",",
"plaintext",
",",
"0600",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"inFile",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"if",
"inFile",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"recipients",
":=",
"c",
".",
"StringSlice",
"(",
"\"",
"\"",
")",
"\n\n",
"outFile",
":=",
"inFile",
"+",
"\"",
"\"",
"\n\n",
"if",
"!",
"fsutil",
".",
"IsFile",
"(",
"inFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitNotFound",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"fsutil",
".",
"IsFile",
"(",
"outFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"plaintext",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"inFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"plaintext",
".",
"Close",
"(",
")",
"}",
"(",
")",
"\n\n",
"ciphertext",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"outFile",
",",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_WRONLY",
",",
"0600",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"ciphertext",
".",
"Close",
"(",
")",
"}",
"(",
")",
"\n\n",
"if",
"err",
":=",
"crypto",
".",
"EncryptStream",
"(",
"ctx",
",",
"plaintext",
",",
"recipients",
",",
"ciphertext",
")",
";",
"err",
"!=",
"nil",
"{",
"_",
"=",
"os",
".",
"Remove",
"(",
"outFile",
")",
"\n",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"inFile",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"if",
"inFile",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"inFile",
",",
"\"",
"\"",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"outFile",
":=",
"strings",
".",
"TrimSuffix",
"(",
"inFile",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"!",
"fsutil",
".",
"IsFile",
"(",
"inFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitNotFound",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"fsutil",
".",
"IsFile",
"(",
"outFile",
")",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ciphertext",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"inFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"ciphertext",
".",
"Close",
"(",
")",
"}",
"(",
")",
"\n\n",
"plaintext",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"outFile",
",",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_WRONLY",
",",
"0600",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"plaintext",
".",
"Close",
"(",
")",
"}",
"(",
")",
"\n\n",
"if",
"err",
":=",
"crypto",
".",
"DecryptStream",
"(",
"ctx",
",",
"ciphertext",
",",
"plaintext",
")",
";",
"err",
"!=",
"nil",
"{",
"_",
"=",
"os",
".",
"Remove",
"(",
"outFile",
")",
"\n",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"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",
",",
"\"",
"\"",
"+",
"c",
".",
"Protocol",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"n",
"+=",
"int64",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"Host",
"!=",
"\"",
"\"",
"{",
"i",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"w",
",",
"\"",
"\"",
"+",
"c",
".",
"Host",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"n",
"+=",
"int64",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"Path",
"!=",
"\"",
"\"",
"{",
"i",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"w",
",",
"\"",
"\"",
"+",
"c",
".",
"Path",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"n",
"+=",
"int64",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"Username",
"!=",
"\"",
"\"",
"{",
"i",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"w",
",",
"\"",
"\"",
"+",
"c",
".",
"Username",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"n",
"+=",
"int64",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"Password",
"!=",
"\"",
"\"",
"{",
"i",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"w",
",",
"\"",
"\"",
"+",
"c",
".",
"Password",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"n",
"+=",
"int64",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"n",
",",
"nil",
"\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",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// try git/host/username... If username is empty, simply try git/host",
"path",
":=",
"\"",
"\"",
"+",
"fsutil",
".",
"CleanFilename",
"(",
"cred",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"fsutil",
".",
"CleanFilename",
"(",
"cred",
".",
"Username",
")",
"\n",
"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",
"\n",
"}",
"\n",
"tree",
",",
"err",
":=",
"s",
".",
"Store",
".",
"Tree",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitDecrypt",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"sub",
",",
"err",
":=",
"tree",
".",
"FindFolder",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// no entry found... this is not an error",
"return",
"nil",
"\n",
"}",
"\n",
"entries",
":=",
"sub",
".",
"List",
"(",
"0",
")",
"\n",
"if",
"len",
"(",
"entries",
")",
"!=",
"1",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"path",
"=",
"\"",
"\"",
"+",
"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",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// leave the username as is otherwise",
"cred",
".",
"Username",
"=",
"username",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"cred",
".",
"WriteTo",
"(",
"out",
".",
"Stdout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitIO",
",",
"err",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"path",
":=",
"\"",
"\"",
"+",
"fsutil",
".",
"CleanFilename",
"(",
"cred",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"fsutil",
".",
"CleanFilename",
"(",
"cred",
".",
"Username",
")",
"\n",
"// This should never really be an issue because git automatically removes invalid credentials first",
"if",
"s",
".",
"Store",
".",
"Exists",
"(",
"ctx",
",",
"path",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
"+",
"\"",
"\\\"",
"\\\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"path",
",",
"path",
",",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"secret",
":=",
"secret",
".",
"New",
"(",
"cred",
".",
"Password",
",",
"\"",
"\"",
")",
"\n",
"if",
"cred",
".",
"Username",
"!=",
"\"",
"\"",
"{",
"_",
"=",
"secret",
".",
"SetValue",
"(",
"\"",
"\"",
",",
"cred",
".",
"Username",
")",
"\n",
"}",
"\n",
"err",
"=",
"s",
".",
"Store",
".",
"Set",
"(",
"ctx",
",",
"path",
",",
"secret",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\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",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"path",
":=",
"\"",
"\"",
"+",
"fsutil",
".",
"CleanFilename",
"(",
"cred",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"fsutil",
".",
"CleanFilename",
"(",
"cred",
".",
"Username",
")",
"\n",
"err",
"=",
"s",
".",
"Store",
".",
"Delete",
"(",
"ctx",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\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",
":=",
"\"",
"\"",
"\n",
"if",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"{",
"flag",
"=",
"\"",
"\"",
"\n",
"flags",
"++",
"\n",
"}",
"\n",
"if",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"{",
"flag",
"=",
"\"",
"\"",
"\n",
"flags",
"++",
"\n",
"}",
"\n",
"if",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"{",
"flag",
"=",
"\"",
"\"",
"\n",
"flags",
"++",
"\n",
"}",
"\n",
"if",
"flags",
">=",
"2",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnsupported",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"flags",
"==",
"0",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"flag",
",",
"\"",
"\"",
",",
"`\"!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",
"[",
"\"",
"\"",
"]",
"{",
"case",
"\"",
"\"",
":",
"ft",
"=",
"\"",
"\"",
"+",
"colBin",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"ft",
"=",
"\"",
"\"",
"+",
"colYaml",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"ca",
"[",
"i",
"]",
".",
"Fn",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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\n",
"sort",
".",
"Strings",
"(",
"in",
")",
"\n",
"for",
"i",
",",
"hash",
":=",
"range",
"in",
"{",
"in",
"[",
"i",
"]",
"=",
"strings",
".",
"ToUpper",
"(",
"hash",
")",
"\n",
"}",
"\n\n",
"out",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"in",
")",
")",
"\n",
"results",
":=",
"make",
"(",
"chan",
"string",
",",
"len",
"(",
"in",
")",
")",
"\n",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"len",
"(",
"s",
".",
"dumps",
")",
")",
"\n\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\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",
"(",
"\"",
"\"",
",",
"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",
",",
"\"",
"\"",
",",
"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",
")",
"{",
"// if it's no URL build file URL and parse that",
"nu",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"us",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"nu",
",",
"err",
"=",
"url",
".",
"Parse",
"(",
"\"",
"\"",
"+",
"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",
"==",
"\"",
"\"",
"{",
"// 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",
",",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
",",
"name",
",",
"revision",
")",
"\n",
"}",
"\n\n",
"content",
",",
"err",
":=",
"s",
".",
"crypto",
".",
"Decrypt",
"(",
"ctx",
",",
"ciphertext",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"store",
".",
"ErrDecrypt",
"\n",
"}",
"\n\n",
"sec",
",",
"err",
":=",
"secret",
".",
"Parse",
"(",
"content",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"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",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"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",
"(",
"\"",
"\"",
",",
"k",
".",
"KeyType",
",",
"k",
".",
"KeyLength",
",",
"fp",
",",
"k",
".",
"CreationDate",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"!",
"k",
".",
"ExpirationDate",
".",
"IsZero",
"(",
")",
"{",
"out",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
".",
"ExpirationDate",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"out",
"+=",
"\"",
"\\n",
"\"",
"+",
"k",
".",
"Fingerprint",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"k",
".",
"Identities",
"{",
"out",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
"+",
"id",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"out",
"\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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"{",
"ctx",
"=",
"backend",
".",
"WithCryptoBackendString",
"(",
"ctx",
",",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"IsSet",
"(",
"\"",
"\"",
")",
"{",
"ctx",
"=",
"backend",
".",
"WithRCSBackendString",
"(",
"ctx",
",",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"Args",
"(",
")",
")",
"<",
"1",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"repo",
":=",
"c",
".",
"Args",
"(",
")",
"[",
"0",
"]",
"\n",
"mount",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"c",
".",
"Args",
"(",
")",
")",
">",
"1",
"{",
"mount",
"=",
"c",
".",
"Args",
"(",
")",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"path",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n\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",
",",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"privKey",
":=",
"x",
".",
"secring",
".",
"Get",
"(",
"privKeyIDs",
"[",
"0",
"]",
")",
"\n\n",
"// generate session / encryption key",
"var",
"sessionKey",
"[",
"32",
"]",
"byte",
"\n",
"if",
"_",
",",
"err",
":=",
"crypto_rand",
".",
"Read",
"(",
"sessionKey",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// encrypt the session key per recipient",
"header",
",",
"err",
":=",
"x",
".",
"encryptHeader",
"(",
"ctx",
",",
"privKey",
",",
"sessionKey",
"[",
":",
"]",
",",
"recipients",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// create the encoder",
"enc",
":=",
"binary",
".",
"NewEncoder",
"(",
"ciphertext",
")",
"\n\n",
"// write verion",
"if",
"err",
":=",
"enc",
".",
"Encode",
"(",
"0x1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// write header",
"if",
"err",
":=",
"enc",
".",
"Encode",
"(",
"header",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// write body",
"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\n",
"// read version",
"ver",
":=",
"0",
"\n",
"if",
"err",
":=",
"dec",
".",
"Decode",
"(",
"&",
"ver",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"ver",
"!=",
"0x1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// read header",
"header",
":=",
"&",
"xcpb",
".",
"Header",
"{",
"}",
"\n",
"if",
"err",
":=",
"dec",
".",
"Decode",
"(",
"header",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// try to find a suiteable decryption key in the header",
"sk",
",",
"err",
":=",
"x",
".",
"decryptSessionKey",
"(",
"ctx",
",",
"header",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"secretKey",
"[",
"32",
"]",
"byte",
"\n",
"copy",
"(",
"secretKey",
"[",
":",
"]",
",",
"sk",
")",
"\n\n",
"// read body",
"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",
",",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"p",
":=",
"s",
".",
"passfile",
"(",
"name",
")",
"\n\n",
"if",
"s",
".",
"IsDir",
"(",
"ctx",
",",
"name",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"recipients",
",",
"err",
":=",
"s",
".",
"useableKeys",
"(",
"ctx",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"p",
")",
"\n",
"}",
"\n\n",
"// confirm recipients",
"newRecipients",
",",
"err",
":=",
"GetRecipientFunc",
"(",
"ctx",
")",
"(",
"ctx",
",",
"name",
",",
"recipients",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"recipients",
"=",
"newRecipients",
"\n\n",
"// make sure the encryptor can decrypt later",
"recipients",
"=",
"s",
".",
"ensureOurKeyID",
"(",
"ctx",
",",
"recipients",
")",
"\n\n",
"buf",
",",
"err",
":=",
"sec",
".",
"Bytes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ciphertext",
",",
"err",
":=",
"s",
".",
"crypto",
".",
"Encrypt",
"(",
"ctx",
",",
"buf",
",",
"recipients",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"store",
".",
"ErrEncrypt",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"storage",
".",
"Set",
"(",
"ctx",
",",
"p",
",",
"ciphertext",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// 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",
",",
"\"",
"\"",
",",
"p",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\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",
",",
"\"",
"\"",
",",
"p",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctxutil",
".",
"IsGitCommit",
"(",
"ctx",
")",
"{",
"return",
"nil",
"\n",
"}",
"\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",
"{",
"// recursive move?",
"if",
"s",
".",
"IsDir",
"(",
"ctx",
",",
"from",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"content",
",",
"err",
":=",
"s",
".",
"Get",
"(",
"ctx",
",",
"from",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"from",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"Set",
"(",
"WithReason",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"from",
",",
"to",
")",
")",
",",
"to",
",",
"content",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"to",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"Delete",
"(",
"ctx",
",",
"from",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"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\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\n",
"if",
"!",
"ctxutil",
".",
"IsGitCommit",
"(",
"ctx",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"rcs",
".",
"Commit",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"Cause",
"(",
"err",
")",
"==",
"store",
".",
"ErrGitNotInit",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// abort if auto sync is not set",
"if",
"!",
"IsAutoSync",
"(",
"ctx",
")",
"{",
"return",
"nil",
"\n",
"}",
"\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",
",",
"\"",
"\"",
")",
"\n",
"}",
"\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",
"// 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\nKey-Type: RSA\nKey-Length: 2048\nSubkey-Type: RSA\nSubkey-Length: 2048\nExpire-Date: 0\n`",
")",
"\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
"+",
"name",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
"+",
"email",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
"+",
"passphrase",
"+",
"\"",
"\\n",
"\"",
")",
"\n\n",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"g",
".",
"binary",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdin",
"=",
"bytes",
".",
"NewReader",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"nil",
"\n",
"cmd",
".",
"Stderr",
"=",
"nil",
"\n\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"}",
"\n",
"g",
".",
"privKeys",
"=",
"nil",
"\n",
"g",
".",
"pubKeys",
"=",
"nil",
"\n",
"return",
"nil",
"\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",
"{",
"\"",
"\"",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"g",
".",
"binary",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdin",
"=",
"os",
".",
"Stdin",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// set commit identity",
"if",
"err",
":=",
"g",
".",
"ConfigSet",
"(",
"ctx",
",",
"\"",
"\"",
",",
"userName",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"ConfigSet",
"(",
"ctx",
",",
"\"",
"\"",
",",
"userEmail",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// ensure sane git config",
"if",
"err",
":=",
"g",
".",
"fixConfig",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"g",
".",
"path",
",",
"\"",
"\"",
")",
",",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
",",
"fileMode",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"Add",
"(",
"ctx",
",",
"g",
".",
"path",
"+",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"out",
".",
"Yellow",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"Commit",
"(",
"ctx",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"out",
".",
"Yellow",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\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",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"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\n",
"buf",
":=",
"&",
"strings",
".",
"Builder",
"{",
"}",
"\n\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"key",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"g",
".",
"path",
"\n",
"cmd",
".",
"Stdout",
"=",
"buf",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\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\n",
"buf",
":=",
"&",
"strings",
".",
"Builder",
"{",
"}",
"\n\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"g",
".",
"path",
"\n",
"cmd",
".",
"Stdout",
"=",
"buf",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"buf",
".",
"String",
"(",
")",
",",
"\"",
"\\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",
"return",
"kv",
",",
"nil",
"\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",
",",
"\"",
"\"",
")",
"\n\n",
"tree",
",",
"err",
":=",
"s",
".",
"Store",
".",
"RecipientsTree",
"(",
"ctx",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitList",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\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\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",
"(",
"\"",
"\"",
")",
"\n",
"force",
":=",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"\n",
"added",
":=",
"0",
"\n\n",
"// select store",
"if",
"store",
"==",
"\"",
"\"",
"{",
"store",
"=",
"cui",
".",
"AskForStore",
"(",
"ctx",
",",
"s",
".",
"Store",
")",
"\n",
"}",
"\n\n",
"crypto",
":=",
"s",
".",
"Store",
".",
"Crypto",
"(",
"ctx",
",",
"store",
")",
"\n\n",
"// select recipient",
"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\n",
"for",
"_",
",",
"r",
":=",
"range",
"recipients",
"{",
"keys",
",",
"err",
":=",
"crypto",
".",
"FindPublicKeys",
"(",
"ctx",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
",",
"r",
",",
"err",
")",
"\n",
"if",
"!",
"force",
"{",
"continue",
"\n",
"}",
"\n",
"keys",
"=",
"[",
"]",
"string",
"{",
"r",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"keys",
")",
"<",
"1",
"&&",
"!",
"force",
"{",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
",",
"r",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
",",
"r",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"recp",
":=",
"r",
"\n",
"if",
"len",
"(",
"keys",
")",
">",
"0",
"{",
"recp",
"=",
"crypto",
".",
"Fingerprint",
"(",
"ctx",
",",
"keys",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"termio",
".",
"AskForConfirmation",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"crypto",
".",
"FormatKey",
"(",
"ctx",
",",
"recp",
")",
",",
"store",
")",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"Store",
".",
"AddRecipient",
"(",
"ctxutil",
".",
"WithNoConfirm",
"(",
"ctx",
",",
"true",
")",
",",
"store",
",",
"recp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitRecipients",
",",
"err",
",",
"\"",
"\"",
",",
"r",
",",
"err",
")",
"\n",
"}",
"\n",
"added",
"++",
"\n",
"}",
"\n",
"if",
"added",
"<",
"1",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\\n",
"\"",
",",
"added",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\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",
"(",
"\"",
"\"",
")",
"\n",
"force",
":=",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"\n",
"removed",
":=",
"0",
"\n\n",
"// select store",
"if",
"store",
"==",
"\"",
"\"",
"{",
"store",
"=",
"cui",
".",
"AskForStore",
"(",
"ctx",
",",
"s",
".",
"Store",
")",
"\n",
"}",
"\n\n",
"crypto",
":=",
"s",
".",
"Store",
".",
"Crypto",
"(",
"ctx",
",",
"store",
")",
"\n\n",
"// select recipient",
"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\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",
"(",
"\"",
"\"",
",",
"r",
")",
")",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"keys",
",",
"err",
":=",
"crypto",
".",
"FindPublicKeys",
"(",
"ctx",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
",",
"r",
",",
"err",
")",
"\n",
"if",
"!",
"force",
"{",
"continue",
"\n",
"}",
"\n",
"keys",
"=",
"[",
"]",
"string",
"{",
"r",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"keys",
")",
"<",
"1",
"&&",
"!",
"force",
"{",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
",",
"r",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
",",
"r",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"recp",
":=",
"r",
"\n",
"if",
"len",
"(",
"keys",
")",
">",
"0",
"{",
"recp",
"=",
"crypto",
".",
"Fingerprint",
"(",
"ctx",
",",
"keys",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"Store",
".",
"RemoveRecipient",
"(",
"ctxutil",
".",
"WithNoConfirm",
"(",
"ctx",
",",
"true",
")",
",",
"store",
",",
"recp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitRecipients",
",",
"err",
",",
"\"",
"\"",
",",
"recp",
",",
"err",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"stdout",
",",
"removalWarning",
",",
"r",
")",
"\n",
"removed",
"++",
"\n",
"}",
"\n",
"if",
"removed",
"<",
"1",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\\n",
"\"",
",",
"removed",
")",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\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\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",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"out",
".",
"Cyan",
"(",
"ctx",
",",
"\"",
"\"",
",",
"alias",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"recp",
"{",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
",",
"subs",
".",
"Crypto",
"(",
")",
".",
"FormatKey",
"(",
"ctx",
",",
"r",
")",
")",
"\n",
"}",
"\n",
"if",
"!",
"termio",
".",
"AskForConfirmation",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"alias",
")",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"subs",
".",
"SetRecipients",
"(",
"ctx",
",",
"recp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"changed",
"++",
"\n",
"}",
"\n\n",
"if",
"changed",
">",
"0",
"{",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
",",
"changed",
")",
"\n",
"}",
"else",
"{",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\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",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"qrf",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"clip",
":=",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"\n\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",
")",
"{",
"// unmarshal the protobuf message, the header and body are still encrypted",
"// afterwards (parts of the header are plaintext!)",
"msg",
":=",
"&",
"xcpb",
".",
"Message",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// try to find a suiteable decryption key in the header",
"sk",
",",
"err",
":=",
"x",
".",
"decryptSessionKey",
"(",
"ctx",
",",
"msg",
".",
"Header",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"secretKey",
"[",
"32",
"]",
"byte",
"\n",
"copy",
"(",
"secretKey",
"[",
":",
"]",
",",
"sk",
")",
"\n\n",
"plainBuf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n\n",
"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",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"nonce",
"[",
":",
"]",
",",
"uint64",
"(",
"i",
")",
")",
"\n\n",
"// decrypt and verify the ciphertext",
"//plaintext, err := cp.Open(nil, nonce, chunk.Body, nil)",
"plaintext",
",",
"ok",
":=",
"secretbox",
".",
"Open",
"(",
"nil",
",",
"chunk",
".",
"Body",
",",
"&",
"nonce",
",",
"&",
"secretKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"plainBuf",
".",
"Write",
"(",
"plaintext",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"msg",
".",
"Compressed",
"{",
"return",
"plainBuf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxUnlockAttempts",
";",
"i",
"++",
"{",
"// retry asking for key in case it's wrong",
"passphrase",
",",
"err",
":=",
"x",
".",
"client",
".",
"Passphrase",
"(",
"ctx",
",",
"fp",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"recp",
".",
"Fingerprint",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"recp",
".",
"Decrypt",
"(",
"passphrase",
")",
";",
"err",
"==",
"nil",
"{",
"// passphrase is correct, the key should now be decrypted",
"return",
"nil",
"\n",
"}",
"\n\n",
"// decryption failed, clear cache and wait a moment before trying again",
"if",
"err",
":=",
"x",
".",
"client",
".",
"Remove",
"(",
"ctx",
",",
"fp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"10",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
")",
"{",
"// find a suiteable decryption key, i.e. a recipient entry which was encrypted",
"// for one of our private keys",
"recp",
",",
"err",
":=",
"x",
".",
"findDecryptionKey",
"(",
"hdr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// 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",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"hdr",
".",
"Sender",
")",
"\n",
"}",
"\n\n",
"// unlock recipient key",
"if",
"err",
":=",
"x",
".",
"decryptPrivateKey",
"(",
"ctx",
",",
"recp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// this is the per recipient ciphertext, we need to decrypt it to extract",
"// the session key",
"ciphertext",
":=",
"hdr",
".",
"Recipients",
"[",
"recp",
".",
"Fingerprint",
"(",
")",
"]",
"\n\n",
"// since box works with byte arrays (or: pointers thereof) we need to copy",
"// the slice to fixed arrays",
"var",
"nonce",
"[",
"24",
"]",
"byte",
"\n",
"copy",
"(",
"nonce",
"[",
":",
"]",
",",
"ciphertext",
"[",
":",
"24",
"]",
")",
"\n\n",
"var",
"privKey",
"[",
"32",
"]",
"byte",
"\n",
"pk",
":=",
"recp",
".",
"PrivateKey",
"(",
")",
"\n",
"copy",
"(",
"privKey",
"[",
":",
"]",
",",
"pk",
"[",
":",
"]",
")",
"\n\n",
"// 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",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\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",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"Store",
".",
"RemoveMount",
"(",
"ctx",
",",
"c",
".",
"Args",
"(",
")",
"[",
"0",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"out",
".",
"Error",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"cfg",
".",
"Save",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitConfig",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
",",
"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",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"root",
":=",
"simple",
".",
"New",
"(",
"color",
".",
"GreenString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"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",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\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",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"if",
"localPath",
"==",
"\"",
"\"",
"{",
"localPath",
"=",
"config",
".",
"PwStoreDir",
"(",
"alias",
")",
"\n",
"}",
"\n\n",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"1",
")",
"\n",
"if",
"k",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
";",
"k",
"!=",
"\"",
"\"",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"Store",
".",
"Exists",
"(",
"ctx",
",",
"alias",
")",
"{",
"out",
".",
"Yellow",
"(",
"ctx",
",",
"\"",
"\"",
",",
"alias",
")",
"\n",
"}",
"\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",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"case",
"root",
".",
"NotInitializedError",
":",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
",",
"e",
".",
"Alias",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"init",
"(",
"ctx",
",",
"e",
".",
"Alias",
"(",
")",
",",
"e",
".",
"Path",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"e",
".",
"Alias",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitMount",
",",
"err",
",",
"\"",
"\"",
",",
"alias",
",",
"localPath",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"cfg",
".",
"Save",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitConfig",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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 |
gopasspw/gopass | pkg/backend/crypto/plain/backend.go | Verify | func (m *Mocker) Verify(ctx context.Context, sigf string, in string) error {
sigb, err := ioutil.ReadFile(sigf)
if err != nil {
return err
}
buf, err := ioutil.ReadFile(in)
if err != nil {
return err
}
sum := sha256.New()
_, _ = sum.Write(buf)
hexsum := fmt.Sprintf("%X", sum.Sum(nil))
if string(sigb) != hexsum {
return fmt.Errorf("hashsum mismatch")
}
return nil
} | go | func (m *Mocker) Verify(ctx context.Context, sigf string, in string) error {
sigb, err := ioutil.ReadFile(sigf)
if err != nil {
return err
}
buf, err := ioutil.ReadFile(in)
if err != nil {
return err
}
sum := sha256.New()
_, _ = sum.Write(buf)
hexsum := fmt.Sprintf("%X", sum.Sum(nil))
if string(sigb) != hexsum {
return fmt.Errorf("hashsum mismatch")
}
return nil
} | [
"func",
"(",
"m",
"*",
"Mocker",
")",
"Verify",
"(",
"ctx",
"context",
".",
"Context",
",",
"sigf",
"string",
",",
"in",
"string",
")",
"error",
"{",
"sigb",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"sigf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sum",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"_",
",",
"_",
"=",
"sum",
".",
"Write",
"(",
"buf",
")",
"\n",
"hexsum",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sum",
".",
"Sum",
"(",
"nil",
")",
")",
"\n\n",
"if",
"string",
"(",
"sigb",
")",
"!=",
"hexsum",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Verify does a pseudo-verification | [
"Verify",
"does",
"a",
"pseudo",
"-",
"verification"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L132-L151 | train |
gopasspw/gopass | pkg/backend/crypto/plain/backend.go | ReadNamesFromKey | func (m *Mocker) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) {
return []string{"unsupported"}, nil
} | go | func (m *Mocker) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) {
return []string{"unsupported"}, nil
} | [
"func",
"(",
"m",
"*",
"Mocker",
")",
"ReadNamesFromKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"buf",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"return",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
"\n",
"}"
] | // ReadNamesFromKey does nothing | [
"ReadNamesFromKey",
"does",
"nothing"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L204-L206 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/loader.go | Clone | func (l loader) Clone(ctx context.Context, repo, path string) (backend.RCS, error) {
return Clone(ctx, repo, path)
} | go | func (l loader) Clone(ctx context.Context, repo, path string) (backend.RCS, error) {
return Clone(ctx, repo, path)
} | [
"func",
"(",
"l",
"loader",
")",
"Clone",
"(",
"ctx",
"context",
".",
"Context",
",",
"repo",
",",
"path",
"string",
")",
"(",
"backend",
".",
"RCS",
",",
"error",
")",
"{",
"return",
"Clone",
"(",
"ctx",
",",
"repo",
",",
"path",
")",
"\n",
"}"
] | // Clone implements backend.RCSLoader | [
"Clone",
"implements",
"backend",
".",
"RCSLoader"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/loader.go#L27-L29 | train |
gopasspw/gopass | pkg/backend/crypto/gpg/cli/import.go | ImportPublicKey | func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error {
if len(buf) < 1 {
return errors.Errorf("empty input")
}
args := append(g.args, "--import")
cmd := exec.CommandContext(ctx, g.binary, args...)
cmd.Stdin = bytes.NewReader(buf)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
out.Debug(ctx, "gpg.ImportPublicKey: %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)
}
// clear key cache
g.privKeys = nil
g.pubKeys = nil
return nil
} | go | func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error {
if len(buf) < 1 {
return errors.Errorf("empty input")
}
args := append(g.args, "--import")
cmd := exec.CommandContext(ctx, g.binary, args...)
cmd.Stdin = bytes.NewReader(buf)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
out.Debug(ctx, "gpg.ImportPublicKey: %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)
}
// clear key cache
g.privKeys = nil
g.pubKeys = nil
return nil
} | [
"func",
"(",
"g",
"*",
"GPG",
")",
"ImportPublicKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"1",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"args",
":=",
"append",
"(",
"g",
".",
"args",
",",
"\"",
"\"",
")",
"\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"g",
".",
"binary",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdin",
"=",
"bytes",
".",
"NewReader",
"(",
"buf",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"}",
"\n\n",
"// clear key cache",
"g",
".",
"privKeys",
"=",
"nil",
"\n",
"g",
".",
"pubKeys",
"=",
"nil",
"\n",
"return",
"nil",
"\n",
"}"
] | // ImportPublicKey will import a key from the given location | [
"ImportPublicKey",
"will",
"import",
"a",
"key",
"from",
"the",
"given",
"location"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/import.go#L15-L35 | train |
gopasspw/gopass | pkg/action/binary/copy.go | Copy | func Copy(ctx context.Context, c *cli.Context, store storer) error {
from := c.Args().Get(0)
to := c.Args().Get(1)
// argument checking is in s.binaryCopy
if err := binaryCopy(ctx, c, from, to, false, store); err != nil {
return action.ExitError(ctx, action.ExitUnknown, err, "%s", err)
}
return nil
} | go | func Copy(ctx context.Context, c *cli.Context, store storer) error {
from := c.Args().Get(0)
to := c.Args().Get(1)
// argument checking is in s.binaryCopy
if err := binaryCopy(ctx, c, from, to, false, store); err != nil {
return action.ExitError(ctx, action.ExitUnknown, err, "%s", err)
}
return nil
} | [
"func",
"Copy",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
",",
"store",
"storer",
")",
"error",
"{",
"from",
":=",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"0",
")",
"\n",
"to",
":=",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"1",
")",
"\n\n",
"// argument checking is in s.binaryCopy",
"if",
"err",
":=",
"binaryCopy",
"(",
"ctx",
",",
"c",
",",
"from",
",",
"to",
",",
"false",
",",
"store",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Copy copies either from the filesystem to the store or from the store
// to the filesystem | [
"Copy",
"copies",
"either",
"from",
"the",
"filesystem",
"to",
"the",
"store",
"or",
"from",
"the",
"store",
"to",
"the",
"filesystem"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/binary/copy.go#L22-L31 | train |
gopasspw/gopass | pkg/action/fsck.go | Fsck | func (s *Action) Fsck(ctx context.Context, c *cli.Context) error {
out.Print(ctx, "Checking store integrity ...")
// make sure config is in the right place
// we may have loaded it from one of the fallback locations
if err := s.cfg.Save(); err != nil {
return ExitError(ctx, ExitConfig, err, "failed to save config: %s", err)
}
// clean up any previous config locations
oldCfg := filepath.Join(config.Homedir(), ".gopass.yml")
if fsutil.IsFile(oldCfg) {
if err := os.Remove(oldCfg); err != nil {
out.Error(ctx, "Failed to remove old gopass config %s: %s", oldCfg, err)
}
}
// display progress bar
t, err := s.Store.Tree(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to list stores: %s", err)
}
pwList := t.List(0)
bar := &goprogressbar.ProgressBar{
Total: int64(len(pwList) * 2),
Width: 120,
}
if out.IsHidden(ctx) {
old := goprogressbar.Stdout
goprogressbar.Stdout = ioutil.Discard
defer func() {
goprogressbar.Stdout = old
}()
}
ctx = ctxutil.WithProgressCallback(ctx, func() {
bar.Current++
bar.Text = fmt.Sprintf("%d of %d objects checked", bar.Current, bar.Total)
bar.LazyPrint()
})
ctx = out.AddPrefix(ctx, "\n")
// the main work in done by the sub stores
if err := s.Store.Fsck(ctx, c.Args().Get(0)); err != nil {
return ExitError(ctx, ExitFsck, err, "fsck found errors: %s", err)
}
return nil
} | go | func (s *Action) Fsck(ctx context.Context, c *cli.Context) error {
out.Print(ctx, "Checking store integrity ...")
// make sure config is in the right place
// we may have loaded it from one of the fallback locations
if err := s.cfg.Save(); err != nil {
return ExitError(ctx, ExitConfig, err, "failed to save config: %s", err)
}
// clean up any previous config locations
oldCfg := filepath.Join(config.Homedir(), ".gopass.yml")
if fsutil.IsFile(oldCfg) {
if err := os.Remove(oldCfg); err != nil {
out.Error(ctx, "Failed to remove old gopass config %s: %s", oldCfg, err)
}
}
// display progress bar
t, err := s.Store.Tree(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to list stores: %s", err)
}
pwList := t.List(0)
bar := &goprogressbar.ProgressBar{
Total: int64(len(pwList) * 2),
Width: 120,
}
if out.IsHidden(ctx) {
old := goprogressbar.Stdout
goprogressbar.Stdout = ioutil.Discard
defer func() {
goprogressbar.Stdout = old
}()
}
ctx = ctxutil.WithProgressCallback(ctx, func() {
bar.Current++
bar.Text = fmt.Sprintf("%d of %d objects checked", bar.Current, bar.Total)
bar.LazyPrint()
})
ctx = out.AddPrefix(ctx, "\n")
// the main work in done by the sub stores
if err := s.Store.Fsck(ctx, c.Args().Get(0)); err != nil {
return ExitError(ctx, ExitFsck, err, "fsck found errors: %s", err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"Fsck",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"// make sure config is in the right place",
"// we may have loaded it from one of the fallback locations",
"if",
"err",
":=",
"s",
".",
"cfg",
".",
"Save",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitConfig",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// clean up any previous config locations",
"oldCfg",
":=",
"filepath",
".",
"Join",
"(",
"config",
".",
"Homedir",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"fsutil",
".",
"IsFile",
"(",
"oldCfg",
")",
"{",
"if",
"err",
":=",
"os",
".",
"Remove",
"(",
"oldCfg",
")",
";",
"err",
"!=",
"nil",
"{",
"out",
".",
"Error",
"(",
"ctx",
",",
"\"",
"\"",
",",
"oldCfg",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// display progress bar",
"t",
",",
"err",
":=",
"s",
".",
"Store",
".",
"Tree",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"pwList",
":=",
"t",
".",
"List",
"(",
"0",
")",
"\n\n",
"bar",
":=",
"&",
"goprogressbar",
".",
"ProgressBar",
"{",
"Total",
":",
"int64",
"(",
"len",
"(",
"pwList",
")",
"*",
"2",
")",
",",
"Width",
":",
"120",
",",
"}",
"\n",
"if",
"out",
".",
"IsHidden",
"(",
"ctx",
")",
"{",
"old",
":=",
"goprogressbar",
".",
"Stdout",
"\n",
"goprogressbar",
".",
"Stdout",
"=",
"ioutil",
".",
"Discard",
"\n",
"defer",
"func",
"(",
")",
"{",
"goprogressbar",
".",
"Stdout",
"=",
"old",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"ctx",
"=",
"ctxutil",
".",
"WithProgressCallback",
"(",
"ctx",
",",
"func",
"(",
")",
"{",
"bar",
".",
"Current",
"++",
"\n",
"bar",
".",
"Text",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"bar",
".",
"Current",
",",
"bar",
".",
"Total",
")",
"\n",
"bar",
".",
"LazyPrint",
"(",
")",
"\n",
"}",
")",
"\n",
"ctx",
"=",
"out",
".",
"AddPrefix",
"(",
"ctx",
",",
"\"",
"\\n",
"\"",
")",
"\n\n",
"// the main work in done by the sub stores",
"if",
"err",
":=",
"s",
".",
"Store",
".",
"Fsck",
"(",
"ctx",
",",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"0",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitFsck",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Fsck checks the store integrity | [
"Fsck",
"checks",
"the",
"store",
"integrity"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/fsck.go#L20-L68 | train |
gopasspw/gopass | pkg/notify/notify_others.go | Notify | func Notify(ctx context.Context, subj, msg string) error {
return errors.Errorf("GOOS %s not yet supported", runtime.GOOS)
} | go | func Notify(ctx context.Context, subj, msg string) error {
return errors.Errorf("GOOS %s not yet supported", runtime.GOOS)
} | [
"func",
"Notify",
"(",
"ctx",
"context",
".",
"Context",
",",
"subj",
",",
"msg",
"string",
")",
"error",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"runtime",
".",
"GOOS",
")",
"\n",
"}"
] | // Notify is not yet implemented on this platform | [
"Notify",
"is",
"not",
"yet",
"implemented",
"on",
"this",
"platform"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/notify/notify_others.go#L13-L15 | train |
gopasspw/gopass | pkg/backend/crypto/gpg/cli/export.go | ExportPublicKey | func (g *GPG) ExportPublicKey(ctx context.Context, id string) ([]byte, error) {
if id == "" {
return nil, errors.Errorf("id is empty")
}
args := append(g.args, "--armor", "--export", id)
cmd := exec.CommandContext(ctx, g.binary, args...)
out.Debug(ctx, "gpg.ExportPublicKey: %s %+v", cmd.Path, cmd.Args)
out, err := cmd.Output()
if err != nil {
return nil, errors.Wrapf(err, "failed to run command '%s %+v'", cmd.Path, cmd.Args)
}
if len(out) < 1 {
return nil, errors.Errorf("Key not found")
}
return out, nil
} | go | func (g *GPG) ExportPublicKey(ctx context.Context, id string) ([]byte, error) {
if id == "" {
return nil, errors.Errorf("id is empty")
}
args := append(g.args, "--armor", "--export", id)
cmd := exec.CommandContext(ctx, g.binary, args...)
out.Debug(ctx, "gpg.ExportPublicKey: %s %+v", cmd.Path, cmd.Args)
out, err := cmd.Output()
if err != nil {
return nil, errors.Wrapf(err, "failed to run command '%s %+v'", cmd.Path, cmd.Args)
}
if len(out) < 1 {
return nil, errors.Errorf("Key not found")
}
return out, nil
} | [
"func",
"(",
"g",
"*",
"GPG",
")",
"ExportPublicKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"args",
":=",
"append",
"(",
"g",
".",
"args",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"id",
")",
"\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"g",
".",
"binary",
",",
"args",
"...",
")",
"\n\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"Output",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"cmd",
".",
"Args",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"out",
")",
"<",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // ExportPublicKey will export the named public key to the location given | [
"ExportPublicKey",
"will",
"export",
"the",
"named",
"public",
"key",
"to",
"the",
"location",
"given"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/export.go#L13-L32 | train |
gopasspw/gopass | pkg/backend/crypto/gpg/cli/utils.go | parseTS | func parseTS(str string) time.Time {
t := time.Time{}
if sec, err := strconv.ParseInt(str, 10, 64); err == nil {
t = time.Unix(sec, 0)
}
return t
} | go | func parseTS(str string) time.Time {
t := time.Time{}
if sec, err := strconv.ParseInt(str, 10, 64); err == nil {
t = time.Unix(sec, 0)
}
return t
} | [
"func",
"parseTS",
"(",
"str",
"string",
")",
"time",
".",
"Time",
"{",
"t",
":=",
"time",
".",
"Time",
"{",
"}",
"\n\n",
"if",
"sec",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"str",
",",
"10",
",",
"64",
")",
";",
"err",
"==",
"nil",
"{",
"t",
"=",
"time",
".",
"Unix",
"(",
"sec",
",",
"0",
")",
"\n",
"}",
"\n\n",
"return",
"t",
"\n",
"}"
] | // parseTS parses the passed string as an Epoch int and returns
// the time struct or the zero time struct | [
"parseTS",
"parses",
"the",
"passed",
"string",
"as",
"an",
"Epoch",
"int",
"and",
"returns",
"the",
"time",
"struct",
"or",
"the",
"zero",
"time",
"struct"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/utils.go#L12-L20 | train |
gopasspw/gopass | pkg/backend/crypto/gpg/cli/utils.go | parseInt | func parseInt(str string) int {
i := 0
if iv, err := strconv.ParseInt(str, 10, 32); err == nil {
i = int(iv)
}
return i
} | go | func parseInt(str string) int {
i := 0
if iv, err := strconv.ParseInt(str, 10, 32); err == nil {
i = int(iv)
}
return i
} | [
"func",
"parseInt",
"(",
"str",
"string",
")",
"int",
"{",
"i",
":=",
"0",
"\n\n",
"if",
"iv",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"str",
",",
"10",
",",
"32",
")",
";",
"err",
"==",
"nil",
"{",
"i",
"=",
"int",
"(",
"iv",
")",
"\n",
"}",
"\n\n",
"return",
"i",
"\n",
"}"
] | // parseInt parses the passed string as an int and returns it
// or 0 on errors | [
"parseInt",
"parses",
"the",
"passed",
"string",
"as",
"an",
"int",
"and",
"returns",
"it",
"or",
"0",
"on",
"errors"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/utils.go#L24-L32 | train |
gopasspw/gopass | pkg/backend/crypto/gpg/cli/utils.go | GPGOpts | func GPGOpts() []string {
for _, en := range []string{"GOPASS_GPG_OPTS", "PASSWORD_STORE_GPG_OPTS"} {
if opts := os.Getenv(en); opts != "" {
return strings.Fields(opts)
}
}
return nil
} | go | func GPGOpts() []string {
for _, en := range []string{"GOPASS_GPG_OPTS", "PASSWORD_STORE_GPG_OPTS"} {
if opts := os.Getenv(en); opts != "" {
return strings.Fields(opts)
}
}
return nil
} | [
"func",
"GPGOpts",
"(",
")",
"[",
"]",
"string",
"{",
"for",
"_",
",",
"en",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"{",
"if",
"opts",
":=",
"os",
".",
"Getenv",
"(",
"en",
")",
";",
"opts",
"!=",
"\"",
"\"",
"{",
"return",
"strings",
".",
"Fields",
"(",
"opts",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // GPGOpts parses extra GPG options from the environment | [
"GPGOpts",
"parses",
"extra",
"GPG",
"options",
"from",
"the",
"environment"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/utils.go#L48-L55 | train |
gopasspw/gopass | pkg/store/vault/store.go | Exists | func (s *Store) Exists(ctx context.Context, name string) bool {
_, err := s.Get(ctx, name)
return err == nil
} | go | func (s *Store) Exists(ctx context.Context, name string) bool {
_, err := s.Get(ctx, name)
return err == nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Exists",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"s",
".",
"Get",
"(",
"ctx",
",",
"name",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // Exists checks if a given secret exists | [
"Exists",
"checks",
"if",
"a",
"given",
"secret",
"exists"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L195-L198 | train |
gopasspw/gopass | pkg/store/vault/store.go | Get | func (s *Store) Get(ctx context.Context, name string) (store.Secret, error) {
key := path.Join(s.path, name)
out.Debug(ctx, "Get(%s) %s", name, key)
sec, err := s.api.Logical().Read(key)
if err != nil {
return nil, err
}
if sec == nil || sec.Data == nil {
return nil, fmt.Errorf("not found")
}
return &Secret{d: sec.Data}, nil
} | go | func (s *Store) Get(ctx context.Context, name string) (store.Secret, error) {
key := path.Join(s.path, name)
out.Debug(ctx, "Get(%s) %s", name, key)
sec, err := s.api.Logical().Read(key)
if err != nil {
return nil, err
}
if sec == nil || sec.Data == nil {
return nil, fmt.Errorf("not found")
}
return &Secret{d: sec.Data}, nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"store",
".",
"Secret",
",",
"error",
")",
"{",
"key",
":=",
"path",
".",
"Join",
"(",
"s",
".",
"path",
",",
"name",
")",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"name",
",",
"key",
")",
"\n",
"sec",
",",
"err",
":=",
"s",
".",
"api",
".",
"Logical",
"(",
")",
".",
"Read",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"sec",
"==",
"nil",
"||",
"sec",
".",
"Data",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"Secret",
"{",
"d",
":",
"sec",
".",
"Data",
"}",
",",
"nil",
"\n",
"}"
] | // Get returns a secret | [
"Get",
"returns",
"a",
"secret"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L201-L212 | train |
gopasspw/gopass | pkg/store/vault/store.go | Initialized | func (s *Store) Initialized(ctx context.Context) bool {
_, err := s.List(ctx, "")
return err == nil
} | go | func (s *Store) Initialized(ctx context.Context) bool {
_, err := s.List(ctx, "")
return err == nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Initialized",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"s",
".",
"List",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // Initialized returns true if the backend can communicate with Vault | [
"Initialized",
"returns",
"true",
"if",
"the",
"backend",
"can",
"communicate",
"with",
"Vault"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L220-L223 | train |
gopasspw/gopass | pkg/store/vault/store.go | IsDir | func (s *Store) IsDir(ctx context.Context, name string) bool {
ls, err := s.List(ctx, name)
if err != nil {
return false
}
return len(ls) > 1
} | go | func (s *Store) IsDir(ctx context.Context, name string) bool {
ls, err := s.List(ctx, name)
if err != nil {
return false
}
return len(ls) > 1
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"IsDir",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"bool",
"{",
"ls",
",",
"err",
":=",
"s",
".",
"List",
"(",
"ctx",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"len",
"(",
"ls",
")",
">",
"1",
"\n",
"}"
] | // IsDir returns true if the given name is a dir | [
"IsDir",
"returns",
"true",
"if",
"the",
"given",
"name",
"is",
"a",
"dir"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L226-L232 | train |
gopasspw/gopass | pkg/store/vault/store.go | List | func (s *Store) List(ctx context.Context, prefix string) ([]string, error) {
keys, err := s.list(ctx, prefix)
if err != nil {
return nil, err
}
for i, e := range keys {
keys[i] = path.Join(s.alias, e)
}
return keys, nil
} | go | func (s *Store) List(ctx context.Context, prefix string) ([]string, error) {
keys, err := s.list(ctx, prefix)
if err != nil {
return nil, err
}
for i, e := range keys {
keys[i] = path.Join(s.alias, e)
}
return keys, nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"keys",
",",
"err",
":=",
"s",
".",
"list",
"(",
"ctx",
",",
"prefix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"e",
":=",
"range",
"keys",
"{",
"keys",
"[",
"i",
"]",
"=",
"path",
".",
"Join",
"(",
"s",
".",
"alias",
",",
"e",
")",
"\n",
"}",
"\n",
"return",
"keys",
",",
"nil",
"\n",
"}"
] | // List returns a list of entries with the given prefix | [
"List",
"returns",
"a",
"list",
"of",
"entries",
"with",
"the",
"given",
"prefix"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L253-L262 | train |
gopasspw/gopass | pkg/store/vault/store.go | Move | func (s *Store) Move(ctx context.Context, from string, to string) error {
// recursive move?
if s.IsDir(ctx, from) {
if s.Exists(ctx, to) {
return errors.Errorf("Can not move dir to file")
}
sf, err := s.List(ctx, "")
if err != nil {
return errors.Wrapf(err, "failed to list store")
}
destPrefix := to
if s.IsDir(ctx, to) {
destPrefix = filepath.Join(to, filepath.Base(from))
}
for _, e := range sf {
if !strings.HasPrefix(e, strings.TrimSuffix(from, "/")+"/") {
continue
}
et := filepath.Join(destPrefix, strings.TrimPrefix(e, from))
if err := s.Move(ctx, e, et); err != nil {
out.Error(ctx, "Failed to move '%s' to '%s': %s", e, et, err)
}
}
return nil
}
content, err := s.Get(ctx, from)
if err != nil {
return errors.Wrapf(err, "failed to decrypt '%s'", from)
}
if err := s.Set(ctx, 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 string, to string) error {
// recursive move?
if s.IsDir(ctx, from) {
if s.Exists(ctx, to) {
return errors.Errorf("Can not move dir to file")
}
sf, err := s.List(ctx, "")
if err != nil {
return errors.Wrapf(err, "failed to list store")
}
destPrefix := to
if s.IsDir(ctx, to) {
destPrefix = filepath.Join(to, filepath.Base(from))
}
for _, e := range sf {
if !strings.HasPrefix(e, strings.TrimSuffix(from, "/")+"/") {
continue
}
et := filepath.Join(destPrefix, strings.TrimPrefix(e, from))
if err := s.Move(ctx, e, et); err != nil {
out.Error(ctx, "Failed to move '%s' to '%s': %s", e, et, err)
}
}
return nil
}
content, err := s.Get(ctx, from)
if err != nil {
return errors.Wrapf(err, "failed to decrypt '%s'", from)
}
if err := s.Set(ctx, 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",
"string",
",",
"to",
"string",
")",
"error",
"{",
"// recursive move?",
"if",
"s",
".",
"IsDir",
"(",
"ctx",
",",
"from",
")",
"{",
"if",
"s",
".",
"Exists",
"(",
"ctx",
",",
"to",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"sf",
",",
"err",
":=",
"s",
".",
"List",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"destPrefix",
":=",
"to",
"\n",
"if",
"s",
".",
"IsDir",
"(",
"ctx",
",",
"to",
")",
"{",
"destPrefix",
"=",
"filepath",
".",
"Join",
"(",
"to",
",",
"filepath",
".",
"Base",
"(",
"from",
")",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"sf",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"e",
",",
"strings",
".",
"TrimSuffix",
"(",
"from",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
")",
"{",
"continue",
"\n",
"}",
"\n",
"et",
":=",
"filepath",
".",
"Join",
"(",
"destPrefix",
",",
"strings",
".",
"TrimPrefix",
"(",
"e",
",",
"from",
")",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"Move",
"(",
"ctx",
",",
"e",
",",
"et",
")",
";",
"err",
"!=",
"nil",
"{",
"out",
".",
"Error",
"(",
"ctx",
",",
"\"",
"\"",
",",
"e",
",",
"et",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"content",
",",
"err",
":=",
"s",
".",
"Get",
"(",
"ctx",
",",
"from",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"from",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"Set",
"(",
"ctx",
",",
"to",
",",
"content",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"to",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"Delete",
"(",
"ctx",
",",
"from",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"from",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Move moves one or many secrets | [
"Move",
"moves",
"one",
"or",
"many",
"secrets"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L290-L327 | train |
gopasspw/gopass | pkg/store/vault/store.go | Set | func (s *Store) Set(ctx context.Context, name string, sec store.Secret) error {
d := sec.Data()
if d == nil {
d = make(map[string]interface{}, 1)
}
d[passwordKey] = sec.Password()
_, err := s.api.Logical().Write(path.Join(s.path, name), d)
return err
} | go | func (s *Store) Set(ctx context.Context, name string, sec store.Secret) error {
d := sec.Data()
if d == nil {
d = make(map[string]interface{}, 1)
}
d[passwordKey] = sec.Password()
_, err := s.api.Logical().Write(path.Join(s.path, name), d)
return err
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Set",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"sec",
"store",
".",
"Secret",
")",
"error",
"{",
"d",
":=",
"sec",
".",
"Data",
"(",
")",
"\n",
"if",
"d",
"==",
"nil",
"{",
"d",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"1",
")",
"\n",
"}",
"\n",
"d",
"[",
"passwordKey",
"]",
"=",
"sec",
".",
"Password",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"s",
".",
"api",
".",
"Logical",
"(",
")",
".",
"Write",
"(",
"path",
".",
"Join",
"(",
"s",
".",
"path",
",",
"name",
")",
",",
"d",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Set writes a secret | [
"Set",
"writes",
"a",
"secret"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L330-L338 | train |
gopasspw/gopass | pkg/store/vault/store.go | Prune | func (s *Store) Prune(ctx context.Context, name string) error {
ls, err := s.List(ctx, name)
if err != nil {
return err
}
for _, e := range ls {
if err := s.Delete(ctx, e); err != nil {
return err
}
}
return nil
} | go | func (s *Store) Prune(ctx context.Context, name string) error {
ls, err := s.List(ctx, name)
if err != nil {
return err
}
for _, e := range ls {
if err := s.Delete(ctx, e); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Prune",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"error",
"{",
"ls",
",",
"err",
":=",
"s",
".",
"List",
"(",
"ctx",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"ls",
"{",
"if",
"err",
":=",
"s",
".",
"Delete",
"(",
"ctx",
",",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Prune removes a directory tree | [
"Prune",
"removes",
"a",
"directory",
"tree"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L341-L352 | train |
gopasspw/gopass | pkg/termio/ask.go | AskForInt | func AskForInt(ctx context.Context, text string, def int) (int, error) {
if ctxutil.IsAlwaysYes(ctx) {
return def, nil
}
str, err := AskForString(ctx, text, strconv.Itoa(def))
if err != nil {
return 0, err
}
if str == "q" {
return 0, ErrAborted
}
intVal, err := strconv.Atoi(str)
if err != nil {
return 0, errors.Wrapf(err, "failed to convert to number")
}
return intVal, nil
} | go | func AskForInt(ctx context.Context, text string, def int) (int, error) {
if ctxutil.IsAlwaysYes(ctx) {
return def, nil
}
str, err := AskForString(ctx, text, strconv.Itoa(def))
if err != nil {
return 0, err
}
if str == "q" {
return 0, ErrAborted
}
intVal, err := strconv.Atoi(str)
if err != nil {
return 0, errors.Wrapf(err, "failed to convert to number")
}
return intVal, nil
} | [
"func",
"AskForInt",
"(",
"ctx",
"context",
".",
"Context",
",",
"text",
"string",
",",
"def",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"ctxutil",
".",
"IsAlwaysYes",
"(",
"ctx",
")",
"{",
"return",
"def",
",",
"nil",
"\n",
"}",
"\n\n",
"str",
",",
"err",
":=",
"AskForString",
"(",
"ctx",
",",
"text",
",",
"strconv",
".",
"Itoa",
"(",
"def",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"str",
"==",
"\"",
"\"",
"{",
"return",
"0",
",",
"ErrAborted",
"\n",
"}",
"\n",
"intVal",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"intVal",
",",
"nil",
"\n",
"}"
] | // AskForInt asks for an valid interger once. If the input
// can not be converted to an int it returns an error | [
"AskForInt",
"asks",
"for",
"an",
"valid",
"interger",
"once",
".",
"If",
"the",
"input",
"can",
"not",
"be",
"converted",
"to",
"an",
"int",
"it",
"returns",
"an",
"error"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/ask.go#L95-L112 | train |
gopasspw/gopass | pkg/termio/ask.go | AskForKeyImport | func AskForKeyImport(ctx context.Context, key string, names []string) bool {
if ctxutil.IsAlwaysYes(ctx) {
return true
}
if !ctxutil.IsInteractive(ctx) {
return false
}
ok, err := AskForBool(ctx, fmt.Sprintf("Do you want to import the public key '%s' (Names: %+v) into your keyring?", key, names), false)
if err != nil {
return false
}
return ok
} | go | func AskForKeyImport(ctx context.Context, key string, names []string) bool {
if ctxutil.IsAlwaysYes(ctx) {
return true
}
if !ctxutil.IsInteractive(ctx) {
return false
}
ok, err := AskForBool(ctx, fmt.Sprintf("Do you want to import the public key '%s' (Names: %+v) into your keyring?", key, names), false)
if err != nil {
return false
}
return ok
} | [
"func",
"AskForKeyImport",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
",",
"names",
"[",
"]",
"string",
")",
"bool",
"{",
"if",
"ctxutil",
".",
"IsAlwaysYes",
"(",
"ctx",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"!",
"ctxutil",
".",
"IsInteractive",
"(",
"ctx",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"ok",
",",
"err",
":=",
"AskForBool",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
",",
"names",
")",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"ok",
"\n",
"}"
] | // AskForKeyImport asks for permissions to import the named key | [
"AskForKeyImport",
"asks",
"for",
"permissions",
"to",
"import",
"the",
"named",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/ask.go#L134-L148 | train |
gopasspw/gopass | pkg/termio/ask.go | AskForPassword | func AskForPassword(ctx context.Context, name string) (string, error) {
if ctxutil.IsAlwaysYes(ctx) {
return "", nil
}
askFn := GetPassPromptFunc(ctx)
for i := 0; i < maxTries; i++ {
// check for context cancelation
select {
case <-ctx.Done():
return "", ErrAborted
default:
}
pass, err := askFn(ctx, fmt.Sprintf("Enter password for %s", name))
if err != nil {
return "", err
}
passAgain, err := askFn(ctx, fmt.Sprintf("Retype password for %s", name))
if err != nil {
return "", err
}
if pass == passAgain || pass == "" {
return pass, nil
}
out.Error(ctx, "Error: the entered password do not match")
}
return "", errors.New("no valid user input")
} | go | func AskForPassword(ctx context.Context, name string) (string, error) {
if ctxutil.IsAlwaysYes(ctx) {
return "", nil
}
askFn := GetPassPromptFunc(ctx)
for i := 0; i < maxTries; i++ {
// check for context cancelation
select {
case <-ctx.Done():
return "", ErrAborted
default:
}
pass, err := askFn(ctx, fmt.Sprintf("Enter password for %s", name))
if err != nil {
return "", err
}
passAgain, err := askFn(ctx, fmt.Sprintf("Retype password for %s", name))
if err != nil {
return "", err
}
if pass == passAgain || pass == "" {
return pass, nil
}
out.Error(ctx, "Error: the entered password do not match")
}
return "", errors.New("no valid user input")
} | [
"func",
"AskForPassword",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"ctxutil",
".",
"IsAlwaysYes",
"(",
"ctx",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"askFn",
":=",
"GetPassPromptFunc",
"(",
"ctx",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxTries",
";",
"i",
"++",
"{",
"// check for context cancelation",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"\"",
"\"",
",",
"ErrAborted",
"\n",
"default",
":",
"}",
"\n\n",
"pass",
",",
"err",
":=",
"askFn",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"passAgain",
",",
"err",
":=",
"askFn",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"pass",
"==",
"passAgain",
"||",
"pass",
"==",
"\"",
"\"",
"{",
"return",
"pass",
",",
"nil",
"\n",
"}",
"\n\n",
"out",
".",
"Error",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // AskForPassword prompts for a password twice until both match | [
"AskForPassword",
"prompts",
"for",
"a",
"password",
"twice",
"until",
"both",
"match"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/ask.go#L151-L182 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.