removed unused variables.
[gnutls.git] / lib / opencdk / hash.c
blob5dcebf80f477c9d369de74821692f1a0a72811bd
1 /* hash.c - Hash filters
2 * Copyright (C) 2002-2012 Free Software Foundation, Inc.
4 * Author: Timo Schulz
6 * This file is part of OpenCDK.
8 * The OpenCDK library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 #include <stdio.h>
27 #include <sys/stat.h>
29 #include "opencdk.h"
30 #include "main.h"
31 #include "filters.h"
33 static cdk_error_t
34 hash_encode (void *data, FILE * in, FILE * out)
36 md_filter_t *mfx = data;
37 byte buf[BUFSIZE];
38 int err;
39 int nread;
41 if (!mfx)
43 gnutls_assert ();
44 return CDK_Inv_Value;
47 _cdk_log_debug ("hash filter: encode algo=%d\n", mfx->digest_algo);
49 if (!mfx->md_initialized)
51 err = _gnutls_hash_init (&mfx->md, mfx->digest_algo);
52 if (err < 0)
54 gnutls_assert ();
55 return map_gnutls_error (err);
58 mfx->md_initialized = 1;
61 while (!feof (in))
63 nread = fread (buf, 1, BUFSIZE, in);
64 if (!nread)
65 break;
66 _gnutls_hash (&mfx->md, buf, nread);
69 memset (buf, 0, sizeof (buf));
70 return 0;
73 cdk_error_t
74 _cdk_filter_hash (void *data, int ctl, FILE * in, FILE * out)
76 if (ctl == STREAMCTL_READ)
77 return hash_encode (data, in, out);
78 else if (ctl == STREAMCTL_FREE)
80 md_filter_t *mfx = data;
81 if (mfx)
83 _cdk_log_debug ("free hash filter\n");
84 _gnutls_hash_deinit (&mfx->md, NULL);
85 mfx->md_initialized = 0;
86 return 0;
90 gnutls_assert ();
91 return CDK_Inv_Mode;