From: ueno Date: Wed, 12 Apr 2006 08:49:43 +0000 (+0000) Subject: * pgg-epg.el: New file. X-Git-Tag: epgsm-branchpoint~115 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8b1b9d766bc634c0f7fd60255e2f4301c1c97bf;p=elisp%2Fepg.git * pgg-epg.el: New file. * epg.el (epg-start-export-keys): New function. (epg-export-keys): New function. (epg-start-import-keys): New function. (epg-import-keys): New function. (epg-verify-file): New function. * epg.el (epg-passphrase-callback-function): Always display key-id. --- diff --git a/ChangeLog b/ChangeLog index 94114be..c101bb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,12 @@ 2006-04-12 Daiki Ueno + * pgg-epg.el: New file. + * epg.el (epg-start-export-keys): New function. (epg-export-keys): New function. (epg-start-import-keys): New function. (epg-import-keys): New function. + (epg-verify-file): New function. * epg-file.el (epg-file-write-region): Support public key encryption. diff --git a/epg.el b/epg.el index 110bbeb..d689fba 100644 --- a/epg.el +++ b/epg.el @@ -647,14 +647,24 @@ For a normal or a clear text signature, STRING should be nil." (progn (if string (write-region signature nil input-file)) - (epg-start-verify context input-file string) - (epg-wait-for-completion context) - (epg-context-result-for context 'verify)) - (epg-reset context) + (epg-verify-file context input-file string)) (if (file-exists-p input-file) (delete-file input-file))))) ;;;###autoload +(defun epg-verify-file (context input-file &optional string) + "Verify INPUT-FILE. + +For a detached signature, both INPUT-FILE and STRING should be string. +For a normal or a clear text signature, STRING should be nil." + (unwind-protect + (progn + (epg-start-verify context input-file string) + (epg-wait-for-completion context) + (epg-context-result-for context 'verify)) + (epg-reset context)))) + +;;;###autoload (defun epg-start-sign (context string &optional mode) "Initiate a sign operation on STRING. diff --git a/pgg-epg.el b/pgg-epg.el new file mode 100644 index 0000000..d2f09c5 --- /dev/null +++ b/pgg-epg.el @@ -0,0 +1,108 @@ +(require 'epg) +(eval-when-compile (require 'pgg)) + +(defun pgg-epg-encrypt-region (start end recipients &optional sign passphrase) + "This function is for internal use only. + +Encrypt the current region between START and END. + +If optional argument SIGN is non-nil, do a combined sign and encrypt. + +If optional PASSPHRASE is not specified, it will be obtained from the +passphrase cache or user." + (let ((context (epg-make-context)) + cipher) + (epg-context-set-armor context t) + (epg-context-set-textmode context pgg-text-mode) + (setq cipher (epg-encrypt-string context (buffer-substring start end) + (if pgg-encrypt-for-me + (cons pgg-default-user-id recipients) + recipients) + sign t)) + (save-excursion + (set-buffer (get-buffer-create pgg-output-buffer)) + (insert cipher)) + t)) + +(defun pgg-epg-encrypt-symmetric-region (start end &optional passphrase) + "This function is for internal use only. + +Encrypt the current region between START and END with symmetric cipher. + +If optional PASSPHRASE is not specified, it will be obtained from the +passphrase cache or user." + (pgg-epg-encrypt-region start end nil)) + +(defun pgg-epg-decrypt-region (start end &optional passphrase) + "This function is for internal use only. + +Decrypt the current region between START and END. + +If optional PASSPHRASE is not specified, it will be obtained from the +passphrase cache or user." + (let ((context (epg-make-context)) + plain) + (epg-context-set-armor context t) + (epg-context-set-textmode context pgg-text-mode) + (setq plain (epg-decrypt-string context (buffer-substring start end))) + (save-excursion + (set-buffer (get-buffer-create pgg-output-buffer)) + (insert plain)) + t)) + +(defun pgg-epg-sign-region (start end &optional cleartext passphrase) + "This function is for internal use only. + +Make detached signature from text between START and END. + +If optional PASSPHRASE is not specified, it will be obtained from the +passphrase cache or user." + (let ((context (epg-make-context)) + signature) + (epg-context-set-armor context t) + (epg-context-set-textmode context pgg-text-mode) + (setq signature (epg-sign-string context (buffer-substring start end) + (if cleartext + 'cleartext + 'detached))) + (save-excursion + (set-buffer (get-buffer-create pgg-output-buffer)) + (insert signature)) + t) + +(defun pgg-epg-verify-region (start end &optional signature) + "This function is for internal use only. + +Verify region between START and END as the detached signature SIGNATURE." + (let ((context (epg-make-context)) + pointer) + (epg-context-set-armor context t) + (epg-context-set-textmode context pgg-text-mode) + (if signature + (epg-verify-file context signature (buffer-substring start end)) + (epg-verify-string context (buffer-substring start end))) + (reverse (epg-context-result-for context 'verify))) + +(defun pgg-epg-insert-key () + "This function is for internal use only. + +Insert public key at point." + (let ((context (epg-make-context)) + pointer) + (epg-context-set-armor context t) + (epg-context-set-textmode context pgg-text-mode) + (insert (epg-export-keys context pgg-default-user-id)))) + +(defun pgg-epg-snarf-keys-region (start end) + "This function is for internal use only. + +Add all public keys in region between START and END to the keyring." + (let ((context (epg-make-context)) + pointer) + (epg-context-set-armor context t) + (epg-context-set-textmode context pgg-text-mode) + (epg-import-keys context (buffer-substring start end)))) + +(provide 'pgg-epg) + +;;; pgg-epg.el ends here