1
/* kbxio.c - KBX I/O handling
2
* Copyright (C) 2000 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
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 2 of the License, or
9
* (at your option) any later version.
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.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
36
kbx_read_blob ( KBXBLOB *r_blob, FILE *a )
44
if ( (c1 = getc ( a )) == EOF
45
|| (c2 = getc ( a )) == EOF
46
|| (c3 = getc ( a )) == EOF
47
|| (c4 = getc ( a )) == EOF ) {
48
if ( c1 == EOF && !ferror ( a ) )
50
return GPGERR_GENERAL;
52
imagelen = (c1 << 24) | (c2 << 16) | (c3 << 8 ) | c4;
53
if ( imagelen > 500000 ) { /* sanity check:blob too large */
54
return GPGERR_GENERAL;
56
else if ( imagelen < 4 ) { /* blobtoo short */
57
return GPGERR_GENERAL;
59
image = gcry_malloc ( imagelen );
61
return GPGERR_GENERAL;
64
image[0] = c1; image[1] = c2; image[2] = c3; image[3] = c4;
65
if ( fread ( image+4, imagelen-4, 1, a ) != 1 ) {
67
return GPGERR_GENERAL;
70
rc = kbx_new_blob ( r_blob, image, imagelen );