From 6c6c4a05267e93597bb009c7d6c36383b6af7bf7 Mon Sep 17 00:00:00 2001 From: ishaan Date: Tue, 14 Jul 2026 19:26:55 +0530 Subject: ssh --- internal/utils/utils.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'internal/utils/utils.go') 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 +} -- cgit v1.3