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.
10 #include <lib-lib/lib-lib.h>
11 #include <lib-hash/hash.h>
15 #include "pgppacket.h"
17 #define CHUNKSIZE 1024
19 static unsigned char *pbuf = NULL;
20 static size_t plen = 0;
22 static int read_material (size_t material, size_t * used, FILE * fp)
24 if (*used + material >= plen) {
28 nplen = *used + material + CHUNKSIZE;
30 if (!(p = realloc (pbuf, nplen))) { /* __MEM_CHECKED__ */
38 if (fread (pbuf + *used, 1, material, fp) < material) {
47 unsigned char *pgp_read_packet (FILE * fp, size_t * len)
55 startpos = ftello (fp);
58 pbuf = p_new(unsigned char, plen = CHUNKSIZE);
61 if (fread (&ctb, 1, 1, fp) < 1) {
71 if (ctb & 0x40) { /* handle PGP 5.0 packets. */
78 if (fread (&b, 1, 1, fp) < 1) {
88 else if (192 <= b && b <= 223) {
89 material = (b - 192) * 256;
90 if (fread (&b, 1, 1, fp) < 1) {
99 material = 1 << (b & 0x1f);
106 unsigned char buf[4];
108 if (fread (buf, 4, 1, fp) < 1) {
112 /*assert( sizeof(material) >= 4 ); */
113 material = buf[0] << 24;
114 material |= buf[1] << 16;
115 material |= buf[2] << 8;
121 if (read_material (material, &used, fp) == -1)
132 pbuf[0] = 0x80 | ((ctb >> 2) & 0x0f);
135 switch (ctb & 0x03) {
138 if (fread (&b, 1, 1, fp) < 1) {
159 for (i = 0; i < bytes; i++) {
160 if (fread (&b, 1, 1, fp) < 1) {
165 material = (material << 8) + b;
174 if (read_material (material, &used, fp) == -1)
185 fseeko (fp, startpos, SEEK_SET);
189 void pgp_release_packet (void)