Problem with decrypt

Werner Koch wk at gnupg.org
Fri Apr 15 19:03:29 CEST 2016


On Thu, 14 Apr 2016 22:41, thecissou98 at hotmail.fr said:

> I'm trying to decrypt a cipher using gpgme. I have a correct cipher and
> have imported the private key but the plain result of gpgme_op_decrypt
> is empty. The error returned is GPG_ERR_NO_ERROR...

Which means success.  In general you test for an error this way:

      err = gpgme_foo (&data);
      if (err)

Of course you could also do

      if (err != 0)
         report_error_foo (gpg_strerror (err));
      else
         process_returned_data (data);

which is identical to the above or 

      if (err != GPG_ERR_NO_ERROR)
         report_error_foo (gpg_strerror (err));
      else
         process_returned_data (data);

which is also identical because GPG_ERR_NO_ERROR expands to 0.  I would
prefer the first becuase it is easier to read.

If you need more help, I suggest to post a snippet of your code.


Salam-Shalom,

   Werner


ps.
And yes, some put the constant first like
      if (0 == err)
to detect an unintentional assignment to the lvalue.  However, modern
compilers are pretty good in warning about unintentional assignments and
thus _I_ do not use that.  Comparing false or true is anyway better done
without an explicit compare operator - that pattern is easier to parse
for the brain.

-- 
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.




More information about the Gnupg-users mailing list