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: 2015-11-05 17:10:59 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 <http://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             : #include <assert.h>
      26             : 
      27             : #include "gpg.h"
      28             : #include "status.h"
      29             : #include "iobuf.h"
      30             : #include "util.h"
      31             : #include "filter.h"
      32             : 
      33             : 
      34             : 
      35             : /****************
      36             :  * This filter is used to collect a message digest
      37             :  */
      38             : int
      39         650 : md_filter( void *opaque, int control,
      40             :                IOBUF a, byte *buf, size_t *ret_len)
      41             : {
      42         650 :     size_t size = *ret_len;
      43         650 :     md_filter_context_t *mfx = opaque;
      44         650 :     int i, rc=0;
      45             : 
      46         650 :     if( control == IOBUFCTRL_UNDERFLOW ) {
      47         416 :         if( mfx->maxbuf_size && size > mfx->maxbuf_size )
      48           0 :             size = mfx->maxbuf_size;
      49         416 :         i = iobuf_read( a, buf, size );
      50         416 :         if( i == -1 ) i = 0;
      51         416 :         if( i ) {
      52         299 :             gcry_md_write(mfx->md, buf, i );
      53         299 :             if( mfx->md2 )
      54           0 :                 gcry_md_write(mfx->md2, buf, i );
      55             :         }
      56             :         else
      57         117 :             rc = -1; /* eof */
      58         416 :         *ret_len = i;
      59             :     }
      60         234 :     else if( control == IOBUFCTRL_DESC )
      61           0 :         *(char**)buf = "md_filter";
      62         650 :     return rc;
      63             : }
      64             : 
      65             : 
      66             : void
      67        2189 : free_md_filter_context( md_filter_context_t *mfx )
      68             : {
      69        2189 :     gcry_md_close(mfx->md);
      70        2189 :     gcry_md_close(mfx->md2);
      71        2189 :     mfx->md = NULL;
      72        2189 :     mfx->md2 = NULL;
      73        2189 :     mfx->maxbuf_size = 0;
      74        2189 : }

Generated by: LCOV version 1.11