Function: epg-edit-key
epg-edit-key is a byte-compiled function defined in epg.el.gz.
Signature
(epg-edit-key CONTEXT KEY EDIT-CALLBACK HANDBACK)
Documentation
Edit KEY in the keyring.
This function and function epg-start-edit-key use the
line-based protocol enabled by "gpg" parameter "--status-fd"
to edit KEY. For each GnuPG status line, these functions or,
more precisely, the EPG process filter calls EDIT-CALLBACK with
four arguments: argument CONTEXT, the GnuPG status keyword, the
GnuPG status argument string, and argument HANDBACK.
The following example uses a simple state machine to trust the first subkey of key KEY ultimately:
(let ((state 0))
(epg-edit-key
context key
(lambda (context status string _handback)
(pcase (vector state status string)
(`[0 "KEY_CONSIDERED" ,_])
('[1 "GET_LINE" "keyedit.prompt"]
(process-send-string (epg-context-process context) "1\\n"))
('[2 "GOT_IT" ""])
('[3 "GET_LINE" "keyedit.prompt"]
(process-send-string (epg-context-process context) "trust\\n"))
('[4 "GOT_IT" ""])
('[5 "GET_LINE" "edit_ownertrust.value"]
(process-send-string (epg-context-process context) "5\\n"))
('[6 "GOT_IT" ""])
('[7 "GET_BOOL" "edit_ownertrust.set_ultimate.okay"]
(process-send-string (epg-context-process context) "yes\\n"))
('[8 "GOT_IT" ""])
('[9 "GET_LINE" "keyedit.prompt"]
(process-send-string (epg-context-process context) "quit\\n"))
('[10 "GOT_IT" ""])
(_
(error "Key edit protocol error in state %d" state)))
(setq state (1+ state)))
nil))
This is a slightly simplified example: Ideally, it should have double-checked the fingerprint argument to the "KEY_CONSIDERED" status keyword instead of ignoring it.
Source Code
;; Defined in /usr/src/emacs/lisp/epg.el.gz
(defun epg-edit-key (context key edit-callback handback)
"Edit KEY in the keyring.
This function and function `epg-start-edit-key' use the
line-based protocol enabled by \"gpg\" parameter \"--status-fd\"
to edit KEY. For each GnuPG status line, these functions or,
more precisely, the EPG process filter calls EDIT-CALLBACK with
four arguments: argument CONTEXT, the GnuPG status keyword, the
GnuPG status argument string, and argument HANDBACK.
The following example uses a simple state machine to trust the
first subkey of key KEY ultimately:
(let ((state 0))
(epg-edit-key
context key
(lambda (context status string _handback)
(pcase (vector state status string)
(\\=`[0 \"KEY_CONSIDERED\" ,_])
(\\='[1 \"GET_LINE\" \"keyedit.prompt\"]
(process-send-string (epg-context-process context) \"1\\n\"))
(\\='[2 \"GOT_IT\" \"\"])
(\\='[3 \"GET_LINE\" \"keyedit.prompt\"]
(process-send-string (epg-context-process context) \"trust\\n\"))
(\\='[4 \"GOT_IT\" \"\"])
(\\='[5 \"GET_LINE\" \"edit_ownertrust.value\"]
(process-send-string (epg-context-process context) \"5\\n\"))
(\\='[6 \"GOT_IT\" \"\"])
(\\='[7 \"GET_BOOL\" \"edit_ownertrust.set_ultimate.okay\"]
(process-send-string (epg-context-process context) \"yes\\n\"))
(\\='[8 \"GOT_IT\" \"\"])
(\\='[9 \"GET_LINE\" \"keyedit.prompt\"]
(process-send-string (epg-context-process context) \"quit\\n\"))
(\\='[10 \"GOT_IT\" \"\"])
(_
(error \"Key edit protocol error in state %d\" state)))
(setq state (1+ state)))
nil))
This is a slightly simplified example: Ideally, it should have
double-checked the fingerprint argument to the \"KEY_CONSIDERED\"
status keyword instead of ignoring it."
(unwind-protect
(progn
(epg-start-edit-key context key edit-callback handback)
(epg-wait-for-completion context)
(let ((errors (epg-context-result-for context 'error)))
(if errors
(signal 'epg-error
(list "Edit key failed"
(epg-errors-to-string errors))))))
(epg-reset context)))