Edit unencrypted files with "encryption" suffix as normal files.

This commit is contained in:
Markus Braun 2006-12-13 15:28:31 +00:00
parent 9a272dbf45
commit 4771cc9025

View File

@ -155,7 +155,8 @@ fun 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 GPGRecipients, GPGUnknownRecipients and GPGOptions " clear GPGEncrypted, GPGRecipients, GPGUnknownRecipients and GPGOptions
let b:GPGEncrypted=0
let b:GPGRecipients="" let b:GPGRecipients=""
let b:GPGUnknownRecipients="" let b:GPGUnknownRecipients=""
let b:GPGOptions="" let b:GPGOptions=""
@ -170,6 +171,8 @@ fun s:GPGDecrypt()
" check if the file is symmetric/asymmetric encrypted " check if the file is symmetric/asymmetric encrypted
if (match(output, "gpg: [^ ]\\+ encrypted data") >= 0) if (match(output, "gpg: [^ ]\\+ encrypted data") >= 0)
" file is symmetric encrypted " file is symmetric encrypted
let b:GPGEncrypted=1
let b:GPGOptions=b:GPGOptions . "symmetric:" let b:GPGOptions=b:GPGOptions . "symmetric:"
let cipher=substitute(output, ".*gpg: \\([^ ]\\+\\) encrypted data.*", "\\1", "") let cipher=substitute(output, ".*gpg: \\([^ ]\\+\\) encrypted data.*", "\\1", "")
@ -181,8 +184,10 @@ fun s:GPGDecrypt()
echo echo
echohl None echohl None
endi endi
else elseif (match(output, "gpg: public key decryption") >= 0)
" file is asymmetric encrypted " file is asymmetric encrypted
let b:GPGEncrypted=1
let b:GPGOptions=b:GPGOptions . "encrypt:" let b:GPGOptions=b:GPGOptions . "encrypt:"
let start=match(output, "ID [[:xdigit:]]\\{8}") let start=match(output, "ID [[:xdigit:]]\\{8}")
@ -200,7 +205,13 @@ fun s:GPGDecrypt()
end end
let start=match(output, "ID [[:xdigit:]]\\{8}", start) let start=match(output, "ID [[:xdigit:]]\\{8}", start)
endw endw
elseif (match(output, "gpg: no valid OpenPGP data found") >= 0)
" file is not encrypted
let b:GPGEncrypted=0
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi endi
" check if the message is armored " check if the message is armored
@ -231,6 +242,14 @@ endf
" encrypts the buffer to all previous recipients " encrypts the buffer to all previous recipients
" "
fun s:GPGEncrypt() fun s:GPGEncrypt()
" guard for unencrypted files
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi
let options="" let options=""
let recipients="" let recipients=""
let field=0 let field=0
@ -298,6 +317,14 @@ endf
" echo the recipients " echo the recipients
" "
fun s:GPGViewRecipients() fun s:GPGViewRecipients()
" guard for unencrypted files
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi
if (exists("b:GPGRecipients")) if (exists("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
@ -338,6 +365,14 @@ endf
" create a scratch buffer with all recipients to add/remove recipients " create a scratch buffer with all recipients to add/remove recipients
" "
fun s:GPGEditRecipients() fun s:GPGEditRecipients()
" guard for unencrypted files
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi
" only do this if it isn't already a GPGRecipients_* buffer " only do this if it isn't already a GPGRecipients_* buffer
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0) if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
@ -431,6 +466,14 @@ endf
" "
" create a new recipient list from RecipientsBuffer " create a new recipient list from RecipientsBuffer
fun s:GPGFinishRecipientsBuffer() fun s:GPGFinishRecipientsBuffer()
" guard for unencrypted files
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi
" clear GPGRecipients and GPGUnknownRecipients " clear GPGRecipients and GPGUnknownRecipients
let GPGRecipients="" let GPGRecipients=""
let GPGUnknownRecipients="" let GPGUnknownRecipients=""
@ -485,6 +528,14 @@ endf
" echo the recipients " echo the recipients
" "
fun s:GPGViewOptions() fun s:GPGViewOptions()
" guard for unencrypted files
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi
if (exists("b:GPGOptions")) if (exists("b:GPGOptions"))
echo 'This file has following options:' echo 'This file has following options:'
" echo the options " echo the options
@ -504,6 +555,14 @@ endf
" create a scratch buffer with all recipients to add/remove recipients " create a scratch buffer with all recipients to add/remove recipients
" "
fun s:GPGEditOptions() fun s:GPGEditOptions()
" guard for unencrypted files
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi
" only do this if it isn't already a GPGOptions_* buffer " only do this if it isn't already a GPGOptions_* buffer
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0) if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
@ -577,6 +636,14 @@ endf
" "
" create a new option list from OptionsBuffer " create a new option list from OptionsBuffer
fun s:GPGFinishOptionsBuffer() fun s:GPGFinishOptionsBuffer()
" guard for unencrypted files
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
echohl GPGWarning
echo "File is not encrypted, all GPG functions disabled!"
echohl None
return
endi
" clear GPGOptions and GPGUnknownOptions " clear GPGOptions and GPGUnknownOptions
let GPGOptions="" let GPGOptions=""
let GPGUnknownOptions="" let GPGUnknownOptions=""