aboutsummaryrefslogtreecommitdiff
path: root/internal/crud/raw_Decrypt.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-12 08:11:50 +0530
committerishaan <contact@ishaan.cc>2026-07-12 08:11:50 +0530
commit777497ec7972d60621dc2ec42495aa73c77dfa41 (patch)
treeb11e147f1feb35d612a84a2d624899c1b42ab23c /internal/crud/raw_Decrypt.go
parente9f777d8f7b8b77993f0b88032c33bbef06959c0 (diff)
go the go
Diffstat (limited to 'internal/crud/raw_Decrypt.go')
-rw-r--r--internal/crud/raw_Decrypt.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/internal/crud/raw_Decrypt.go b/internal/crud/raw_Decrypt.go
index 155ac85..ae94bef 100644
--- a/internal/crud/raw_Decrypt.go
+++ b/internal/crud/raw_Decrypt.go
@@ -2,6 +2,7 @@ package crud
import (
"fmt"
+ "log/slog"
"os"
"strconv"
"strings"
@@ -26,14 +27,14 @@ func RawDecryptFile(inputFile, outputFile string) {
fmt.Scanln(&overwriteConfirm)
if overwriteConfirm != "y" && overwriteConfirm != "Y" {
- fmt.Fprintln(os.Stderr, "write aborted")
+ slog.Error("write aborted")
os.Exit(1)
}
}
fileBytes, err := os.ReadFile(inputFile)
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
+ slog.Error("failed to read input file", "error", err)
os.Exit(1)
}
@@ -47,25 +48,25 @@ func RawDecryptFile(inputFile, outputFile string) {
headerLen, err := getUInt32FromBytes(fileBytes[:idx])
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
+ slog.Error("failed to parse header length", "error", err)
os.Exit(1)
}
headerBytes := fileBytes[idx+1 : idx+1+int(headerLen)]
headers := GetFileHeaders(headerBytes)
- fmt.Println(headers)
+ slog.Debug("file headers", "headers", headers)
fmt.Printf("Enter the super secure passphrase: ")
password, err := utils.TakeSecureUserInput()
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
+ slog.Error("failed to read passphrase", "error", err)
os.Exit(1)
}
key := argon2.IDKey(password, headers.Salt[:], 1, 2*1024*1024, 2, 32)
aead, err := chacha20poly1305.New(key)
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
+ slog.Error("failed to create cipher", "error", err)
os.Exit(1)
}
@@ -75,14 +76,14 @@ func RawDecryptFile(inputFile, outputFile string) {
plaintext, err := aead.Open(nil, nonce[:], ciphertext, nil)
if err != nil {
if strings.Contains(err.Error(), "message authentication failed") {
- fmt.Fprintln(os.Stderr, "wrong password or corrupted data")
+ slog.Error("wrong password or corrupted data")
os.Exit(1)
}
panic(err)
}
if err := os.WriteFile(outputFile, plaintext, 0644); err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
+ slog.Error("failed to write output file", "error", err)
os.Exit(1)
}
}