Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion initialize/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

const (
saltLen = 32
configFound = "A passgo config file was already found."
)

Expand Down
10 changes: 5 additions & 5 deletions passgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ var (
not yet initialized your vault, it is necessary to run
the init subcommand in order to create your passgo
directory, and initialize your cryptographic keys.`,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
if exists, _ := pio.PassFileDirExists(); exists {
show.ListAll()
} else {
cmd.Help()
return show.ListAll()
}

return cmd.Help()
},
}
versionCmd = &cobra.Command{
Expand Down Expand Up @@ -164,5 +164,5 @@ func init() {
}

func main() {
RootCmd.Execute()
RootCmd.Execute() // nolint: errcheck
}
15 changes: 10 additions & 5 deletions pio/pio.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,23 @@ func PromptPass(prompt string) (pass string, err error) {
fd := int(os.Stdin.Fd())
oldState, err := terminal.GetState(fd)
if err != nil {
panic("Could not get state of terminal: " + err.Error())
log.Fatalf("Count not get state of terminal: %v", err)
}
defer terminal.Restore(fd, oldState)
defer func() {
if err := terminal.Restore(fd, oldState); err != nil {
log.Fatal(err)
}
}()

// Restore STDIN in the event of a signal interuption
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)
go func() {
for _ = range sigch {
terminal.Restore(fd, oldState)
os.Exit(1)
<-sigch
if err := terminal.Restore(fd, oldState); err != nil {
log.Fatal(err)
}
os.Exit(1)
}()

fmt.Printf("%s: ", prompt)
Expand Down
26 changes: 15 additions & 11 deletions show/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,47 @@ func init() {
}
}

func handleErrors(allErrors []error) {
errorStr := "Error"
func handleErrors(allErrors []error) error {
if len(allErrors) == 0 {
return
} else if len(allErrors) > 1 {
return nil
}

errorStr := "Error"
if len(allErrors) > 1 {
errorStr = "Errors"
}
log.Printf("%d %s encountered:\n", len(allErrors), errorStr)
for n, err := range allErrors {
log.Printf("Error %d: %s", n, err.Error())
}

return fmt.Errorf("%d %s encountered", len(allErrors), errorStr)
}

// Find will search the vault for all occurences of frag in the site name.
func Find(frag string) {
func Find(frag string) error {
allSites, allErrors := SearchAll(Search, frag)
showResults(allSites)
handleErrors(allErrors)
return handleErrors(allErrors)
}

// Site will print out the password of the site that matches path
func Site(path string, copyPassword bool) {
func Site(path string, copyPassword bool) error {
allSites, allErrors := SearchAll(One, path)
if len(allSites) == 0 {
fmt.Printf("Site with path %s not found", path)
return
return nil
}
masterPrivKey := pc.GetMasterKey()
showPassword(allSites, masterPrivKey, copyPassword)
handleErrors(allErrors)
return handleErrors(allErrors)
}

// ListAll will print out all contents of the vault.
func ListAll() {
func ListAll() error {
allSites, allErrors := SearchAll(All, "")
showResults(allSites)
handleErrors(allErrors)
return handleErrors(allErrors)
}

func showPassword(allSites map[string][]pio.SiteInfo, masterPrivKey [32]byte, copyPassword bool) {
Expand Down