aboutsummaryrefslogtreecommitdiff
path: root/cmd/eno/cobra_decrypt.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/eno/cobra_decrypt.go')
-rw-r--r--cmd/eno/cobra_decrypt.go34
1 files changed, 20 insertions, 14 deletions
diff --git a/cmd/eno/cobra_decrypt.go b/cmd/eno/cobra_decrypt.go
index 262816e..df81f22 100644
--- a/cmd/eno/cobra_decrypt.go
+++ b/cmd/eno/cobra_decrypt.go
@@ -15,10 +15,11 @@ var decryptCmd = &cobra.Command{
Use: "decrypt <file>",
Short: "decrypt a file",
Args: cobra.ExactArgs(1),
- RunE: func(cmd *cobra.Command, args []string) error {
+ Run: func(cmd *cobra.Command, args []string) {
output, err := cmd.Flags().GetString("output")
if err != nil {
- return fmt.Errorf("failed to get output flag: %v", err)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
}
if output == "" {
@@ -28,26 +29,31 @@ var decryptCmd = &cobra.Command{
if _, err := os.Stat(output); err == nil {
ok, err := utils.AskUserYesNo("file '"+output+"' already exists. Overwrite?", false)
if err != nil {
- return err
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
}
if !ok {
- return fmt.Errorf("write aborted")
+ cmd.PrintErrln("Error: write aborted")
+ os.Exit(1)
}
}
fileBytes, err := os.ReadFile(args[0])
if err != nil {
- return fmt.Errorf("failed to read input file: %v", err)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
}
authMode, err := utils.CheckFileAuthMode(args[0])
if err != nil {
- return fmt.Errorf("failed to check auth mode: %v", err)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
}
if authMode == crypt.SSH {
if config.Conf.DefaultSSHPrivPath == "" {
- return fmt.Errorf("SSH not configured. Run 'eno ssh init' first")
+ cmd.PrintErrln("Error: SSH not configured. Run 'eno ssh init' first")
+ os.Exit(1)
}
plaintext, err := crypt.DecryptBytesSSH(fileBytes, config.Conf.DefaultSSHPrivPath)
if err != nil {
@@ -58,23 +64,24 @@ var decryptCmd = &cobra.Command{
defer clear(plaintext)
if err := os.WriteFile(output, plaintext, 0600); err != nil {
- return fmt.Errorf("failed to write output file: %v", err)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
}
- return nil
+ return
}
fmt.Printf("Enter the passphrase: ")
password, err := utils.TakeSecureUserInput()
if err != nil {
- return fmt.Errorf("failed to read passphrase: %v", err)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
}
crypt.TryMlock(password)
defer clear(password)
plaintext, err := crypt.DecryptBytesPass(fileBytes, password)
if err != nil {
- clear(password)
cmd.PrintErrln("Error:", err)
os.Exit(1)
}
@@ -82,9 +89,8 @@ var decryptCmd = &cobra.Command{
defer clear(plaintext)
if err := os.WriteFile(output, plaintext, 0600); err != nil {
- return fmt.Errorf("failed to write output file: %v", err)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
}
-
- return nil
},
}