LCOV - code coverage report
Current view: top level - src - decrypt-verify.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 43 65 66.2 %
Date: 2018-11-15 08:49:49 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /* decrypt-verify.c - Decrypt and verify function.
       2             :    Copyright (C) 2000 Werner Koch (dd9jn)
       3             :    Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
       4             : 
       5             :    This file is part of GPGME.
       6             : 
       7             :    GPGME is free software; you can redistribute it and/or modify it
       8             :    under the terms of the GNU Lesser General Public License as
       9             :    published by the Free Software Foundation; either version 2.1 of
      10             :    the License, or (at your option) any later version.
      11             : 
      12             :    GPGME is distributed in the hope that it will be useful, but
      13             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :    Lesser General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU Lesser General Public
      18             :    License along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      20             :    02111-1307, USA.  */
      21             : 
      22             : #if HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : 
      26             : #include <assert.h>
      27             : 
      28             : #include "debug.h"
      29             : #include "gpgme.h"
      30             : #include "ops.h"
      31             : 
      32             : 
      33             : static gpgme_error_t
      34         403 : decrypt_verify_status_handler (void *priv, gpgme_status_code_t code,
      35             :                                char *args)
      36             : {
      37             :   gpgme_error_t err;
      38             : 
      39         403 :   err = _gpgme_progress_status_handler (priv, code, args);
      40         403 :   if (!err)
      41         403 :     err = _gpgme_decrypt_status_handler (priv, code, args);
      42         403 :   if (!err)
      43         403 :       err = _gpgme_verify_status_handler (priv, code, args);
      44         403 :   return err;
      45             : }
      46             : 
      47             : 
      48             : static gpgme_error_t
      49          19 : decrypt_verify_start (gpgme_ctx_t ctx, int synchronous,
      50             :                       gpgme_decrypt_flags_t flags,
      51             :                       gpgme_data_t cipher, gpgme_data_t plain)
      52             : {
      53             :   gpgme_error_t err;
      54             : 
      55          19 :   assert ((flags & GPGME_DECRYPT_VERIFY));
      56             : 
      57          19 :   err = _gpgme_op_reset (ctx, synchronous);
      58          19 :   if (err)
      59           0 :     return err;
      60             : 
      61          19 :   err = _gpgme_op_decrypt_init_result (ctx, plain);
      62          19 :   if (err)
      63           0 :     return err;
      64             : 
      65          19 :   err = _gpgme_op_verify_init_result (ctx);
      66          19 :   if (err)
      67           0 :     return err;
      68             : 
      69          19 :   if (!cipher)
      70           0 :     return gpg_error (GPG_ERR_NO_DATA);
      71          19 :   if (!plain)
      72           0 :     return gpg_error (GPG_ERR_INV_VALUE);
      73             : 
      74          19 :   if (ctx->passphrase_cb)
      75             :     {
      76           9 :       err = _gpgme_engine_set_command_handler
      77             :         (ctx->engine, _gpgme_passphrase_command_handler, ctx);
      78           9 :       if (err)
      79           0 :         return err;
      80             :     }
      81             : 
      82          19 :   _gpgme_engine_set_status_handler (ctx->engine,
      83             :                                     decrypt_verify_status_handler, ctx);
      84             : 
      85          38 :   return _gpgme_engine_op_decrypt (ctx->engine,
      86             :                                    flags,
      87             :                                    cipher, plain,
      88          19 :                                    ctx->export_session_keys,
      89          19 :                                    ctx->override_session_key,
      90          19 :                                    ctx->auto_key_retrieve);
      91             : }
      92             : 
      93             : 
      94             : /* Decrypt ciphertext CIPHER and make a signature verification within
      95             :    CTX and store the resulting plaintext in PLAIN.  */
      96             : gpgme_error_t
      97           0 : gpgme_op_decrypt_verify_start (gpgme_ctx_t ctx, gpgme_data_t cipher,
      98             :                                gpgme_data_t plain)
      99             : {
     100             :   gpgme_error_t err;
     101             : 
     102           0 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify_start", ctx,
     103             :               "cipher=%p, plain=%p", cipher, plain);
     104             : 
     105           0 :   if (!ctx)
     106           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
     107             : 
     108           0 :   err = decrypt_verify_start (ctx, 0, GPGME_DECRYPT_VERIFY, cipher, plain);
     109           0 :   return TRACE_ERR (err);
     110             : }
     111             : 
     112             : 
     113             : /* Decrypt ciphertext CIPHER and make a signature verification within
     114             :    CTX and store the resulting plaintext in PLAIN.  */
     115             : gpgme_error_t
     116          17 : gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher,
     117             :                          gpgme_data_t plain)
     118             : {
     119             :   gpgme_error_t err;
     120             : 
     121          17 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify", ctx,
     122             :               "cipher=%p, plain=%p", cipher, plain);
     123             : 
     124          17 :   if (!ctx)
     125           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
     126             : 
     127          17 :   err = decrypt_verify_start (ctx, 1, GPGME_DECRYPT_VERIFY, cipher, plain);
     128          17 :   if (!err)
     129          17 :     err = _gpgme_wait_one (ctx);
     130          17 :   ctx->ignore_mdc_error = 0;  /* Always reset.  */
     131          17 :   return TRACE_ERR (err);
     132             : }
     133             : 
     134             : 
     135             : /* Decrypt ciphertext CIPHER within CTX and store the resulting
     136             :    plaintext in PLAIN.  */
     137             : gpgme_error_t
     138           0 : gpgme_op_decrypt_ext_start (gpgme_ctx_t ctx,
     139             :                             gpgme_decrypt_flags_t flags,
     140             :                             gpgme_data_t cipher,
     141             :                             gpgme_data_t plain)
     142             : {
     143             :   gpgme_error_t err;
     144             : 
     145           0 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_ext_start", ctx,
     146             :               "cipher=%p, plain=%p", cipher, plain);
     147             : 
     148           0 :   if (!ctx)
     149           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
     150             : 
     151           0 :   if ((flags & GPGME_DECRYPT_VERIFY))
     152           0 :     err = decrypt_verify_start (ctx, 0, flags, cipher, plain);
     153             :   else
     154           0 :     err = _gpgme_decrypt_start (ctx, 0, flags, cipher, plain);
     155           0 :   return TRACE_ERR (err);
     156             : }
     157             : 
     158             : 
     159             : /* Decrypt ciphertext CIPHER within CTX and store the resulting
     160             :    plaintext in PLAIN.  */
     161             : gpgme_error_t
     162           5 : gpgme_op_decrypt_ext (gpgme_ctx_t ctx,
     163             :                       gpgme_decrypt_flags_t flags,
     164             :                       gpgme_data_t cipher,
     165             :                       gpgme_data_t plain)
     166             : {
     167             :   gpgme_error_t err;
     168             : 
     169           5 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_ext", ctx,
     170             :               "cipher=%p, plain=%p", cipher, plain);
     171             : 
     172           5 :   if (!ctx)
     173           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
     174             : 
     175           5 :   if ((flags & GPGME_DECRYPT_VERIFY))
     176           2 :     err = decrypt_verify_start (ctx, 1, flags, cipher, plain);
     177             :   else
     178           3 :     err = _gpgme_decrypt_start (ctx, 1, flags, cipher, plain);
     179           5 :   if (!err)
     180           5 :     err = _gpgme_wait_one (ctx);
     181           5 :   ctx->ignore_mdc_error = 0;  /* Always reset.  */
     182           5 :   return TRACE_ERR (err);
     183             : }

Generated by: LCOV version 1.13