From 01dbe6635ff256e683cf6b702f81cd4d60af2cf8 Mon Sep 17 00:00:00 2001 From: ueno Date: Sat, 11 Nov 2006 08:30:40 +0000 Subject: [PATCH] (epg-make-context): New slot "sig-notations". (epg--args-from-sig-notations): New function. (epg-start-sign): Specify --sig-notation or --sig-policy-url if desired. (epg-start-encrypt): Ditto. --- ChangeLog | 5 +++ epg.el | 101 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 86 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5137efe..6f79624 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ * epg.el (epg-start-sign): Don't set --armor nor --textmode if mode is set for a cleartext signature. + (epg-make-context): New slot "sig-notations". + (epg--args-from-sig-notations): New function. + (epg-start-sign): Specify --sig-notation or --sig-policy-url if + desired. + (epg-start-encrypt): Ditto. 2006-10-29 Daiki Ueno diff --git a/epg.el b/epg.el index e7e4616..89f7949 100644 --- a/epg.el +++ b/epg.el @@ -187,7 +187,7 @@ cipher-algorithm digest-algorithm compress-algorithm #'epg-passphrase-callback-function nil - nil nil nil nil nil))) + nil nil nil nil nil nil))) (defun epg-context-protocol (context) "Return the protocol used within CONTEXT." @@ -250,31 +250,37 @@ message." (signal 'wrong-type-argument (list 'epg-context-p context))) (aref (cdr context) 9)) +(defun epg-context-sig-notations (context) + "Return the list of notations for singning." + (unless (eq (car-safe context) 'epg-context) + (signal 'wrong-type-argument (list 'epg-context-p context))) + (aref (cdr context) 10)) + (defun epg-context-process (context) "Return the process object of `epg-gpg-program'. This function is for internal use only." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aref (cdr context) 10)) + (aref (cdr context) 11)) (defun epg-context-output-file (context) "Return the output file of `epg-gpg-program'. This function is for internal use only." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aref (cdr context) 11)) + (aref (cdr context) 12)) (defun epg-context-result (context) "Return the result of the previous cryptographic operation." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aref (cdr context) 12)) + (aref (cdr context) 13)) (defun epg-context-operation (context) "Return the name of the current cryptographic operation." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aref (cdr context) 13)) + (aref (cdr context) 14)) (defun epg-context-set-protocol (context protocol) "Set the protocol used within CONTEXT." @@ -332,36 +338,42 @@ This function is for internal use only." (aset (cdr context) 8 progress-callback)) (defun epg-context-set-signers (context signers) - "Set the list of key-id for singning." + "Set the list of key-id for singning." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) (aset (cdr context) 9 signers)) +(defun epg-context-set-sig-notations (context notations) + "Set the list of notations for singning." + (unless (eq (car-safe context) 'epg-context) + (signal 'wrong-type-argument (list 'epg-context-p context))) + (aset (cdr context) 10 signers)) + (defun epg-context-set-process (context process) "Set the process object of `epg-gpg-program'. This function is for internal use only." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aset (cdr context) 10 process)) + (aset (cdr context) 11 process)) (defun epg-context-set-output-file (context output-file) "Set the output file of `epg-gpg-program'. This function is for internal use only." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aset (cdr context) 11 output-file)) + (aset (cdr context) 12 output-file)) (defun epg-context-set-result (context result) "Set the result of the previous cryptographic operation." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aset (cdr context) 12 result)) + (aset (cdr context) 13 result)) (defun epg-context-set-operation (context operation) "Set the name of the current cryptographic operation." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) - (aset (cdr context) 13 operation)) + (aset (cdr context) 14 operation)) (defun epg-make-signature (status &optional key-id) "Return a signature object." @@ -715,6 +727,34 @@ This function is for internal use only." (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature))) (aref (cdr key-signature) 7)) +(defun epg-make-sig-notation (name value &optional human-readable critical) + "Return a notation object." + (cons 'epg-sig-notation (vector name value human-readable critical))) + +(defun epg-sig-notation-name (sig-notation) + "Return the name of SIG-NOTATION." + (unless (eq (car-safe sig-notation) 'epg-sig-notation) + (signal 'wrong-type-argument (list 'epg-sig-notation-p sig-notation))) + (aref (cdr sig-notation) 0)) + +(defun epg-sig-notation-value (sig-notation) + "Return the value of SIG-NOTATION." + (unless (eq (car-safe sig-notation) 'epg-sig-notation) + (signal 'wrong-type-argument (list 'epg-sig-notation-p sig-notation))) + (aref (cdr sig-notation) 1)) + +(defun epg-sig-notation-human-readable (sig-notation) + "Return the human-readable of SIG-NOTATION." + (unless (eq (car-safe sig-notation) 'epg-sig-notation) + (signal 'wrong-type-argument (list 'epg-sig-notation-p sig-notation))) + (aref (cdr sig-notation) 2)) + +(defun epg-sig-notation-critical (sig-notation) + "Return the critical of SIG-NOTATION." + (unless (eq (car-safe sig-notation) 'epg-sig-notation) + (signal 'wrong-type-argument (list 'epg-sig-notation-p sig-notation))) + (aref (cdr sig-notation) 3)) + (defun epg-context-result-for (context name) "Return the result of CONTEXT associated with NAME." (cdr (assq name (epg-context-result context)))) @@ -1494,6 +1534,23 @@ You can then use `write-region' to write new data into the file." (defun epg--clear-string (string) (fillarray string 0))) +(defun epg--args-from-sig-notations (notations) + (apply #'nconc + (mapcar + (lambda (notation) + (if (and (epg-sig-notation-name notation) + (not (epg-sig-notation-human-readable notation))) + (error "Unreadable")) + (if (epg-sig-notation-name notation) + (list "--sig-notation" + (if (epg-sig-notation-critical notation) + (concat "!" (epg-sig-notation-name notation) + "=" (epg-sig-notation-value notation)) + (concat (epg-sig-notation-name notation) + "=" (epg-sig-notation-value notation)))) + (list "--sig-policy-url" (epg-sig-notation-value notation)))) + notations)) + ;;;###autoload (defun epg-cancel (context) (if (buffer-live-p (process-buffer (epg-context-process context))) @@ -1679,7 +1736,7 @@ If you are unsure, use synchronous version of this function `epg-sign-file' or `epg-sign-string' instead." (epg-context-set-operation context 'sign) (epg-context-set-result context nil) - (unless (memq mode '(t detached nil normal)) + (unless (memq mode '(t detached nil normal)) ;i.e. cleartext (epg-context-set-armor context nil) (epg-context-set-textmode context nil)) (epg--start context @@ -1695,6 +1752,7 @@ If you are unsure, use synchronous version of this function (epg-sub-key-id (car (epg-key-sub-key-list signer))))) (epg-context-signers context))) + (epg--args-from-sig-notations (epg-context-sig-notations)) (if (epg-data-file plain) (list "--" (epg-data-file plain))))) ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed. @@ -1771,16 +1829,19 @@ If you are unsure, use synchronous version of this function (epg--start context (append (if always-trust '("--always-trust")) (if recipients '("--encrypt") '("--symmetric")) + (if sign '("--sign")) + (if sign + (apply #'nconc + (mapcar + (lambda (signer) + (list "-u" + (epg-sub-key-id + (car (epg-key-sub-key-list + signer))))) + (epg-context-signers context)))) (if sign - (cons "--sign" - (apply #'nconc - (mapcar - (lambda (signer) - (list "-u" - (epg-sub-key-id - (car (epg-key-sub-key-list - signer))))) - (epg-context-signers context))))) + (epg--args-from-sig-notations + (epg-context-sig-notations))) (apply #'nconc (mapcar (lambda (recipient) -- 1.7.10.4