LCOV - code coverage report
Current view: top level - src - signers.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 38 92.1 %
Date: 2017-03-02 17:11:10 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* signers.c - Maintain signer sets.
       2             :    Copyright (C) 2001 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 <stdio.h>
      27             : #include <stdlib.h>
      28             : #include <assert.h>
      29             : #include <errno.h>
      30             : 
      31             : #include "gpgme.h"
      32             : #include "util.h"
      33             : #include "context.h"
      34             : #include "debug.h"
      35             : 
      36             : 
      37             : /* Delete all signers from CTX.  */
      38             : void
      39         683 : _gpgme_signers_clear (gpgme_ctx_t ctx)
      40             : {
      41             :   unsigned int i;
      42             : 
      43         683 :   if (!ctx || !ctx->signers)
      44         658 :     return;
      45             : 
      46          57 :   for (i = 0; i < ctx->signers_len; i++)
      47             :     {
      48          32 :       assert (ctx->signers[i]);
      49          32 :       gpgme_key_unref (ctx->signers[i]);
      50          32 :       ctx->signers[i] = NULL;
      51             :     }
      52          25 :   ctx->signers_len = 0;
      53             : }
      54             : 
      55             : 
      56             : void
      57         117 : gpgme_signers_clear (gpgme_ctx_t ctx)
      58             : {
      59         117 :   TRACE (DEBUG_CTX, "gpgme_signers_clear", ctx);
      60         117 :   _gpgme_signers_clear (ctx);
      61         117 : }
      62             : 
      63             : 
      64             : /* Add KEY to list of signers in CTX.  */
      65             : gpgme_error_t
      66          32 : gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key)
      67             : {
      68          32 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_signers_add", ctx,
      69             :               "key=%p (%s)", key, (key && key->subkeys && key->subkeys->fpr) ?
      70             :               key->subkeys->fpr : "invalid");
      71             : 
      72          32 :   if (!ctx || !key)
      73           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
      74             : 
      75          32 :   if (ctx->signers_len == ctx->signers_size)
      76             :     {
      77             :       gpgme_key_t *newarr;
      78          17 :       int n = ctx->signers_size + 5;
      79             :       int j;
      80             : 
      81          17 :       newarr = realloc (ctx->signers, n * sizeof (*newarr));
      82          17 :       if (!newarr)
      83           0 :         return TRACE_ERR (gpg_error_from_syserror ());
      84         102 :       for (j = ctx->signers_size; j < n; j++)
      85          85 :         newarr[j] = NULL;
      86          17 :       ctx->signers = newarr;
      87          17 :       ctx->signers_size = n;
      88             :     }
      89             : 
      90          32 :   gpgme_key_ref (key);
      91          32 :   ctx->signers[ctx->signers_len++] = key;
      92          32 :   return TRACE_SUC ();
      93             : }
      94             : 
      95             : 
      96             : /* Return the number of signers in CTX.  */
      97             : unsigned int
      98         198 : gpgme_signers_count (const gpgme_ctx_t ctx)
      99             : {
     100         198 :   return ctx? ctx->signers_len : 0;
     101             : }
     102             : 
     103             : 
     104             : /* Return the SEQth signer's key in CTX with one reference.  */
     105             : gpgme_key_t
     106         149 : gpgme_signers_enum (const gpgme_ctx_t ctx, int seq)
     107             : {
     108             :   unsigned int seqno;
     109             : 
     110         149 :   if (!ctx || seq < 0)
     111           0 :     return NULL;
     112             : 
     113         149 :   seqno = (unsigned int) seq;
     114         149 :   if (seqno >= ctx->signers_len)
     115          85 :     return NULL;
     116          64 :   gpgme_key_ref (ctx->signers[seqno]);
     117          64 :   return ctx->signers[seqno];
     118             : }

Generated by: LCOV version 1.13