Get rid of b:GPGUnknownRecipients
Introduce s:GPGCheckRecipients() and do _always_ check the recipients before using them.
This commit is contained in:
parent
71645fcb3a
commit
eebc52cbe1
101
plugin/gnupg.vim
101
plugin/gnupg.vim
@ -206,10 +206,9 @@ function s:GPGDecrypt()
|
|||||||
" get the filename of the current buffer
|
" get the filename of the current buffer
|
||||||
let filename=escape(expand("%:p"), '\"')
|
let filename=escape(expand("%:p"), '\"')
|
||||||
|
|
||||||
" clear GPGEncrypted, GPGRecipients, GPGUnknownRecipients and GPGOptions
|
" clear GPGEncrypted, GPGRecipients and GPGOptions
|
||||||
let b:GPGEncrypted=0
|
let b:GPGEncrypted=0
|
||||||
let b:GPGRecipients=[]
|
let b:GPGRecipients=[]
|
||||||
let b:GPGUnknownRecipients=[]
|
|
||||||
let b:GPGOptions=[]
|
let b:GPGOptions=[]
|
||||||
|
|
||||||
" find the recipients of the file
|
" find the recipients of the file
|
||||||
@ -258,7 +257,7 @@ function s:GPGDecrypt()
|
|||||||
let b:GPGRecipients+=[name]
|
let b:GPGRecipients+=[name]
|
||||||
call s:GPGDebug(1, "name of recipient is " . name)
|
call s:GPGDebug(1, "name of recipient is " . name)
|
||||||
else
|
else
|
||||||
let b:GPGUnknownRecipients+=[recipient]
|
let b:GPGRecipients+=[recipient]
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
||||||
echohl None
|
echohl None
|
||||||
@ -362,37 +361,10 @@ function s:GPGEncrypt()
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
" check here again if all recipients are available in the keyring
|
" check here again if all recipients are available in the keyring
|
||||||
let recipients = []
|
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(b:GPGRecipients)
|
||||||
if (exists("b:GPGRecipients") && type(b:GPGRecipients) == type([]))
|
|
||||||
let recipients += b:GPGRecipients
|
|
||||||
else
|
|
||||||
unlet b:GPGRecipients
|
|
||||||
endif
|
|
||||||
if (exists("b:GPGUnknownRecipients") && type(b:GPGUnknownRecipients) == type([]))
|
|
||||||
let recipients += b:GPGUnknownRecipients
|
|
||||||
else
|
|
||||||
unlet b:GPGUnknownRecipients
|
|
||||||
endif
|
|
||||||
let b:GPGRecipients = []
|
|
||||||
let b:GPGUnknownRecipients = []
|
|
||||||
for recipient in recipients
|
|
||||||
let gpgid=s:GPGNameToID(recipient)
|
|
||||||
if (strlen(gpgid) > 0)
|
|
||||||
if (match(b:GPGRecipients, gpgid) < 0)
|
|
||||||
let b:GPGRecipients+=[gpgid]
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if (match(b:GPGUnknownRecipients, recipient) < 0)
|
|
||||||
let b:GPGUnknownRecipients+=[recipient]
|
|
||||||
echohl GPGWarning
|
|
||||||
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
|
||||||
echohl None
|
|
||||||
endif
|
|
||||||
end
|
|
||||||
endfor
|
|
||||||
|
|
||||||
" check if there are unknown recipients and warn
|
" check if there are unknown recipients and warn
|
||||||
if(exists("b:GPGUnknownRecipients") && len(b:GPGUnknownRecipients) > 0)
|
if(len(unknownrecipients) > 0)
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "Please use GPGEditRecipients to correct!!"
|
echom "Please use GPGEditRecipients to correct!!"
|
||||||
echo
|
echo
|
||||||
@ -403,8 +375,8 @@ function s:GPGEncrypt()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" built list of recipients
|
" built list of recipients
|
||||||
if (exists("b:GPGRecipients") && len(b:GPGRecipients) > 0)
|
if (len(recipients) > 0)
|
||||||
for gpgid in b:GPGRecipients
|
for gpgid in recipients
|
||||||
let options=options . " -r " . gpgid
|
let options=options . " -r " . gpgid
|
||||||
endfor
|
endfor
|
||||||
else
|
else
|
||||||
@ -478,29 +450,29 @@ function s:GPGViewRecipients()
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if (exists("b:GPGRecipients"))
|
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(b:GPGRecipients)
|
||||||
|
|
||||||
echo 'This file has following recipients (Unknown recipients have a prepended "!"):'
|
echo 'This file has following recipients (Unknown recipients have a prepended "!"):'
|
||||||
" echo the recipients
|
" echo the recipients
|
||||||
for name in b:GPGRecipients
|
for name in recipients
|
||||||
let name=s:GPGIDToName(name)
|
let name=s:GPGIDToName(name)
|
||||||
echo name
|
echo name
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" echo the unknown recipients
|
" echo the unknown recipients
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
for name in b:GPGUnknownRecipients
|
for name in unknownrecipients
|
||||||
let name="!" . name
|
let name="!" . name
|
||||||
echo name
|
echo name
|
||||||
endfor
|
endfor
|
||||||
echohl None
|
echohl None
|
||||||
|
|
||||||
" check if there is any known recipient
|
" check if there is any known recipient
|
||||||
if (len(b:GPGRecipients) == 0)
|
if (len(recipients) == 0)
|
||||||
echohl GPGError
|
echohl GPGError
|
||||||
echom 'There are no known recipients!'
|
echom 'There are no known recipients!'
|
||||||
echohl None
|
echohl None
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGEditRecipients() {{{2
|
" Function: s:GPGEditRecipients() {{{2
|
||||||
@ -565,23 +537,16 @@ function s:GPGEditRecipients()
|
|||||||
silent put ='GPG: Closing this buffer commits changes'
|
silent put ='GPG: Closing this buffer commits changes'
|
||||||
silent put ='GPG: ----------------------------------------------------------------------'
|
silent put ='GPG: ----------------------------------------------------------------------'
|
||||||
|
|
||||||
|
" get the recipients
|
||||||
|
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(getbufvar(b:GPGCorrespondingTo, "GPGRecipients"))
|
||||||
|
|
||||||
" put the recipients in the scratch buffer
|
" put the recipients in the scratch buffer
|
||||||
let recipients=getbufvar(b:GPGCorrespondingTo, "GPGRecipients")
|
|
||||||
if (type(recipients) != type([]))
|
|
||||||
unlet recipients
|
|
||||||
let recipients=[]
|
|
||||||
endif
|
|
||||||
for name in recipients
|
for name in recipients
|
||||||
let name=s:GPGIDToName(name)
|
let name=s:GPGIDToName(name)
|
||||||
silent put =name
|
silent put =name
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" put the unknown recipients in the scratch buffer
|
" put the unknown recipients in the scratch buffer
|
||||||
let unknownrecipients=getbufvar(b:GPGCorrespondingTo, "GPGUnknownRecipients")
|
|
||||||
if (type(unknownrecipients) != type([]))
|
|
||||||
unlet unknownrecipients
|
|
||||||
let unknownrecipients=[]
|
|
||||||
endif
|
|
||||||
let syntaxPattern="\\(nonexxistinwordinthisbuffer"
|
let syntaxPattern="\\(nonexxistinwordinthisbuffer"
|
||||||
for name in unknownrecipients
|
for name in unknownrecipients
|
||||||
let name="!" . name
|
let name="!" . name
|
||||||
@ -634,7 +599,6 @@ function s:GPGFinishRecipientsBuffer()
|
|||||||
|
|
||||||
" get the recipients from the scratch buffer
|
" get the recipients from the scratch buffer
|
||||||
let recipients=[]
|
let recipients=[]
|
||||||
let unknownrecipients=[]
|
|
||||||
let lines=getline(1,"$")
|
let lines=getline(1,"$")
|
||||||
for recipient in lines
|
for recipient in lines
|
||||||
" delete all spaces at beginning and end of the recipient
|
" delete all spaces at beginning and end of the recipient
|
||||||
@ -651,8 +615,8 @@ function s:GPGFinishRecipientsBuffer()
|
|||||||
let recipients+=[gpgid]
|
let recipients+=[gpgid]
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if (match(unknownrecipients, recipient) < 0)
|
if (match(recipients, recipient) < 0)
|
||||||
let unknownrecipients+=[recipient]
|
let recipients+=[recipient]
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
||||||
echohl None
|
echohl None
|
||||||
@ -664,7 +628,6 @@ function s:GPGFinishRecipientsBuffer()
|
|||||||
" write back the new recipient list to the corresponding buffer and mark it
|
" write back the new recipient list to the corresponding buffer and mark it
|
||||||
" as modified. Buffer is now for sure a encrypted buffer.
|
" as modified. Buffer is now for sure a encrypted buffer.
|
||||||
call setbufvar(b:GPGCorrespondingTo, "GPGRecipients", recipients)
|
call setbufvar(b:GPGCorrespondingTo, "GPGRecipients", recipients)
|
||||||
call setbufvar(b:GPGCorrespondingTo, "GPGUnknownRecipients", unknownrecipients)
|
|
||||||
call setbufvar(b:GPGCorrespondingTo, "&mod", 1)
|
call setbufvar(b:GPGCorrespondingTo, "&mod", 1)
|
||||||
call setbufvar(b:GPGCorrespondingTo, "GPGEncrypted", 1)
|
call setbufvar(b:GPGCorrespondingTo, "GPGEncrypted", 1)
|
||||||
|
|
||||||
@ -836,6 +799,38 @@ function s:GPGFinishOptionsBuffer()
|
|||||||
set nomodified
|
set nomodified
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Function: s:GPGCheckRecipients(tocheck) {{{2
|
||||||
|
"
|
||||||
|
" check if recipients are known
|
||||||
|
" Returns: two lists recipients and unknownrecipients
|
||||||
|
function s:GPGCheckRecipients(tocheck)
|
||||||
|
let recipients=[]
|
||||||
|
let unknownrecipients=[]
|
||||||
|
|
||||||
|
if (type(a:tocheck) == type([]))
|
||||||
|
for recipient in a:tocheck
|
||||||
|
let gpgid=s:GPGNameToID(recipient)
|
||||||
|
if (strlen(gpgid) > 0)
|
||||||
|
if (match(recipients, gpgid) < 0)
|
||||||
|
let recipients+=[gpgid]
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
if (match(unknownrecipients, recipient) < 0)
|
||||||
|
let unknownrecipients+=[recipient]
|
||||||
|
echohl GPGWarning
|
||||||
|
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
|
||||||
|
echohl None
|
||||||
|
endif
|
||||||
|
end
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
|
call s:GPGDebug(2, "recipients are: " . string(recipients))
|
||||||
|
call s:GPGDebug(2, "unknown recipients are: " . string(unknownrecipients))
|
||||||
|
|
||||||
|
return [ recipients, unknownrecipients ]
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGNameToID(name) {{{2
|
" Function: s:GPGNameToID(name) {{{2
|
||||||
"
|
"
|
||||||
" find GPG key ID corresponding to a name
|
" find GPG key ID corresponding to a name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user