diff options
| author | ishaan <contact@ishaan.cc> | 2026-07-14 19:26:55 +0530 |
|---|---|---|
| committer | ishaan <contact@ishaan.cc> | 2026-07-14 19:26:55 +0530 |
| commit | 6c6c4a05267e93597bb009c7d6c36383b6af7bf7 (patch) | |
| tree | 4c2c85b78b07e877ca18e833d07e8624712e8a4c /internal/utils | |
| parent | 9eb2b774e9f0522a3547644453bf929dd560f05f (diff) | |
ssh
Diffstat (limited to 'internal/utils')
| -rw-r--r-- | internal/utils/utils.go | 37 |
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 +} |