-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added re-signing of existing signed files. #108
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would ensure that we only change the option for this buffer, instead of overriding the user's choice for all buffers just because this one file is signed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, per-buffer sure sounds better than my method. I think at one or two places I wasn't sure if it was safe to edit b:GPGOptions yet, because gnupg might be invoked for something else prior to encrypt-to-save (i.e. if another gpg -d were done, including --sign would be a usage error). If you are sure it's safe/appropriate to do there - then +1 for sure! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
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 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change isn't necessary with the above suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well... As a user, I want a way to say that any file I edit should get signed when I save it, even if the original was not signed. When I read of the g:GPGPreferSign option, that's initially what I expected it to do. Perhaps there should be a g:GPGAlwaysSign that behaves that way? (In fact I think I started to add a g:GPGAlwaysSign, then thought it was redundant. But maybe not?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then you probably want to add something like this to your vimrc: autocmd User GnuPG if index(b:GPGOptions, 'sign') == -1 | call add(b:GPGOptions, 'sign') | endif There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, nice, I will try that! (And sorry this has veered into stupid user questions ;) |
||||||||
if (exists("g:GPGPreferSign") && g:GPGPreferSign == 1) | ||||||||
let b:GPGOptions += ["sign"] | ||||||||
endif | ||||||||
|
||||||||
" built list of options | ||||||||
let options = "" | ||||||||
for option in b:GPGOptions | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that the man page describes this option as such (emphasis added):
It'd be nice if there was a more stable way to get this information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, yes that is unfortunate.
Hm, often "use --status-fd" is recommended. So as a quick test:
I don't know how well that redirection would play with s:GPGSystem, might need a separate helper for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like more motivation for me to finally move to using jobs/channels, loopback pinentry, etc. so I can get more fine-grained information out of gpg, as well as supporting nvim.