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"
27 #define CHUNKSIZE 1024
29 static unsigned char *pbuf = NULL;
30 static size_t plen = 0;
32 static int read_material (size_t material, size_t * used, FILE * fp)
34 if (*used + material >= plen) {
38 nplen = *used + material + CHUNKSIZE;
40 if (!(p = realloc (pbuf, nplen))) { /* __MEM_CHECKED__ */
48 if (fread (pbuf + *used, 1, material, fp) < material) {
57 unsigned char *pgp_read_packet (FILE * fp, size_t * len)
65 startpos = ftell (fp);
69 pbuf = safe_malloc (plen);
72 if (fread (&ctb, 1, 1, fp) < 1) {
82 if (ctb & 0x40) { /* handle PGP 5.0 packets. */
89 if (fread (&b, 1, 1, fp) < 1) {
99 else if (192 <= b && b <= 223) {
100 material = (b - 192) * 256;
101 if (fread (&b, 1, 1, fp) < 1) {
110 material = 1 << (b & 0x1f);
117 unsigned char buf[4];
119 if (fread (buf, 4, 1, fp) < 1) {
123 /*assert( sizeof(material) >= 4 ); */
124 material = buf[0] << 24;
125 material |= buf[1] << 16;
126 material |= buf[2] << 8;
132 if (read_material (material, &used, fp) == -1)
143 pbuf[0] = 0x80 | ((ctb >> 2) & 0x0f);
146 switch (ctb & 0x03) {
149 if (fread (&b, 1, 1, fp) < 1) {
170 for (i = 0; i < bytes; i++) {
171 if (fread (&b, 1, 1, fp) < 1) {
176 material = (material << 8) + b;
185 if (read_material (material, &used, fp) == -1)
196 fseek (fp, startpos, SEEK_SET);
200 void pgp_release_packet (void)