1 /* hash.c - Hash filters
2 * Copyright (C) 2002-2012 Free Software Foundation, Inc.
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/>
34 hash_encode (void *data
, FILE * in
, FILE * out
)
36 md_filter_t
*mfx
= data
;
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
);
55 return map_gnutls_error (err
);
58 mfx
->md_initialized
= 1;
63 nread
= fread (buf
, 1, BUFSIZE
, in
);
66 _gnutls_hash (&mfx
->md
, buf
, nread
);
69 memset (buf
, 0, sizeof (buf
));
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
;
83 _cdk_log_debug ("free hash filter\n");
84 _gnutls_hash_deinit (&mfx
->md
, NULL
);
85 mfx
->md_initialized
= 0;