Skip to content

Commit

Permalink
add -confirm-key option
Browse files Browse the repository at this point in the history
  • Loading branch information
notwithering committed Jul 27, 2024
1 parent 40bd56b commit 91e6f4b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
31 changes: 30 additions & 1 deletion choice.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,43 @@ chooseKey:
fmt.Print("\n")
default:
key = hash([]byte(in))

memory.Zero(&in)

if confirmKey {
fmt.Print(eviInput)

in, err := line(true)
if err != nil {
fmt.Printf(eviError, err)
os.Exit(1)
}

confirmedKey := hash([]byte(in))
memory.Zero(&in)

if !keysMatch(key, confirmedKey) {
fmt.Printf(eviError, "keys do not match")
os.Exit(1)
}
}

break chooseKey
}
}
}

func keysMatch(key, confirmedKey []byte) bool {
if len(key) != len(confirmedKey) {
return false
}
for i, b := range key {
if b != confirmedKey[i] {
return false
}
}
return true
}

func removeFile() {
fmt.Printf(eviInfo, "Remove file? [y/N]")
fmt.Print(eviInput)
Expand Down
25 changes: 15 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@ import (
)

var (
noDecrypt bool
noEdit bool
noEncrypt bool
confirmKey bool
noDecrypt bool
noEdit bool
noEncrypt bool
)

func main() {
var keyFlag string
flag.StringVar(&keyFlag, "key", "", "")
flag.StringVar(&keyFlag, "k", "", "")
flag.BoolVar(&confirmKey, "confirm-key", confirmKey, "")
flag.BoolVar(&confirmKey, "c", confirmKey, "")

flag.StringVar(&keyFlag, "key", keyFlag, "")
flag.StringVar(&keyFlag, "k", keyFlag, "")

flag.BoolVar(&noDecrypt, "no-decrypt", noDecrypt, "")
flag.BoolVar(&noEdit, "no-edit", noEdit, "")
flag.BoolVar(&noEncrypt, "no-encrypt", noEncrypt, "")

flag.Usage = func() {
fmt.Println("Usage: evi [options...] <file>")
fmt.Println(" -h, -help Show this help menu")
fmt.Println(" -k, -key Preset the encryption key")
fmt.Println(" -no-decrypt Stop the program from decrypting the file")
fmt.Println(" -no-edit Stop the program from opening the editor")
fmt.Println(" -no-encrypt Stop the program from re-encrypting the file")
fmt.Println(" -c, -confirm-key Program asks for key twice")
fmt.Println(" -h, -help Show this help menu")
fmt.Println(" -k, -key Preset the encryption key")
fmt.Println(" -no-decrypt Stop the program from decrypting the file")
fmt.Println(" -no-edit Stop the program from opening the editor")
fmt.Println(" -no-encrypt Stop the program from re-encrypting the file")
}

flag.Parse()
Expand Down

0 comments on commit 91e6f4b

Please sign in to comment.