Mailing List Archive

GpgME: gpgme_op_import_result() for crap data
Hi all,

when I call gpg to import some crap data, a proper error message is returned, e.g.:

<snip>
user@host:~$ gpg --import <<< 'some crap'
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
</snip>

However, calling gpgme_op_import() on the same data, and then reading gpgme_op_import_result(), no usable error information is returned. E.g. running the attached simple code, the result is

<snip>
user@host:~$ ./gpgme-import
GpgME version: 1.12.0
gpgme_new: 0
gpgme_set_protocol: 0
gpgme_data_new_from_mem: 0
gpgme_op_import: 0
gpgme_op_import_result: imported=0, not imported=0, imports=(nil)
</snip>

I would expect that imports is not NULL, and imports->result indicate the error (probably GPG_ERR_INV_DATA).

Did I miss something here (i.e. I have to read the error information somewhere else), or is this information left out intentionally?

Thanks
Albrecht.
Re: GpgME: gpgme_op_import_result() for crap data [ In reply to ]
Hi,

On Saturday, January 12, 2019 4:52:11 PM CET Albrecht Dre? wrote:
> when I call gpg to import some crap data, a proper error message is
> returned, e.g.:
>
> <snip>
> user@host:~$ gpg --import <<< 'some crap'
> gpg: no valid OpenPGP data found.
> gpg: Total number processed: 0
> </snip>

That is not an error but a status message. The difference is that the
operation continues. E.g. if you provide two filenames and the second one
contains valid data you will get the status message once but still something
is imported.

> I would expect that imports is not NULL, and imports->result indicate the
error (probably GPG_ERR_INV_DATA).

I agree that it is bad. In Kleopatra I just treat empty results like an error
happened. But if you import two files and only one has an error Kleopatra also
will not show it.

> Did I miss something here (i.e. I have to read the error information
somewhere else), or is this information left out intentionally?

You could use the new diagnostic interface to show the status output of GnuPG
to the user in case an empty import result occured. I explicitly wanted to
have that interface for such reasons where diagnostic output that is printed
to stderr by GnuPG would otherwise be lost.

Be aware though that you should not automatically parse the diagnostic output
as it might change because it is by design human readable output and not
machine output.

I've commited an example how to use it to the gpgme run-import test:

https://dev.gnupg.org/rMce327f994a2888b807b63cf202ddcecc3fb9c685


Best Regards,
Andre

--
GnuPG e.V., Rochusstr. 44, D-40479 D?sseldorf. VR 11482 D?sseldorf
Vorstand: W.Koch, M.Gollowitzer, A.Heinecke. Mail: board@gnupg.org
Finanzamt D-Altstadt, St-Nr: 103/5923/1779. Tel: +49-2104-4938799
Re: GpgME: gpgme_op_import_result() for crap data [ In reply to ]
Am 15.01.19 10:54 schrieb(en) Andre Heinecke:
> That is not an error but a status message. The difference is that the operation continues. E.g. if you provide two filenames and the second one contains valid data you will get the status message once but still something is imported.

O.k., understood.

>> I would expect that imports is not NULL, and imports->result indicate the error (probably GPG_ERR_INV_DATA).
>
> I agree that it is bad. In Kleopatra I just treat empty results like an error happened.

My use case is the import of a single key in a MUA (from Autocrypt header, key server search, etc.). Just telling the user “something went wrong” is somewhat unsatisfactory…

> But if you import two files and only one has an error Kleopatra also will not show it.

The GpgME gpgme_import_result_t and gpgme_import_status_t data structures could cover this case, as the latter is a linked list. I.e. add a separate item for each key, with a NULL fpr and appropriate status for all failed attempts.

> You could use the new diagnostic interface to show the status output of GnuPG to the user in case an empty import result occured. I explicitly wanted to have that interface for such reasons where diagnostic output that is printed to stderr by GnuPG would otherwise be lost.
[snip]
> I've commited an example how to use it to the gpgme run-import test:

Thanks, that's a helpful hint! Unfortunately available since 1.11.2 only, i.e. not in Stretch or Ubuntu 18.04 – more #ifdef's in the code!

Thanks again,
Albrecht.