LCOV - code coverage report
Current view: top level - src - decrypt-verify.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 30 43 69.8 %
Date: 2016-12-01 18:45:36 Functions: 3 4 75.0 %

          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 "debug.h"
      27             : #include "gpgme.h"
      28             : #include "ops.h"
      29             : 
      30             : 
      31             : static gpgme_error_t
      32         223 : decrypt_verify_status_handler (void *priv, gpgme_status_code_t code,
      33             :                                char *args)
      34             : {
      35             :   gpgme_error_t err;
      36             : 
      37         223 :   err = _gpgme_progress_status_handler (priv, code, args);
      38         223 :   if (!err)
      39         223 :     err = _gpgme_decrypt_status_handler (priv, code, args);
      40         223 :   if (!err)
      41         223 :       err = _gpgme_verify_status_handler (priv, code, args);
      42         223 :   return err;
      43             : }
      44             : 
      45             : 
      46             : static gpgme_error_t
      47          13 : decrypt_verify_start (gpgme_ctx_t ctx, int synchronous,
      48             :                       gpgme_data_t cipher, gpgme_data_t plain)
      49             : {
      50             :   gpgme_error_t err;
      51             : 
      52          13 :   err = _gpgme_op_reset (ctx, synchronous);
      53          13 :   if (err)
      54           0 :     return err;
      55             : 
      56          13 :   err = _gpgme_op_decrypt_init_result (ctx);
      57          13 :   if (err)
      58           0 :     return err;
      59             : 
      60          13 :   err = _gpgme_op_verify_init_result (ctx);
      61          13 :   if (err)
      62           0 :     return err;
      63             : 
      64          13 :   if (!cipher)
      65           0 :     return gpg_error (GPG_ERR_NO_DATA);
      66          13 :   if (!plain)
      67           0 :     return gpg_error (GPG_ERR_INV_VALUE);
      68             : 
      69          13 :   if (ctx->passphrase_cb)
      70             :     {
      71           5 :       err = _gpgme_engine_set_command_handler
      72             :         (ctx->engine, _gpgme_passphrase_command_handler, ctx, NULL);
      73           5 :       if (err)
      74           0 :         return err;
      75             :     }
      76             : 
      77          13 :   _gpgme_engine_set_status_handler (ctx->engine,
      78             :                                     decrypt_verify_status_handler, ctx);
      79             : 
      80          13 :   return _gpgme_engine_op_decrypt_verify (ctx->engine, cipher, plain,
      81          13 :                                           ctx->export_session_keys,
      82          13 :                                           ctx->override_session_key);
      83             : }
      84             : 
      85             : 
      86             : /* Decrypt ciphertext CIPHER and make a signature verification within
      87             :    CTX and store the resulting plaintext in PLAIN.  */
      88             : gpgme_error_t
      89           0 : gpgme_op_decrypt_verify_start (gpgme_ctx_t ctx, gpgme_data_t cipher,
      90             :                                gpgme_data_t plain)
      91             : {
      92             :   gpgme_error_t err;
      93             : 
      94           0 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify_start", ctx,
      95             :               "cipher=%p, plain=%p", cipher, plain);
      96             : 
      97           0 :   if (!ctx)
      98           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
      99             : 
     100           0 :   err = decrypt_verify_start (ctx, 0, cipher, plain);
     101           0 :   return TRACE_ERR (err);
     102             : }
     103             : 
     104             : 
     105             : /* Decrypt ciphertext CIPHER and make a signature verification within
     106             :    CTX and store the resulting plaintext in PLAIN.  */
     107             : gpgme_error_t
     108          13 : gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher,
     109             :                          gpgme_data_t plain)
     110             : {
     111             :   gpgme_error_t err;
     112             : 
     113          13 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify", ctx,
     114             :               "cipher=%p, plain=%p", cipher, plain);
     115             : 
     116          13 :   if (!ctx)
     117           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
     118             : 
     119          13 :   err = decrypt_verify_start (ctx, 1, cipher, plain);
     120          13 :   if (!err)
     121          13 :     err = _gpgme_wait_one (ctx);
     122          13 :   return TRACE_ERR (err);
     123             : }

Generated by: LCOV version 1.11