LCOV - code coverage report
Current view: top level - g10 - mdfilter.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 25 88.0 %
Date: 2016-11-29 15:00:56 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* mdfilter.c - filter data and calculate a message digest
       2             :  * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
       3             :  *
       4             :  * This file is part of GnuPG.
       5             :  *
       6             :  * GnuPG is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * GnuPG is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program; if not, see <https://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include <config.h>
      21             : #include <stdio.h>
      22             : #include <stdlib.h>
      23             : #include <string.h>
      24             : #include <errno.h>
      25             : 
      26             : #include "gpg.h"
      27             : #include "status.h"
      28             : #include "iobuf.h"
      29             : #include "util.h"
      30             : #include "filter.h"
      31             : 
      32             : 
      33             : 
      34             : /****************
      35             :  * This filter is used to collect a message digest
      36             :  */
      37             : int
      38         746 : md_filter( void *opaque, int control,
      39             :                IOBUF a, byte *buf, size_t *ret_len)
      40             : {
      41         746 :     size_t size = *ret_len;
      42         746 :     md_filter_context_t *mfx = opaque;
      43         746 :     int i, rc=0;
      44             : 
      45         746 :     if( control == IOBUFCTRL_UNDERFLOW ) {
      46         480 :         if( mfx->maxbuf_size && size > mfx->maxbuf_size )
      47           0 :             size = mfx->maxbuf_size;
      48         480 :         i = iobuf_read( a, buf, size );
      49         480 :         if( i == -1 ) i = 0;
      50         480 :         if( i ) {
      51         347 :             gcry_md_write(mfx->md, buf, i );
      52         347 :             if( mfx->md2 )
      53           0 :                 gcry_md_write(mfx->md2, buf, i );
      54             :         }
      55             :         else
      56         133 :             rc = -1; /* eof */
      57         480 :         *ret_len = i;
      58             :     }
      59         266 :     else if( control == IOBUFCTRL_DESC )
      60           0 :         mem2str (buf, "md_filter", *ret_len);
      61         746 :     return rc;
      62             : }
      63             : 
      64             : 
      65             : void
      66        1695 : free_md_filter_context( md_filter_context_t *mfx )
      67             : {
      68        1695 :     gcry_md_close(mfx->md);
      69        1695 :     gcry_md_close(mfx->md2);
      70        1695 :     mfx->md = NULL;
      71        1695 :     mfx->md2 = NULL;
      72        1695 :     mfx->maxbuf_size = 0;
      73        1695 : }

Generated by: LCOV version 1.11