(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.
--- /dev/null
+(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