Function: mml-secure-find-usable-keys
mml-secure-find-usable-keys is a byte-compiled function defined in
mml-sec.el.gz.
Signature
(mml-secure-find-usable-keys CONTEXT NAME USAGE &optional JUSTONE)
Documentation
In CONTEXT return a list of keys for NAME and USAGE.
If USAGE is encrypt public keys are returned, otherwise secret ones.
Only non-revoked and non-expired keys are returned whose primary key is
not disabled.
NAME can be an e-mail address or a key ID.
If NAME just consists of hexadecimal digits (possibly prefixed by "0x"), it
is treated as key ID for which at most one key must exist in the keyring.
Otherwise, NAME is treated as user ID, for which no keys are returned if it
is expired or revoked.
If optional JUSTONE is not nil, return the first key instead of a list.
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/mml-sec.el.gz
(defun mml-secure-find-usable-keys (context name usage &optional justone)
"In CONTEXT return a list of keys for NAME and USAGE.
If USAGE is `encrypt' public keys are returned, otherwise secret ones.
Only non-revoked and non-expired keys are returned whose primary key is
not disabled.
NAME can be an e-mail address or a key ID.
If NAME just consists of hexadecimal digits (possibly prefixed by \"0x\"), it
is treated as key ID for which at most one key must exist in the keyring.
Otherwise, NAME is treated as user ID, for which no keys are returned if it
is expired or revoked.
If optional JUSTONE is not nil, return the first key instead of a list."
(let* ((keys (epg-list-keys context name))
(iskeyid (string-match "\\(0x\\)?\\([[:xdigit:]]\\{8,\\}\\)" name))
(fingerprint (match-string 2 name))
result)
(when (and iskeyid (>= (length keys) 2))
(error
"Name %s (for %s) looks like a key ID but multiple keys found"
name usage))
(catch 'break
(dolist (key keys result)
(if (and (or iskeyid
(mml-secure-check-user-id key name))
(mml-secure-check-sub-key context key usage fingerprint))
(if justone
(throw 'break key)
(push key result)))))))