You would import the key into a new keyring file, and use the --status-fd
or --status-file
option to gpg to have it generate running commentary in a fixed format that you can then process afterwards.
For example, importing my key from a keyserver with
curl 'http://keys.gnupg.net/pks/lookup?op=get&search=0xEBF67A846AABE354' | \
gpg --status-file=status --import
generates a status
file listing
[GNUPG:] KEY_CONSIDERED 040EB5F784F14FBCCEADADC618A0CC8D5706A4B4 0
[GNUPG:] KEY_CONSIDERED 040EB5F784F14FBCCEADADC618A0CC8D5706A4B4 0
[GNUPG:] KEY_CONSIDERED 040EB5F784F14FBCCEADADC618A0CC8D5706A4B4 0
[GNUPG:] KEY_CONSIDERED 040EB5F784F14FBCCEADADC618A0CC8D5706A4B4 0
[GNUPG:] KEY_CONSIDERED 9C43253495E4DCA837945F5BEBF67A846AABE354 0
[GNUPG:] IMPORT_OK 4 9C43253495E4DCA837945F5BEBF67A846AABE354
[GNUPG:] IMPORT_RES 1 0 0 0 0 0 0 295 0 0 0 0 0 0 0
In my case, the key was already in my keyring, although 295 signatures were added.
In addition, you should also check the exit code from the gpg
process.
The same method can be used for retrieving a key from a keyserver, but you might be given multiple keys here, even for search by ID -- for example, if you use my short ID, 6AABE354
, you get my real key and one from the evil32 set, so you may need additional UI to select one key in this case.