style: change space to tab for goreport

This commit is contained in:
Adrien Waksberg 2019-08-31 19:18:35 +02:00
parent 30ada1a1fc
commit 3f9d4850b6
13 changed files with 853 additions and 842 deletions

View file

@ -17,6 +17,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
- Export in a file - Export in a file
- Use RandomString function for wallet's salt - Use RandomString function for wallet's salt
- Search is case insensite - Search is case insensite
- change space to tab for goreport
## v1.1.0 - 2019-07-23 ## v1.1.0 - 2019-07-23

View file

@ -1,8 +1,9 @@
# gpm: Go Passwords Manager # gpm: Go Passwords Manager
[![Version](https://img.shields.io/badge/latest_version-1.1.0-green.svg)](https://git.yaegashi.fr/nishiki/gpm/releases) [![Version](https://img.shields.io/badge/latest_version-1.1.0-green.svg)](https://git.yaegashi.fr/nishiki/gpm/releases)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/gpm/src/branch/master/LICENSE)
[![Build Status](https://travis-ci.org/nishiki/gpm.svg?branch=master)](https://travis-ci.org/nishiki/gpm) [![Build Status](https://travis-ci.org/nishiki/gpm.svg?branch=master)](https://travis-ci.org/nishiki/gpm)
[![GoReport](https://goreportcard.com/badge/git.yaegashi.fr/nishiki/gpm)](https://goreportcard.com/report/git.yaegashi.fr/nishiki/gpm)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/gpm/src/branch/master/LICENSE)
gpm is passwords manager write in go and use AES-256 to encrypt the wallets gpm is passwords manager write in go and use AES-256 to encrypt the wallets

View file

@ -14,7 +14,7 @@
package main package main
import( import (
"git.yaegashi.fr/nishiki/gpm/gpm" "git.yaegashi.fr/nishiki/gpm/gpm"
) )

View file

@ -14,16 +14,16 @@
package gpm package gpm
import( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/atotto/clipboard"
"github.com/olekukonko/tablewriter"
"golang.org/x/crypto/ssh/terminal"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv" "strconv"
"syscall" "syscall"
"github.com/atotto/clipboard"
"github.com/olekukonko/tablewriter"
"golang.org/x/crypto/ssh/terminal"
) )
// Cli contain config and wallet to use // Cli contain config and wallet to use
@ -40,7 +40,11 @@ func (c *Cli) printEntries(entries []Entry) {
tables = make(map[string]*tablewriter.Table) tables = make(map[string]*tablewriter.Table)
for i, entry := range entries { for i, entry := range entries {
if entry.OTP == "" { otp = "" } else { otp = "X" } if entry.OTP == "" {
otp = ""
} else {
otp = "X"
}
if _, present := tables[entry.Group]; present == false { if _, present := tables[entry.Group]; present == false {
tables[entry.Group] = tablewriter.NewWriter(os.Stdout) tables[entry.Group] = tablewriter.NewWriter(os.Stdout)
tables[entry.Group].SetHeader([]string{"", "Name", "URI", "User", "OTP", "Comment"}) tables[entry.Group].SetHeader([]string{"", "Name", "URI", "User", "OTP", "Comment"})
@ -54,7 +58,7 @@ func (c *Cli) printEntries(entries []Entry) {
tablewriter.Colors{tablewriter.Normal, tablewriter.FgMagentaColor}) tablewriter.Colors{tablewriter.Normal, tablewriter.FgMagentaColor})
} }
tables[entry.Group].Append([]string{ strconv.Itoa(i), entry.Name, entry.URI, entry.User, otp, entry.Comment }) tables[entry.Group].Append([]string{strconv.Itoa(i), entry.Name, entry.URI, entry.User, otp, entry.Comment})
} }
for group, table := range tables { for group, table := range tables {
@ -110,7 +114,7 @@ func (c *Cli) selectEntry() Entry {
for true { for true {
index, err := strconv.Atoi(c.input("Select the entry: ", "", true)) index, err := strconv.Atoi(c.input("Select the entry: ", "", true))
if err == nil && index >= 0 && index + 1 <= len(entries) { if err == nil && index >= 0 && index+1 <= len(entries) {
break break
} }
fmt.Println("your choice is not an integer or is out of range") fmt.Println("your choice is not an integer or is out of range")

View file

@ -14,11 +14,11 @@
package gpm package gpm
import( import (
"crypto/aes" "crypto/aes"
"crypto/sha512"
"crypto/cipher" "crypto/cipher"
"crypto/rand" "crypto/rand"
"crypto/sha512"
"encoding/base64" "encoding/base64"
"io" "io"
mrand "math/rand" mrand "math/rand"
@ -89,9 +89,15 @@ func RandomString(length int, letter bool, digit bool, special bool) string {
chars := "" chars := ""
randomString := make([]byte, length) randomString := make([]byte, length)
if letter { chars = chars + letters } if letter {
if digit { chars = chars + digits } chars = chars + letters
if special { chars = chars + specials } }
if digit {
chars = chars + digits
}
if special {
chars = chars + specials
}
if !letter && !digit && !special { if !letter && !digit && !special {
chars = digits + letters chars = digits + letters
} }

View file

@ -14,10 +14,10 @@
package gpm package gpm
import( import (
"fmt" "fmt"
"time"
"net/url" "net/url"
"time"
"github.com/pquerna/otp/totp" "github.com/pquerna/otp/totp"
) )
@ -60,7 +60,7 @@ func (e *Entry) GenerateID() {
} }
// OTPCode generate an OTP Code // OTPCode generate an OTP Code
func (e *Entry) OTPCode() (string, int64, error){ func (e *Entry) OTPCode() (string, int64, error) {
code, err := totp.GenerateCode(e.OTP, time.Now()) code, err := totp.GenerateCode(e.OTP, time.Now())
time := 30 - (time.Now().Unix() % 30) time := 30 - (time.Now().Unix() % 30)
if err != nil { if err != nil {

View file

@ -24,7 +24,7 @@ func TestCreateEntryWithoutName(t *testing.T) {
} }
func TestCreateEntryWithName(t *testing.T) { func TestCreateEntryWithName(t *testing.T) {
entry := Entry{ Name: "test" } entry := Entry{Name: "test"}
entry.GenerateID() entry.GenerateID()
err := entry.Verify() err := entry.Verify()
if err != nil { if err != nil {
@ -33,7 +33,7 @@ func TestCreateEntryWithName(t *testing.T) {
} }
func TestCreateEntryWithBadURI(t *testing.T) { func TestCreateEntryWithBadURI(t *testing.T) {
entry := Entry{ Name: "test", URI: "url/bad:" } entry := Entry{Name: "test", URI: "url/bad:"}
entry.GenerateID() entry.GenerateID()
err := entry.Verify() err := entry.Verify()
if err == nil { if err == nil {
@ -42,7 +42,7 @@ func TestCreateEntryWithBadURI(t *testing.T) {
} }
func TestCreateEntryWithGoodURI(t *testing.T) { func TestCreateEntryWithGoodURI(t *testing.T) {
entry := Entry{ Name: "test", URI: "http://localhost:8081" } entry := Entry{Name: "test", URI: "http://localhost:8081"}
entry.GenerateID() entry.GenerateID()
err := entry.Verify() err := entry.Verify()
if err != nil { if err != nil {
@ -51,7 +51,7 @@ func TestCreateEntryWithGoodURI(t *testing.T) {
} }
func TestGenerateOTPCode(t *testing.T) { func TestGenerateOTPCode(t *testing.T) {
entry := Entry{ OTP: "JBSWY3DPEHPK3PXP" } entry := Entry{OTP: "JBSWY3DPEHPK3PXP"}
code, time, err := entry.OTPCode() code, time, err := entry.OTPCode()
if err != nil { if err != nil {
t.Errorf("must generate an OTP code without error: %s", err) t.Errorf("must generate an OTP code without error: %s", err)

View file

@ -14,14 +14,14 @@
package gpm package gpm
import( import (
"fmt"
"flag" "flag"
"fmt"
"os" "os"
) )
// Options // Options
var( var (
ADD = flag.Bool("add", false, "add a new entry in the wallet") ADD = flag.Bool("add", false, "add a new entry in the wallet")
UPDATE = flag.Bool("update", false, "update an entry") UPDATE = flag.Bool("update", false, "update an entry")
DELETE = flag.Bool("delete", false, "delete an entry") DELETE = flag.Bool("delete", false, "delete an entry")

View file

@ -20,12 +20,11 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"regexp" "regexp"
"time"
"sort" "sort"
"strings" "strings"
"time"
) )
// WalletFile contains the data in file // WalletFile contains the data in file
type WalletFile struct { type WalletFile struct {
Salt string Salt string
@ -90,7 +89,7 @@ func (w *Wallet) Save() error {
return err return err
} }
walletFile := WalletFile{ Salt: w.Salt, Data: dataEncrypted } walletFile := WalletFile{Salt: w.Salt, Data: dataEncrypted}
content, err := json.Marshal(&walletFile) content, err := json.Marshal(&walletFile)
if err != nil { if err != nil {
return err return err

View file

@ -2,8 +2,8 @@ package gpm
import ( import (
"fmt" "fmt"
"os"
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
) )
@ -11,7 +11,7 @@ func generateWalletWithEntries() Wallet {
var wallet Wallet var wallet Wallet
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
entry := Entry{ ID: fmt.Sprintf("%d", i), Name: fmt.Sprintf("Entry %d", i), Group: "Good Group" } entry := Entry{ID: fmt.Sprintf("%d", i), Name: fmt.Sprintf("Entry %d", i), Group: "Good Group"}
wallet.AddEntry(entry) wallet.AddEntry(entry)
} }
@ -32,7 +32,7 @@ func TestAddEntries(t *testing.T) {
var wallet Wallet var wallet Wallet
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
entry := Entry{ ID: fmt.Sprintf("%d", i), Name: fmt.Sprintf("Entry %d", i) } entry := Entry{ID: fmt.Sprintf("%d", i), Name: fmt.Sprintf("Entry %d", i)}
err := wallet.AddEntry(entry) err := wallet.AddEntry(entry)
if err != nil { if err != nil {
t.Errorf("a good entry mustn't return an error: %s", err) t.Errorf("a good entry mustn't return an error: %s", err)