aboutsummaryrefslogtreecommitdiff
path: root/internal/utils
diff options
context:
space:
mode:
Diffstat (limited to 'internal/utils')
-rw-r--r--internal/utils/utils.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/utils/utils.go b/internal/utils/utils.go
index a8437b9..cea00a3 100644
--- a/internal/utils/utils.go
+++ b/internal/utils/utils.go
@@ -5,9 +5,11 @@ import (
"fmt"
"os"
"os/signal"
+ "strconv"
"syscall"
"github.com/charmbracelet/x/term"
+ "gitlab.com/whiteboardguy/eno/internal/crypt"
)
func TakeSecureUserInput() ([]byte, error) {
@@ -63,3 +65,38 @@ func RandomLettersNumbers(n int) []byte {
}
return b
}
+
+func CheckFileAuthMode(notePath string) (crypt.AuthMode, error) {
+ data, err := os.ReadFile(notePath)
+ if err != nil {
+ return "", fmt.Errorf("failed to read file: %w", err)
+ }
+
+ idx := -1
+ for i, b := range data {
+ if b == ':' {
+ idx = i
+ break
+ }
+ }
+ if idx == -1 {
+ return "", fmt.Errorf("invalid file format: no header length prefix found")
+ }
+
+ headerLen, err := strconv.Atoi(string(data[:idx]))
+ if err != nil {
+ return "", fmt.Errorf("failed to parse header length: %w", err)
+ }
+
+ if headerLen < 0 || idx+1+headerLen > len(data) {
+ return "", fmt.Errorf("invalid header length %d", headerLen)
+ }
+
+ headerBytes := data[idx+1 : idx+1+headerLen]
+ headers, err := crypt.GetFileHeaders(headerBytes)
+ if err != nil {
+ return "", fmt.Errorf("failed to decode headers: %w", err)
+ }
+
+ return headers.Auth, nil
+}