_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q29100 | GetAlias | train | func GetAlias(ctx context.Context) string {
a, ok := ctx.Value(ctxKeyAlias).(string)
if !ok {
return ""
}
return a
} | go | {
"resource": ""
} |
q29101 | WithAutoPrint | train | func WithAutoPrint(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyAutoPrint, bv)
} | go | {
"resource": ""
} |
q29102 | HasAutoPrint | train | func HasAutoPrint(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAutoPrint).(bool)
return ok
} | go | {
"resource": ""
} |
q29103 | IsAutoPrint | train | func IsAutoPrint(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyAutoPrint).(bool)
if !ok {
return false
}
return bv
} | go | {
"resource": ""
} |
q29104 | WithGitInit | train | func WithGitInit(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyGitInit, bv)
} | go | {
"resource": ""
} |
q29105 | HasGitInit | train | func HasGitInit(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyGitInit).(bool)
return ok
} | go | {
"resource": ""
} |
q29106 | IsGitInit | train | func IsGitInit(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyGitInit).(bool)
if !ok {
return true
}
return bv
} | go | {
"resource": ""
} |
q29107 | GetCompletion | train | func GetCompletion(a *cli.App) (string, error) {
tplFuncs := template.FuncMap{
"formatFlag": formatFlagFunc(),
}
tpl, err := template.New("zsh").Funcs(tplFuncs).Parse(zshTemplate)
if err != nil {
return "", err
}
buf := &bytes.Buffer{}
if err := tpl.Execute(buf, a); err != nil {
return "", err
}
return b... | go | {
"resource": ""
} |
q29108 | Sum | train | func Sum(ctx context.Context, c *cli.Context, store storer) error {
name := c.Args().First()
if name == "" {
return action.ExitError(ctx, action.ExitUsage, nil, "Usage: %s sha256 name", c.App.Name)
}
if !strings.HasSuffix(name, Suffix) {
name += Suffix
}
buf, err := binaryGet(ctx, name, store)
if err != ni... | go | {
"resource": ""
} |
q29109 | Get | train | func (s *Store) Get(ctx context.Context, name string) (store.Secret, error) {
p := s.passfile(name)
ciphertext, err := s.storage.Get(ctx, p)
if err != nil {
out.Debug(ctx, "File %s not found: %s", p, err)
return nil, store.ErrNotFound
}
content, err := s.crypto.Decrypt(ctx, ciphertext)
if err != nil {
out... | go | {
"resource": ""
} |
q29110 | JSONAPI | train | func (s *Action) JSONAPI(ctx context.Context, c *cli.Context) error {
api := jsonapi.API{Store: s.Store, Reader: stdin, Writer: stdout, Version: s.version}
if err := api.ReadAndRespond(ctx); err != nil {
return api.RespondError(err)
}
return nil
} | go | {
"resource": ""
} |
q29111 | Get | train | func (m *InMem) Get(ctx context.Context, name string) ([]byte, error) {
m.Lock()
defer m.Unlock()
sec, found := m.data[name]
if !found {
return nil, fmt.Errorf("entry not found")
}
return sec, nil
} | go | {
"resource": ""
} |
q29112 | Set | train | func (m *InMem) Set(ctx context.Context, name string, value []byte) error {
m.Lock()
defer m.Unlock()
m.data[name] = value
return nil
} | go | {
"resource": ""
} |
q29113 | Delete | train | func (m *InMem) Delete(ctx context.Context, name string) error {
m.Lock()
defer m.Unlock()
delete(m.data, name)
return nil
} | go | {
"resource": ""
} |
q29114 | Exists | train | func (m *InMem) Exists(ctx context.Context, name string) bool {
m.Lock()
defer m.Unlock()
_, found := m.data[name]
return found
} | go | {
"resource": ""
} |
q29115 | List | train | func (m *InMem) List(ctx context.Context, prefix string) ([]string, error) {
m.Lock()
defer m.Unlock()
keys := make([]string, 0, len(m.data))
for k := range m.data {
keys = append(keys, k)
}
sort.Strings(keys)
return keys, nil
} | go | {
"resource": ""
} |
q29116 | IsDir | train | func (m *InMem) IsDir(ctx context.Context, name string) bool {
m.Lock()
defer m.Unlock()
for k := range m.data {
if strings.HasPrefix(k, name+"/") {
return true
}
}
return false
} | go | {
"resource": ""
} |
q29117 | Prune | train | func (m *InMem) Prune(ctx context.Context, prefix string) error {
m.Lock()
defer m.Unlock()
deleted := 0
for k := range m.data {
if strings.HasPrefix(k, prefix+"/") {
delete(m.data, k)
deleted++
}
}
if deleted < 1 {
return fmt.Errorf("not found")
}
return nil
} | go | {
"resource": ""
} |
q29118 | GenerateKeypair | train | func GenerateKeypair(passphrase string) (*PrivateKey, error) {
pub, priv, err := box.GenerateKey(crypto_rand.Reader)
if err != nil {
return nil, err
}
k := &PrivateKey{
PublicKey: PublicKey{
CreationTime: time.Now(),
PubKeyAlgo: PubKeyNaCl,
PublicKey: *pub,
Identity: &xcpb.Identity{},
},
... | go | {
"resource": ""
} |
q29119 | Encrypt | train | func (p *PrivateKey) Encrypt(passphrase string) error {
p.Salt = make([]byte, saltLength)
if n, err := crypto_rand.Read(p.Salt); err != nil || n < len(p.Salt) {
return err
}
secretKey := p.deriveKey(passphrase)
var nonce [nonceLength]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
r... | go | {
"resource": ""
} |
q29120 | Decrypt | train | func (p *PrivateKey) Decrypt(passphrase string) error {
if !p.Encrypted {
return nil
}
secretKey := p.deriveKey(passphrase)
decrypted, ok := secretbox.Open(nil, p.EncryptedData, &p.Nonce, &secretKey)
if !ok {
return fmt.Errorf("decryption error")
}
copy(p.privateKey[:], decrypted)
p.Encrypted = false
ret... | go | {
"resource": ""
} |
q29121 | Create | train | func Create(ctx context.Context, c *cli.Context, store storer) error {
s := creator{store: store}
acts := make(cui.Actions, 0, 5)
acts = append(acts, cui.Action{Name: "Website Login", Fn: s.createWebsite})
acts = append(acts, cui.Action{Name: "PIN Code (numerical)", Fn: s.createPIN})
acts = append(acts, cui.Action... | go | {
"resource": ""
} |
q29122 | extractHostname | train | func extractHostname(in string) string {
if in == "" {
return ""
}
// help url.Parse by adding a scheme if one is missing. This should still
// allow for any scheme, but by default we assume http (only for parsing)
urlStr := in
if !strings.Contains(urlStr, "://") {
urlStr = "http://" + urlStr
}
u, err := ur... | go | {
"resource": ""
} |
q29123 | createAWS | train | func (s *creator) createAWS(ctx context.Context, c *cli.Context) error {
var (
account = c.Args().Get(0)
username = c.Args().Get(1)
accesskey = c.Args().Get(2)
secretkey string
region string
store = c.String("store")
err error
)
out.Green(ctx, "=> Creating AWS credentials ...")
account... | go | {
"resource": ""
} |
q29124 | createGCP | train | func (s *creator) createGCP(ctx context.Context, c *cli.Context) error {
var (
project string
username string
svcaccfn = c.Args().Get(0)
store = c.String("store")
err error
)
out.Green(ctx, "=> Creating GCP credentials ...")
svcaccfn, err = termio.AskForString(ctx, fmtfn(2, "1", "Service Account ... | go | {
"resource": ""
} |
q29125 | extractGCPInfo | train | func extractGCPInfo(buf []byte) (string, string, error) {
var m map[string]string
if err := json.Unmarshal(buf, &m); err != nil {
return "", "", err
}
p := strings.Split(m["client_email"], "@")
if len(p) < 2 {
return "", "", fmt.Errorf("client_email contains no email")
}
username := p[0]
p = strings.Split(p... | go | {
"resource": ""
} |
q29126 | createGeneric | train | func (s *creator) createGeneric(ctx context.Context, c *cli.Context) error {
var (
shortname = c.Args().Get(0)
password string
store = c.String("store")
err error
genPw bool
)
out.Green(ctx, "=> Creating generic secret ...")
shortname, err = termio.AskForString(ctx, fmtfn(2, "1", "Name"), s... | go | {
"resource": ""
} |
q29127 | createGeneratePassword | train | func (s *creator) createGeneratePassword(ctx context.Context) (string, error) {
noXkcd, err := termio.AskForBool(ctx, fmtfn(4, "a", "Cryptic Password?"), true)
if err != nil {
return "", err
}
if !noXkcd {
length, err := termio.AskForInt(ctx, fmtfn(4, "b", "How many words?"), 4)
if err != nil {
return "", ... | go | {
"resource": ""
} |
q29128 | createGeneratePIN | train | func (s *creator) createGeneratePIN(ctx context.Context) (string, error) {
length, err := termio.AskForInt(ctx, fmtfn(4, "a", "How long?"), 4)
if err != nil {
return "", err
}
return pwgen.GeneratePasswordCharset(length, "0123456789"), nil
} | go | {
"resource": ""
} |
q29129 | WithCryptoBackendString | train | func WithCryptoBackendString(ctx context.Context, be string) context.Context {
if cb := cryptoBackendFromName(be); cb >= 0 {
ctx = WithCryptoBackend(ctx, cb)
}
return ctx
} | go | {
"resource": ""
} |
q29130 | WithCryptoBackend | train | func WithCryptoBackend(ctx context.Context, be CryptoBackend) context.Context {
return context.WithValue(ctx, ctxKeyCryptoBackend, be)
} | go | {
"resource": ""
} |
q29131 | HasCryptoBackend | train | func HasCryptoBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyCryptoBackend).(CryptoBackend)
return ok
} | go | {
"resource": ""
} |
q29132 | WithRCSBackendString | train | func WithRCSBackendString(ctx context.Context, sb string) context.Context {
if be := rcsBackendFromName(sb); be >= 0 {
return WithRCSBackend(ctx, be)
}
return WithRCSBackend(ctx, Noop)
} | go | {
"resource": ""
} |
q29133 | WithRCSBackend | train | func WithRCSBackend(ctx context.Context, sb RCSBackend) context.Context {
return context.WithValue(ctx, ctxKeyRCSBackend, sb)
} | go | {
"resource": ""
} |
q29134 | HasRCSBackend | train | func HasRCSBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyRCSBackend).(RCSBackend)
return ok
} | go | {
"resource": ""
} |
q29135 | WithStorageBackendString | train | func WithStorageBackendString(ctx context.Context, sb string) context.Context {
return WithStorageBackend(ctx, storageBackendFromName(sb))
} | go | {
"resource": ""
} |
q29136 | WithStorageBackend | train | func WithStorageBackend(ctx context.Context, sb StorageBackend) context.Context {
return context.WithValue(ctx, ctxKeyStorageBackend, sb)
} | go | {
"resource": ""
} |
q29137 | HasStorageBackend | train | func HasStorageBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyStorageBackend).(StorageBackend)
return ok
} | go | {
"resource": ""
} |
q29138 | New | train | func New() *Config {
return &Config{
Path: configLocation(),
Root: &StoreConfig{
AskForMore: false,
AutoClip: true,
AutoImport: true,
AutoSync: true,
ClipTimeout: 45,
Concurrency: 1,
NoColor: false,
NoConfirm: false,
NoPager: false,
SafeContent: f... | go | {
"resource": ""
} |
q29139 | GetRecipientHash | train | func (c *Config) GetRecipientHash(alias, name string) string {
if alias == "" {
return c.Root.RecipientHash[name]
}
if sc, found := c.Mounts[alias]; found && sc != nil {
return sc.RecipientHash[name]
}
return ""
} | go | {
"resource": ""
} |
q29140 | SetRecipientHash | train | func (c *Config) SetRecipientHash(alias, name, value string) error {
if alias == "" {
c.Root.setRecipientHash(name, value)
} else {
if sc, found := c.Mounts[alias]; found && sc != nil {
sc.setRecipientHash(name, value)
}
}
return c.Save()
} | go | {
"resource": ""
} |
q29141 | List | train | func (s *Store) List(ctx context.Context, prefix string) ([]string, error) {
if s.storage == nil || s.crypto == nil {
return nil, nil
}
lst, err := s.storage.List(ctx, prefix)
if err != nil {
return nil, err
}
out.Debug(ctx, "sub.List(%s): %+v\n", prefix, lst)
out := make([]string, 0, len(lst))
cExt := "."... | go | {
"resource": ""
} |
q29142 | Initialized | train | func (s *Action) Initialized(ctx context.Context, c *cli.Context) error {
inited, err := s.Store.Initialized(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "Failed to initialize store: %s", err)
}
if inited {
out.Debug(ctx, "Store is already initialized")
return nil
}
out.Debug(ctx, "Store ne... | go | {
"resource": ""
} |
q29143 | Init | train | func (s *Action) Init(ctx context.Context, c *cli.Context) error {
path := c.String("path")
alias := c.String("store")
ctx = initParseContext(ctx, c)
inited, err := s.Store.Initialized(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "Failed to initialized store: %s", err)
}
if inited {
out.Erro... | go | {
"resource": ""
} |
q29144 | initLocal | train | func (s *Action) initLocal(ctx context.Context, c *cli.Context) error {
ctx = out.AddPrefix(ctx, "[local] ")
path := ""
if s.Store != nil {
path = s.Store.URL()
}
out.Print(ctx, "Initializing your local store ...")
if err := s.init(out.WithHidden(ctx, true), "", path); err != nil {
return errors.Wrapf(err, ... | go | {
"resource": ""
} |
q29145 | initCreateTeam | train | func (s *Action) initCreateTeam(ctx context.Context, c *cli.Context, team, remote string) error {
var err error
out.Print(ctx, "Creating a new team ...")
if err := s.initLocal(ctx, c); err != nil {
return errors.Wrapf(err, "failed to create local store")
}
// name of the new team
team, err = termio.AskForStri... | go | {
"resource": ""
} |
q29146 | Notify | train | func Notify(ctx context.Context, subj, msg string) error {
if os.Getenv("GOPASS_NO_NOTIFY") != "" || !ctxutil.IsNotifications(ctx) {
return nil
}
conn, err := dbus.SessionBus()
if err != nil {
return err
}
obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call... | go | {
"resource": ""
} |
q29147 | Fingerprint | train | func (p PublicKey) Fingerprint() string {
h := make([]byte, 20)
d := sha3.NewShake256()
_, _ = d.Write([]byte{0x42})
_ = binary.Write(d, binary.LittleEndian, p.PubKeyAlgo)
_, _ = d.Write(p.PublicKey[:])
_, _ = d.Read(h)
return fmt.Sprintf("%x", h)
} | go | {
"resource": ""
} |
q29148 | bashEscape | train | func bashEscape(s string) string {
return escapeRegExp.ReplaceAllStringFunc(s, func(c string) string {
if c == `\` {
return `\\\\`
}
return `\\` + c
})
} | go | {
"resource": ""
} |
q29149 | Complete | train | func (s *Action) Complete(ctx context.Context, c *cli.Context) {
_, err := s.Store.Initialized(ctx) // important to make sure the structs are not nil
if err != nil {
out.Error(ctx, "Store not initialized: %s", err)
return
}
list, err := s.Store.List(ctx, 0)
if err != nil {
return
}
for _, v := range list ... | go | {
"resource": ""
} |
q29150 | CompletionOpenBSDKsh | train | func (s *Action) CompletionOpenBSDKsh(c *cli.Context, a *cli.App) error {
out := `
PASS_LIST=$(gopass ls -f)
set -A complete_gopass -- $PASS_LIST %s
`
if a == nil {
return fmt.Errorf("can not parse command options")
}
var opts []string
for _, opt := range a.Commands {
opts = append(opts, opt.Name)
if len(o... | go | {
"resource": ""
} |
q29151 | CompletionBash | train | func (s *Action) CompletionBash(c *cli.Context) error {
out := `_gopass_bash_autocomplete() {
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ... | go | {
"resource": ""
} |
q29152 | CompletionFish | train | func (s *Action) CompletionFish(c *cli.Context, a *cli.App) error {
comp, err := fishcomp.GetCompletion(a)
if err != nil {
return err
}
fmt.Fprintln(stdout, comp)
return nil
} | go | {
"resource": ""
} |
q29153 | CompletionZSH | train | func (s *Action) CompletionZSH(c *cli.Context, a *cli.App) error {
comp, err := zshcomp.GetCompletion(a)
if err != nil {
return err
}
fmt.Fprintln(stdout, comp)
return nil
} | go | {
"resource": ""
} |
q29154 | New | train | func New(dir string) *Client {
socket := filepath.Join(dir, ".gopass-agent.sock")
return &Client{
http: &http.Client{
Transport: &http.Transport{
DialContext: func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", socket)
},
},
Timeout: 10 * time.Minute,
},
}
} | go | {
"resource": ""
} |
q29155 | Ping | train | func (c *Client) Ping(ctx context.Context) error {
pc := &http.Client{
Transport: c.http.Transport,
Timeout: 5 * time.Second,
}
resp, err := pc.Get("http://unix/ping")
if err != nil {
return err
}
_ = resp.Body.Close()
return nil
} | go | {
"resource": ""
} |
q29156 | Remove | train | func (c *Client) Remove(ctx context.Context, key string) error {
if err := c.checkAgent(ctx); err != nil {
return errors.Wrapf(err, "agent not available: %s", err)
}
u, err := url.Parse("http://unix/cache/remove")
if err != nil {
return errors.Wrapf(err, "failed to build request url")
}
values := u.Query()
... | go | {
"resource": ""
} |
q29157 | ImportPublicKey | train | func (x *XC) ImportPublicKey(ctx context.Context, buf []byte) error {
if err := x.pubring.Import(buf); err != nil {
return err
}
return x.pubring.Save()
} | go | {
"resource": ""
} |
q29158 | ImportPrivateKey | train | func (x *XC) ImportPrivateKey(ctx context.Context, buf []byte) error {
if err := x.secring.Import(buf); err != nil {
return err
}
return x.secring.Save()
} | go | {
"resource": ""
} |
q29159 | New | train | func New(dir string, client agentClient) (*XC, error) {
skr, _ := keyring.LoadSecring(filepath.Join(dir, secringFilename))
pkr, _ := keyring.LoadPubring(filepath.Join(dir, pubringFilename), skr)
return &XC{
dir: dir,
pubring: pkr,
secring: skr,
client: client,
}, nil
} | go | {
"resource": ""
} |
q29160 | RemoveKey | train | func (x *XC) RemoveKey(id string) error {
if x.secring.Contains(id) {
if err := x.secring.Remove(id); err != nil {
return err
}
return x.secring.Save()
}
if x.pubring.Contains(id) {
if err := x.pubring.Remove(id); err != nil {
return err
}
return x.pubring.Save()
}
return fmt.Errorf("not found")
... | go | {
"resource": ""
} |
q29161 | Initialized | train | func (x *XC) Initialized(ctx context.Context) error {
if x == nil {
return fmt.Errorf("XC not initialized")
}
if x.pubring == nil {
return fmt.Errorf("pubring not initialized")
}
if x.secring == nil {
return fmt.Errorf("secring not initialized")
}
if x.client == nil {
return fmt.Errorf("client not initia... | go | {
"resource": ""
} |
q29162 | Version | train | func (x *XC) Version(ctx context.Context) semver.Version {
return semver.Version{
Patch: 1,
}
} | go | {
"resource": ""
} |
q29163 | Binary | train | func Binary(ctx context.Context, bin string) (string, error) {
bins, err := detectBinaryCandidates(bin)
if err != nil {
return "", err
}
bv := make(byVersion, 0, len(bins))
for _, b := range bins {
//out.Debug(ctx, "gpg.detectBinary - Looking for '%s' ...", b)
if p, err := exec.LookPath(b); err == nil {
g... | go | {
"resource": ""
} |
q29164 | WithPrefix | train | func WithPrefix(ctx context.Context, prefix string) context.Context {
return context.WithValue(ctx, ctxKeyPrefix, prefix)
} | go | {
"resource": ""
} |
q29165 | AddPrefix | train | func AddPrefix(ctx context.Context, prefix string) context.Context {
if prefix == "" {
return ctx
}
pfx := Prefix(ctx)
if pfx == "" {
return WithPrefix(ctx, prefix)
}
return WithPrefix(ctx, pfx+prefix)
} | go | {
"resource": ""
} |
q29166 | Prefix | train | func Prefix(ctx context.Context) string {
sv, ok := ctx.Value(ctxKeyPrefix).(string)
if !ok {
return ""
}
return sv
} | go | {
"resource": ""
} |
q29167 | WithHidden | train | func WithHidden(ctx context.Context, hidden bool) context.Context {
return context.WithValue(ctx, ctxKeyHidden, hidden)
} | go | {
"resource": ""
} |
q29168 | IsHidden | train | func IsHidden(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyHidden).(bool)
if !ok {
return false
}
return bv
} | go | {
"resource": ""
} |
q29169 | WithNewline | train | func WithNewline(ctx context.Context, nl bool) context.Context {
return context.WithValue(ctx, ctxKeyNewline, nl)
} | go | {
"resource": ""
} |
q29170 | Move | train | func (s *Action) Move(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
if len(c.Args()) != 2 {
return ExitError(ctx, ExitUsage, nil, "Usage: %s mv old-path new-path", s.Name)
}
from := c.Args()[0]
to := c.Args()[1]
if !force {
if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ct... | go | {
"resource": ""
} |
q29171 | New | train | func New(dir, passphrase string) (*Config, error) {
if dir == "" || dir == "." {
return nil, fmt.Errorf("dir must not be empty")
}
fn := filepath.Join(dir, filename)
c := &Config{
filename: fn,
passphrase: passphrase,
}
if !fsutil.IsFile(fn) {
err := save(c.filename, c.passphrase, map[string]string{})... | go | {
"resource": ""
} |
q29172 | Get | train | func (c *Config) Get(key string) (string, error) {
data, err := load(c.filename, c.passphrase)
return data[key], err
} | go | {
"resource": ""
} |
q29173 | Set | train | func (c *Config) Set(key, value string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
old := data[key]
if value == old {
return nil
}
data[key] = value
return save(c.filename, c.passphrase, data)
} | go | {
"resource": ""
} |
q29174 | Unset | train | func (c *Config) Unset(key string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
_, found := data[key]
if !found {
return nil
}
delete(data, key)
return save(c.filename, c.passphrase, data)
} | go | {
"resource": ""
} |
q29175 | open | train | func open(buf []byte, passphrase string) (map[string]string, error) {
salt := make([]byte, saltLength)
copy(salt, buf[:saltLength])
var nonce [nonceLength]byte
copy(nonce[:], buf[saltLength:nonceLength+saltLength])
secretKey := deriveKey(passphrase, salt)
decrypted, ok := secretbox.Open(nil, buf[nonceLength+saltL... | go | {
"resource": ""
} |
q29176 | save | train | func save(filename, passphrase string, data map[string]string) error {
buf, err := seal(data, passphrase)
if err != nil {
return err
}
return ioutil.WriteFile(filename, buf, 0600)
} | go | {
"resource": ""
} |
q29177 | seal | train | func seal(data map[string]string, passphrase string) ([]byte, error) {
jstr, err := json.Marshal(data)
if err != nil {
return nil, err
}
var nonce [nonceLength]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
return nil, err
}
salt := make([]byte, saltLength)
if _, err := crypto_ran... | go | {
"resource": ""
} |
q29178 | AskForPrivateKey | train | func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, name, prompt string) (string, error) {
if !ctxutil.IsInteractive(ctx) {
return "", errors.New("can not select private key without terminal")
}
if crypto == nil {
return "", errors.New("can not select private key without valid crypto backend")
}
... | go | {
"resource": ""
} |
q29179 | NewSecring | train | func NewSecring() *Secring {
return &Secring{
data: &xcpb.Secring{
PrivateKeys: make([]*xcpb.PrivateKey, 0, 10),
},
}
} | go | {
"resource": ""
} |
q29180 | LoadSecring | train | func LoadSecring(file string) (*Secring, error) {
pr := NewSecring()
pr.File = file
buf, err := ioutil.ReadFile(file)
if os.IsNotExist(err) {
return pr, nil
}
if err != nil {
return nil, err
}
if err := proto.Unmarshal(buf, pr.data); err != nil {
return nil, err
}
return pr, nil
} | go | {
"resource": ""
} |
q29181 | Contains | train | func (p *Secring) Contains(fp string) bool {
p.Lock()
defer p.Unlock()
for _, pk := range p.data.PrivateKeys {
if pk.PublicKey.Fingerprint == fp {
return true
}
}
return false
} | go | {
"resource": ""
} |
q29182 | KeyIDs | train | func (p *Secring) KeyIDs() []string {
p.Lock()
defer p.Unlock()
ids := make([]string, 0, len(p.data.PrivateKeys))
for _, pk := range p.data.PrivateKeys {
ids = append(ids, pk.PublicKey.Fingerprint)
}
sort.Strings(ids)
return ids
} | go | {
"resource": ""
} |
q29183 | Export | train | func (p *Secring) Export(id string, withPrivate bool) ([]byte, error) {
p.Lock()
defer p.Unlock()
xpk := p.fetch(id)
if xpk == nil {
return nil, fmt.Errorf("key not found")
}
if withPrivate {
return proto.Marshal(xpk)
}
return proto.Marshal(xpk.PublicKey)
} | go | {
"resource": ""
} |
q29184 | Import | train | func (p *Secring) Import(buf []byte) error {
pk := &xcpb.PrivateKey{}
if err := proto.Unmarshal(buf, pk); err != nil {
return err
}
p.insert(pk)
return nil
} | go | {
"resource": ""
} |
q29185 | Set | train | func (p *Secring) Set(pk *PrivateKey) error {
if !pk.Encrypted {
return fmt.Errorf("private key must be encrypted")
}
p.Lock()
defer p.Unlock()
p.insert(secKRToPB(pk))
return nil
} | go | {
"resource": ""
} |
q29186 | Remove | train | func (p *Secring) Remove(id string) error {
p.Lock()
defer p.Unlock()
match := -1
for i, pk := range p.data.PrivateKeys {
if pk.PublicKey.Fingerprint == id {
match = i
break
}
}
if match < 0 || match > len(p.data.PrivateKeys) {
return fmt.Errorf("not found")
}
p.data.PrivateKeys = append(p.data.Pri... | go | {
"resource": ""
} |
q29187 | Sync | train | func (s *Action) Sync(ctx context.Context, c *cli.Context) error {
store := c.String("store")
return s.sync(ctx, c, store)
} | go | {
"resource": ""
} |
q29188 | Open | train | func Open(path, gpg string) (*Git, error) {
if !fsutil.IsDir(filepath.Join(path, ".git")) {
return nil, fmt.Errorf("git repo does not exist")
}
return &Git{
path: path,
}, nil
} | go | {
"resource": ""
} |
q29189 | Clone | train | func Clone(ctx context.Context, repo, path string) (*Git, error) {
g := &Git{
path: filepath.Dir(path),
}
if err := g.Cmd(ctx, "Clone", "clone", repo, path); err != nil {
return nil, err
}
g.path = path
return g, nil
} | go | {
"resource": ""
} |
q29190 | Init | train | func Init(ctx context.Context, path, userName, userEmail string) (*Git, error) {
g := &Git{
path: path,
}
// the git repo may be empty (i.e. no branches, cloned from a fresh remote)
// or already initialized. Only run git init if the folder is completely empty
if !g.IsInitialized() {
if err := g.Cmd(ctx, "Init... | go | {
"resource": ""
} |
q29191 | Cmd | train | func (g *Git) Cmd(ctx context.Context, name string, args ...string) error {
stdout, stderr, err := g.captureCmd(ctx, name, args...)
if err != nil {
out.Debug(ctx, "Output:\n Stdout: '%s'\n Stderr: '%s'", string(stdout), string(stderr))
return err
}
return nil
} | go | {
"resource": ""
} |
q29192 | Version | train | func (g *Git) Version(ctx context.Context) semver.Version {
v := semver.Version{}
cmd := exec.CommandContext(ctx, "git", "version")
cmdout, err := cmd.Output()
if err != nil {
out.Debug(ctx, "Failed to run 'git version': %s", err)
return v
}
svStr := strings.TrimPrefix(string(cmdout), "git version ")
if p ... | go | {
"resource": ""
} |
q29193 | Add | train | func (g *Git) Add(ctx context.Context, files ...string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
for i := range files {
files[i] = strings.TrimPrefix(files[i], g.path+"/")
}
args := []string{"add", "--all", "--force"}
args = append(args, files...)
return g.Cmd(ctx, "gitAdd", args...)
} | go | {
"resource": ""
} |
q29194 | HasStagedChanges | train | func (g *Git) HasStagedChanges(ctx context.Context) bool {
if err := g.Cmd(ctx, "gitDiffIndex", "diff-index", "--quiet", "HEAD"); err != nil {
return true
}
return false
} | go | {
"resource": ""
} |
q29195 | Commit | train | func (g *Git) Commit(ctx context.Context, msg string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
if !g.HasStagedChanges(ctx) {
return store.ErrGitNothingToCommit
}
return g.Cmd(ctx, "gitCommit", "commit", "-m", msg)
} | go | {
"resource": ""
} |
q29196 | Push | train | func (g *Git) Push(ctx context.Context, remote, branch string) error {
return g.PushPull(ctx, "push", remote, branch)
} | go | {
"resource": ""
} |
q29197 | exportPublicKey | train | func (s *Store) exportPublicKey(ctx context.Context, r string) (string, error) {
filename := filepath.Join(keyDir, r)
// do not overwrite existing keys
if s.storage.Exists(ctx, filename) {
return "", nil
}
pk, err := s.crypto.ExportPublicKey(ctx, r)
if err != nil {
return "", errors.Wrapf(err, "failed to ex... | go | {
"resource": ""
} |
q29198 | importPublicKey | train | func (s *Store) importPublicKey(ctx context.Context, r string) error {
for _, kd := range []string{keyDir, oldKeyDir} {
filename := filepath.Join(kd, r)
if !s.storage.Exists(ctx, filename) {
out.Debug(ctx, "Public Key %s not found at %s", r, filename)
continue
}
pk, err := s.storage.Get(ctx, filename)
... | go | {
"resource": ""
} |
q29199 | List | train | func (s *Action) List(ctx context.Context, c *cli.Context) error {
filter := c.Args().First()
flat := c.Bool("flat")
stripPrefix := c.Bool("strip-prefix")
limit := c.Int("limit")
folders := c.Bool("folders")
// we only support listing folders in flat mode currently
if folders {
flat = true
}
ctx = s.Store.W... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.