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
45 changes: 2 additions & 43 deletions cmd/lyra/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"errors"
"flag"

"github.com/azohra/lyra/pkg/lcrypt"
"github.com/azohra/lyra/pkg/lfile"
"github.com/azohra/lyra/internal/pkg/encryption"
)

const (
Expand Down Expand Up @@ -93,7 +92,7 @@ func (cmd *decryptcmd) Run(opt []string) error {
cmd.passphrase = string(getPassphrase())
}

err = decrypt(opt[0], cmd.path, cmd.printOnly, []byte(cmd.passphrase))
err = encryption.Decrypt(opt[0], cmd.path, cmd.printOnly, []byte(cmd.passphrase))
cmd.passphrase = ""

return err
Expand All @@ -106,43 +105,3 @@ func (cmd *decryptcmd) validateInputs() error {

return nil
}

//decrypt encrypts file file and overides the content of file with the ciphertext
//of the specified plaintext file.
func decrypt(file, saveTo string, print bool, passphrase []byte) error {
ctFile, err := lfile.NewParsedSLFile(file)
if err != nil {
return err
}

key, err := lcrypt.NewLKey(passphrase, ctFile.RetrieveSalt())
if err != nil {
return err
}

ptFile, err := ctFile.DecipherFile(key)
if err != nil {
return err
}

if saveTo == "" && !print {
err = ptFile.Write(file)
} else if saveTo != "" && !print {
err = ptFile.Write(saveTo)
}

if err != nil {
return err
}

if print {
ptFile.PrintLyraFile()
}

err = key.DestroyKey()
if err != nil {
handleErr(err)
}

return nil
}
9 changes: 0 additions & 9 deletions cmd/lyra/decrypt_test.go

This file was deleted.

42 changes: 3 additions & 39 deletions cmd/lyra/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"fmt"
"os"

"github.com/azohra/lyra/pkg/lcrypt"
"github.com/azohra/lyra/pkg/lfile"
"github.com/azohra/lyra/internal/pkg/encryption"
"github.com/brsmsn/gware/pkg/diceware"
)

Expand Down Expand Up @@ -38,7 +37,7 @@ lyra encrypt --gen-str file

Encrypts and overides file (user specified file) with an auto generated passphrase
and outputs the auto generated passphrase to stdout.
Auto generaates a 7 word passphrase in kebab case (no spaces).
Auto generates a 7 word passphrase in kebab case (no spaces).

lyra encrypt -p "mypassphrase" file

Expand Down Expand Up @@ -138,7 +137,7 @@ func (cmd *encryptcmd) Run(opt []string) error {
cmd.passphrase = string(input)
}

err = encrypt(opt[0], cmd.path, []byte(cmd.passphrase))
err = encryption.Encrypt(opt[0], cmd.path, []byte(cmd.passphrase))
if err != nil {
return err
}
Expand All @@ -159,41 +158,6 @@ func (cmd *encryptcmd) validateInputs() error {
return nil
}

//encrypt encrypts file file and overides the content of file with the ciphertext
//of the specified plaintext file.
func encrypt(file, saveTo string, passphrase []byte) error {
ptFile, err := lfile.NewParsedLyraFile(file)
if err != nil {
return err
}

key, err := lcrypt.NewLKey(passphrase, nil)
if err != nil {
return err
}

ctFile, err := ptFile.EncipherFile(key)
if err != nil {
return err
}

switch saveTo {
case "":
err = ctFile.Write(file)
default:
err = ctFile.Write(saveTo)
}
if err != nil {
return err
}
err = key.DestroyKey()
if err != nil {
return err
}

return nil
}

//gen a diceware passphrase using eff long wordlist
func (cmd *encryptcmd) genPass() error {

Expand Down
10 changes: 0 additions & 10 deletions cmd/lyra/encrypt_test.go

This file was deleted.

Loading