2 * Copyright notice from original mutt:
3 * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
23 #include "pgppacket.h"
25 #define CHUNKSIZE 1024
27 static unsigned char *pbuf = NULL;
28 static size_t plen = 0;
30 static int read_material (size_t material, size_t * used, FILE * fp)
32 if (*used + material >= plen) {
36 nplen = *used + material + CHUNKSIZE;
38 if (!(p = realloc (pbuf, nplen))) { /* __MEM_CHECKED__ */
46 if (fread (pbuf + *used, 1, material, fp) < material) {
55 unsigned char *pgp_read_packet (FILE * fp, size_t * len)
63 startpos = ftell (fp);
67 pbuf = safe_malloc (plen);
70 if (fread (&ctb, 1, 1, fp) < 1) {
80 if (ctb & 0x40) { /* handle PGP 5.0 packets. */
87 if (fread (&b, 1, 1, fp) < 1) {
97 else if (192 <= b && b <= 223) {
98 material = (b - 192) * 256;
99 if (fread (&b, 1, 1, fp) < 1) {
108 material = 1 << (b & 0x1f);
115 unsigned char buf[4];
117 if (fread (buf, 4, 1, fp) < 1) {
121 /*assert( sizeof(material) >= 4 ); */
122 material = buf[0] << 24;
123 material |= buf[1] << 16;
124 material |= buf[2] << 8;
130 if (read_material (material, &used, fp) == -1)
141 pbuf[0] = 0x80 | ((ctb >> 2) & 0x0f);
144 switch (ctb & 0x03) {
147 if (fread (&b, 1, 1, fp) < 1) {
168 for (i = 0; i < bytes; i++) {
169 if (fread (&b, 1, 1, fp) < 1) {
174 material = (material << 8) + b;
183 if (read_material (material, &used, fp) == -1)
194 fseek (fp, startpos, SEEK_SET);
198 void pgp_release_packet (void)