From 4d49c0782aa8ef1c0df9547474ca8e0834a00787 Mon Sep 17 00:00:00 2001 From: ishaan Date: Tue, 14 Jul 2026 19:45:27 +0530 Subject: fix can't edit when no personal key --- internal/crud/cli_new.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'internal/crud/cli_new.go') diff --git a/internal/crud/cli_new.go b/internal/crud/cli_new.go index c8303a0..cd06455 100644 --- a/internal/crud/cli_new.go +++ b/internal/crud/cli_new.go @@ -230,7 +230,7 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { tmptxt := []byte(string(utils.RandomLettersNumbers(37))+"\nYou can Delete all of this ^^^") - encrypted, err := crypt.EncryptBytesSSH(tmptxt, pubKeys) + encrypted, _, err := crypt.EncryptBytesSSH(tmptxt, pubKeys) if err != nil { return err } @@ -327,10 +327,12 @@ func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath preExisting := err == nil initialContent := []byte(string(utils.RandomLettersNumbers(37)) + "\nYou can Delete all of this ^^^") - encrypted, err := crypt.EncryptBytesSSH(initialContent, pubKeys) + encrypted, noteKey, err := crypt.EncryptBytesSSH(initialContent, pubKeys) if err != nil { return err } + crypt.TryMlock(noteKey) + defer clear(noteKey) file, err := os.Create(output) if err != nil { @@ -355,7 +357,12 @@ func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath return err } - plaintext, err := crypt.DecryptBytesSSH(ciphertext, defaultPrivKeyPath) + var plaintext []byte + if useDefault { + plaintext, err = crypt.DecryptBytesSSH(ciphertext, defaultPrivKeyPath) + } else { + plaintext, err = crypt.DecryptBytesSSHWithKey(ciphertext, noteKey) + } if err != nil { return err } @@ -384,7 +391,7 @@ func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath os.WriteFile(tmpFile.Name(), make([]byte, len(newContent)), 0600) - encrypted, err = crypt.EncryptBytesSSH(newContent, pubKeys) + encrypted, _, err = crypt.EncryptBytesSSH(newContent, pubKeys) if err != nil { return err } -- cgit v1.3