mirror of
https://github.com/Ascyii/vim-gnupg.git
synced 2026-01-01 06:14:24 -05:00
releasing gnupg.vim 2276
- added support for default recipients via the variable g:GPGDefaultRecipients. - fixed an wrong error message with symmetric encryption and set recipients (thanks to Sebastian Luettich). - create a empty new buffer on leaving vim to wipe out sensitive data on console. - make sure senisitive data is never written unencrypted to disk.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
" Name: gnupg.vim
|
" Name: gnupg.vim
|
||||||
" Version: $Id: gnupg.vim 2249 2008-07-31 11:43:14Z mbr $
|
" Version: $Id: gnupg.vim 2276 2008-08-15 12:50:33Z mbr $
|
||||||
" Author: Markus Braun <markus.braun@krawel.de>
|
" Author: Markus Braun <markus.braun@krawel.de>
|
||||||
" Summary: Vim plugin for transparent editing of gpg encrypted files.
|
" Summary: Vim plugin for transparent editing of gpg encrypted files.
|
||||||
" Licence: This program is free software; you can redistribute it and/or
|
" Licence: This program is free software; you can redistribute it and/or
|
||||||
@@ -68,6 +68,10 @@
|
|||||||
" g:GPGPreferArmor
|
" g:GPGPreferArmor
|
||||||
" If set to 1 armored data is preferred for new files. Defaults to 0.
|
" If set to 1 armored data is preferred for new files. Defaults to 0.
|
||||||
"
|
"
|
||||||
|
" g:GPGDefaultRecipients
|
||||||
|
" If set, these recipients are used as defaults when no other recipient is
|
||||||
|
" defined. This variable is a Vim list. Default is unset.
|
||||||
|
"
|
||||||
" Credits:
|
" Credits:
|
||||||
" - Mathieu Clabaut for inspirations through his vimspell.vim script.
|
" - Mathieu Clabaut for inspirations through his vimspell.vim script.
|
||||||
" - Richard Bronosky for patch to enable ".pgp" suffix.
|
" - Richard Bronosky for patch to enable ".pgp" suffix.
|
||||||
@@ -78,9 +82,11 @@
|
|||||||
" - Karl-Heinz Ruskowski for patch to fix unknown recipients and trust model
|
" - Karl-Heinz Ruskowski for patch to fix unknown recipients and trust model
|
||||||
" and patient beta testing.
|
" and patient beta testing.
|
||||||
" - Giel van Schijndel for patch to get GPG_TTY dynamically.
|
" - Giel van Schijndel for patch to get GPG_TTY dynamically.
|
||||||
|
" - Sebastian Luettich for patch to fix issue with symmetric encryption an set
|
||||||
|
" recipients.
|
||||||
"
|
"
|
||||||
" Section: Plugin header {{{1
|
" Section: Plugin header {{{1
|
||||||
if v:version < 700
|
if (v:version < 700)
|
||||||
echohl ErrorMsg | echo 'plugin gnupg.vim requires Vim version >= 7.0' | echohl None
|
echohl ErrorMsg | echo 'plugin gnupg.vim requires Vim version >= 7.0' | echohl None
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
@@ -89,7 +95,7 @@ if (exists("g:loaded_gnupg") || &cp || exists("#BufReadPre#*.\(gpg\|asc\|pgp\)")
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let g:loaded_gnupg = "$Revision: 2249 $"
|
let g:loaded_gnupg = "$Revision: 2276 $"
|
||||||
|
|
||||||
" Section: Autocmd setup {{{1
|
" Section: Autocmd setup {{{1
|
||||||
augroup GnuPG
|
augroup GnuPG
|
||||||
@@ -108,6 +114,9 @@ augroup GnuPG
|
|||||||
" undo the encryption so we are back in the normal text, directly
|
" undo the encryption so we are back in the normal text, directly
|
||||||
" after the file has been written.
|
" after the file has been written.
|
||||||
autocmd BufWritePost,FileWritePost *.\(gpg\|asc\|pgp\) call s:GPGEncryptPost()
|
autocmd BufWritePost,FileWritePost *.\(gpg\|asc\|pgp\) call s:GPGEncryptPost()
|
||||||
|
|
||||||
|
" cleanup on leaving vim
|
||||||
|
autocmd VimLeave *.\(gpg\|asc\|pgp\) call s:GPGCleanup()
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" Section: Highlight setup {{{1
|
" Section: Highlight setup {{{1
|
||||||
@@ -148,6 +157,11 @@ function s:GPGInit()
|
|||||||
let g:GPGPreferArmor = 0
|
let g:GPGPreferArmor = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" check if debugging is turned on
|
||||||
|
if (!exists("g:GPGDefaultRecipients"))
|
||||||
|
let g:GPGDefaultRecipients = []
|
||||||
|
endif
|
||||||
|
|
||||||
" check if debugging is turned on
|
" check if debugging is turned on
|
||||||
if (!exists("g:GPGDebugLevel"))
|
if (!exists("g:GPGDebugLevel"))
|
||||||
let g:GPGDebugLevel = 0
|
let g:GPGDebugLevel = 0
|
||||||
@@ -176,7 +190,7 @@ function s:GPGInit()
|
|||||||
" don't use tty in gvim
|
" don't use tty in gvim
|
||||||
" FIXME find a better way to avoid an error.
|
" FIXME find a better way to avoid an error.
|
||||||
" with this solution only --use-agent will work
|
" with this solution only --use-agent will work
|
||||||
if has("gui_running")
|
if (has("gui_running"))
|
||||||
let s:GPGCommand = s:GPGCommand . " --no-tty"
|
let s:GPGCommand = s:GPGCommand . " --no-tty"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -209,6 +223,16 @@ function s:GPGInit()
|
|||||||
let s:GPGCompress = substitute(output, ".*Compress: \\(.\\{-}\\)\n.*", "\\1", "")
|
let s:GPGCompress = substitute(output, ".*Compress: \\(.\\{-}\\)\n.*", "\\1", "")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Function: s:GPGCleanup() {{{2
|
||||||
|
"
|
||||||
|
" cleanup on leaving vim
|
||||||
|
"
|
||||||
|
function s:GPGCleanup()
|
||||||
|
" wipe out screen
|
||||||
|
new +only
|
||||||
|
redraw!
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGDecrypt() {{{2
|
" Function: s:GPGDecrypt() {{{2
|
||||||
"
|
"
|
||||||
" decrypt the buffer and find all recipients of the encrypted file
|
" decrypt the buffer and find all recipients of the encrypted file
|
||||||
@@ -334,7 +358,7 @@ function s:GPGEncrypt()
|
|||||||
call s:GPGDebug(2, "saved window view " . string(s:GPGWindowView))
|
call s:GPGDebug(2, "saved window view " . string(s:GPGWindowView))
|
||||||
|
|
||||||
" store encoding and switch to a safe one
|
" store encoding and switch to a safe one
|
||||||
if &fileencoding != &encoding
|
if (&fileencoding != &encoding)
|
||||||
let s:GPGEncoding = &encoding
|
let s:GPGEncoding = &encoding
|
||||||
let &encoding = &fileencoding
|
let &encoding = &fileencoding
|
||||||
call s:GPGDebug(2, "encoding was \"" . s:GPGEncoding . "\", switched to \"" . &encoding . "\"")
|
call s:GPGDebug(2, "encoding was \"" . s:GPGEncoding . "\", switched to \"" . &encoding . "\"")
|
||||||
@@ -359,6 +383,7 @@ function s:GPGEncrypt()
|
|||||||
let b:GPGOptions = []
|
let b:GPGOptions = []
|
||||||
if (exists("g:GPGPreferSymmetric") && g:GPGPreferSymmetric == 1)
|
if (exists("g:GPGPreferSymmetric") && g:GPGPreferSymmetric == 1)
|
||||||
let b:GPGOptions += ["symmetric"]
|
let b:GPGOptions += ["symmetric"]
|
||||||
|
let b:GPGRecipients = []
|
||||||
else
|
else
|
||||||
let b:GPGOptions += ["encrypt"]
|
let b:GPGOptions += ["encrypt"]
|
||||||
endif
|
endif
|
||||||
@@ -411,11 +436,13 @@ function s:GPGEncrypt()
|
|||||||
let &shell = s:shellsave
|
let &shell = s:shellsave
|
||||||
call s:GPGDebug(1, "called gpg command is: " . "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . " " . s:stderrredirnull)
|
call s:GPGDebug(1, "called gpg command is: " . "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . " " . s:stderrredirnull)
|
||||||
if (v:shell_error) " message could not be encrypted
|
if (v:shell_error) " message could not be encrypted
|
||||||
silent u
|
" delete content of the buffer to be sure no data is written unencrypted
|
||||||
|
" content will be recovered in GPGEncryptPost()
|
||||||
|
silent normal! 1GdG
|
||||||
|
|
||||||
echohl GPGError
|
echohl GPGError
|
||||||
let blackhole = input("Message could not be encrypted! File might be empty! (Press ENTER)")
|
let blackhole = input("Message could not be encrypted! File might be empty! (Press ENTER)")
|
||||||
echohl None
|
echohl None
|
||||||
bwipeout
|
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -438,7 +465,7 @@ function s:GPGEncryptPost()
|
|||||||
set nobin
|
set nobin
|
||||||
|
|
||||||
" restore encoding
|
" restore encoding
|
||||||
if s:GPGEncoding != ""
|
if (s:GPGEncoding != "")
|
||||||
let &encoding = s:GPGEncoding
|
let &encoding = s:GPGEncoding
|
||||||
call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"")
|
call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"")
|
||||||
endif
|
endif
|
||||||
@@ -554,6 +581,17 @@ function s:GPGEditRecipients()
|
|||||||
" get the recipients
|
" get the recipients
|
||||||
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(getbufvar(b:GPGCorrespondingTo, "GPGRecipients"))
|
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(getbufvar(b:GPGCorrespondingTo, "GPGRecipients"))
|
||||||
|
|
||||||
|
" if there are no known or unknown recipients, use the default ones
|
||||||
|
if (len(recipients) == 0 && len(unknownrecipients) == 0)
|
||||||
|
if (type(g:GPGDefaultRecipients) == type([]))
|
||||||
|
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(g:GPGDefaultRecipients)
|
||||||
|
else
|
||||||
|
echohl GPGWarning
|
||||||
|
echom "g:GPGDefaultRecipients is not a Vim list, please correct this in your vimrc!"
|
||||||
|
echohl None
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
" put the recipients in the scratch buffer
|
" put the recipients in the scratch buffer
|
||||||
for name in recipients
|
for name in recipients
|
||||||
let name = s:GPGIDToName(name)
|
let name = s:GPGIDToName(name)
|
||||||
@@ -635,7 +673,7 @@ function s:GPGFinishRecipientsBuffer()
|
|||||||
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
||||||
echohl None
|
echohl None
|
||||||
endif
|
endif
|
||||||
end
|
endif
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
@@ -859,7 +897,7 @@ function s:GPGNameToID(name)
|
|||||||
|
|
||||||
" when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8,
|
" when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8,
|
||||||
" so convert it, if necessary
|
" so convert it, if necessary
|
||||||
if &encoding != "utf-8"
|
if (&encoding != "utf-8")
|
||||||
let output = iconv(output, "utf-8", &encoding)
|
let output = iconv(output, "utf-8", &encoding)
|
||||||
endif
|
endif
|
||||||
let lines = split(output, "\n")
|
let lines = split(output, "\n")
|
||||||
@@ -927,7 +965,7 @@ function s:GPGIDToName(identity)
|
|||||||
|
|
||||||
" when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8,
|
" when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8,
|
||||||
" so convert it, if necessary
|
" so convert it, if necessary
|
||||||
if &encoding != "utf-8"
|
if (&encoding != "utf-8")
|
||||||
let output = iconv(output, "utf-8", &encoding)
|
let output = iconv(output, "utf-8", &encoding)
|
||||||
endif
|
endif
|
||||||
let lines = split(output, "\n")
|
let lines = split(output, "\n")
|
||||||
@@ -968,7 +1006,7 @@ command! GPGEditRecipients call s:GPGEditRecipients()
|
|||||||
command! GPGViewOptions call s:GPGViewOptions()
|
command! GPGViewOptions call s:GPGViewOptions()
|
||||||
command! GPGEditOptions call s:GPGEditOptions()
|
command! GPGEditOptions call s:GPGEditOptions()
|
||||||
" Section: Menu {{{1
|
" Section: Menu {{{1
|
||||||
if has("menu")
|
if (has("menu"))
|
||||||
amenu <silent> Plugin.GnuPG.View\ Recipients :GPGViewRecipients<CR>
|
amenu <silent> Plugin.GnuPG.View\ Recipients :GPGViewRecipients<CR>
|
||||||
amenu <silent> Plugin.GnuPG.Edit\ Recipients :GPGEditRecipients<CR>
|
amenu <silent> Plugin.GnuPG.Edit\ Recipients :GPGEditRecipients<CR>
|
||||||
amenu <silent> Plugin.GnuPG.View\ Options :GPGViewOptions<CR>
|
amenu <silent> Plugin.GnuPG.View\ Options :GPGViewOptions<CR>
|
||||||
|
|||||||
Reference in New Issue
Block a user