From 50222e13306dd4881c6cf48eb32d78a0d1f605a8 Mon Sep 17 00:00:00 2001 From: Hank Leininger Date: Fri, 11 Oct 2019 19:31:55 -0600 Subject: [PATCH] Added re-signing of existing signed files. When editing an existing file, check if the source file was signed, and if so, enable signing when we save it. When writing out a file, moved the "should we sign" check so that it always happens. When saving an existing file, b:GPGOptions exists already, so g:GPGPreferSign was not being checked previously. This partially addresses https://github.com/jamessan/vim-gnupg/issues/34 If we wanted to support selecting between different private keys to sign with, then checking _which_ key had signed a file and looking for a corresponding private key in our keyring could be done in the --list-packets check. But that is another future issue & PR. --- autoload/gnupg.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/autoload/gnupg.vim b/autoload/gnupg.vim index 9a91ed0..e3cfaac 100644 --- a/autoload/gnupg.vim +++ b/autoload/gnupg.vim @@ -368,6 +368,16 @@ function gnupg#decrypt(bufread) end let start = match(output, asymmPattern, start) endwhile + + " determine if the file was signed; if so, we will too + let cmd = { 'level': 3 } + let cmd.args = '--list-packets ' . s:shellescape(filename, { 'cygpath': 1 }) + let output = s:GPGSystem(cmd) + + if (matchstr(output, "^:\(onepass_sig\|signature\) packet:") >= 0) + let g:GPGPreferSign = 1 + endif + else " file is not encrypted let b:GPGEncrypted = 0 @@ -509,12 +519,14 @@ function gnupg#encrypt() if (preferArmor >= 0 && preferArmor) || filename =~ '\.asc$' let b:GPGOptions += ["armor"] endif - if (exists("g:GPGPreferSign") && g:GPGPreferSign == 1) - let b:GPGOptions += ["sign"] - endif call s:GPGDebug(1, "no options set, so using default options: " . string(b:GPGOptions)) endif + " check if we should sign this file + if (exists("g:GPGPreferSign") && g:GPGPreferSign == 1) + let b:GPGOptions += ["sign"] + endif + " built list of options let options = "" for option in b:GPGOptions