aboutsummaryrefslogtreecommitdiff
path: root/internal/crud/cli_new.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-14 19:45:27 +0530
committerishaan <contact@ishaan.cc>2026-07-14 19:45:27 +0530
commit4d49c0782aa8ef1c0df9547474ca8e0834a00787 (patch)
tree261705b8e786dec67fa8efa1055369a75550dd9b /internal/crud/cli_new.go
parent6c6c4a05267e93597bb009c7d6c36383b6af7bf7 (diff)
fix can't edit when no personal key
Diffstat (limited to 'internal/crud/cli_new.go')
-rw-r--r--internal/crud/cli_new.go15
1 files changed, 11 insertions, 4 deletions
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
}