style: change space to tab for goreport
This commit is contained in:
parent
30ada1a1fc
commit
3f9d4850b6
13 changed files with 853 additions and 842 deletions
|
@ -17,6 +17,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|||
- Export in a file
|
||||
- Use RandomString function for wallet's salt
|
||||
- Search is case insensite
|
||||
- change space to tab for goreport
|
||||
|
||||
## v1.1.0 - 2019-07-23
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
# gpm: Go Passwords Manager
|
||||
|
||||
[![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)
|
||||
[![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
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package main
|
||||
|
||||
import(
|
||||
import (
|
||||
"git.yaegashi.fr/nishiki/gpm/gpm"
|
||||
)
|
||||
|
||||
|
|
18
gpm/cli.go
18
gpm/cli.go
|
@ -14,16 +14,16 @@
|
|||
|
||||
package gpm
|
||||
|
||||
import(
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
// Cli contain config and wallet to use
|
||||
|
@ -40,7 +40,11 @@ func (c *Cli) printEntries(entries []Entry) {
|
|||
tables = make(map[string]*tablewriter.Table)
|
||||
|
||||
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 {
|
||||
tables[entry.Group] = tablewriter.NewWriter(os.Stdout)
|
||||
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})
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -110,7 +114,7 @@ func (c *Cli) selectEntry() Entry {
|
|||
|
||||
for 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
|
||||
}
|
||||
fmt.Println("your choice is not an integer or is out of range")
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
package gpm
|
||||
|
||||
import(
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/sha512"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
mrand "math/rand"
|
||||
|
@ -89,9 +89,15 @@ func RandomString(length int, letter bool, digit bool, special bool) string {
|
|||
chars := ""
|
||||
randomString := make([]byte, length)
|
||||
|
||||
if letter { chars = chars + letters }
|
||||
if digit { chars = chars + digits }
|
||||
if special { chars = chars + specials }
|
||||
if letter {
|
||||
chars = chars + letters
|
||||
}
|
||||
if digit {
|
||||
chars = chars + digits
|
||||
}
|
||||
if special {
|
||||
chars = chars + specials
|
||||
}
|
||||
if !letter && !digit && !special {
|
||||
chars = digits + letters
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
package gpm
|
||||
|
||||
import(
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/pquerna/otp/totp"
|
||||
)
|
||||
|
@ -60,7 +60,7 @@ func (e *Entry) GenerateID() {
|
|||
}
|
||||
|
||||
// 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())
|
||||
time := 30 - (time.Now().Unix() % 30)
|
||||
if err != nil {
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestCreateEntryWithoutName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateEntryWithName(t *testing.T) {
|
||||
entry := Entry{ Name: "test" }
|
||||
entry := Entry{Name: "test"}
|
||||
entry.GenerateID()
|
||||
err := entry.Verify()
|
||||
if err != nil {
|
||||
|
@ -33,7 +33,7 @@ func TestCreateEntryWithName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateEntryWithBadURI(t *testing.T) {
|
||||
entry := Entry{ Name: "test", URI: "url/bad:" }
|
||||
entry := Entry{Name: "test", URI: "url/bad:"}
|
||||
entry.GenerateID()
|
||||
err := entry.Verify()
|
||||
if err == nil {
|
||||
|
@ -42,7 +42,7 @@ func TestCreateEntryWithBadURI(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()
|
||||
err := entry.Verify()
|
||||
if err != nil {
|
||||
|
@ -51,7 +51,7 @@ func TestCreateEntryWithGoodURI(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGenerateOTPCode(t *testing.T) {
|
||||
entry := Entry{ OTP: "JBSWY3DPEHPK3PXP" }
|
||||
entry := Entry{OTP: "JBSWY3DPEHPK3PXP"}
|
||||
code, time, err := entry.OTPCode()
|
||||
if err != nil {
|
||||
t.Errorf("must generate an OTP code without error: %s", err)
|
||||
|
|
|
@ -14,14 +14,14 @@
|
|||
|
||||
package gpm
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Options
|
||||
var(
|
||||
var (
|
||||
ADD = flag.Bool("add", false, "add a new entry in the wallet")
|
||||
UPDATE = flag.Bool("update", false, "update an entry")
|
||||
DELETE = flag.Bool("delete", false, "delete an entry")
|
||||
|
|
|
@ -20,12 +20,11 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"time"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
// WalletFile contains the data in file
|
||||
type WalletFile struct {
|
||||
Salt string
|
||||
|
@ -90,7 +89,7 @@ func (w *Wallet) Save() error {
|
|||
return err
|
||||
}
|
||||
|
||||
walletFile := WalletFile{ Salt: w.Salt, Data: dataEncrypted }
|
||||
walletFile := WalletFile{Salt: w.Salt, Data: dataEncrypted}
|
||||
content, err := json.Marshal(&walletFile)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -2,8 +2,8 @@ package gpm
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -11,7 +11,7 @@ func generateWalletWithEntries() Wallet {
|
|||
var wallet Wallet
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ func TestAddEntries(t *testing.T) {
|
|||
var wallet Wallet
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
t.Errorf("a good entry mustn't return an error: %s", err)
|
||||
|
|
Loading…
Reference in a new issue