Skip to content

Commit

Permalink
Added re-signing of existing signed files.
Browse files Browse the repository at this point in the history
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
jamessan#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.
  • Loading branch information
hlein committed Oct 12, 2019
1 parent f663d0e commit 50222e1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions autoload/gnupg.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 50222e1

Please sign in to comment.