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.
20 #include <lib-lib/mem.h>
25 #include "pgppacket.h"
29 #define CHUNKSIZE 1024
31 static unsigned char *pbuf = NULL;
32 static size_t plen = 0;
34 static int read_material (size_t material, size_t * used, FILE * fp)
36 if (*used + material >= plen) {
40 nplen = *used + material + CHUNKSIZE;
42 if (!(p = realloc (pbuf, nplen))) { /* __MEM_CHECKED__ */
50 if (fread (pbuf + *used, 1, material, fp) < material) {
59 unsigned char *pgp_read_packet (FILE * fp, size_t * len)
67 startpos = ftello (fp);
70 pbuf = p_new(char, plen = CHUNKSIZE);
73 if (fread (&ctb, 1, 1, fp) < 1) {
83 if (ctb & 0x40) { /* handle PGP 5.0 packets. */
90 if (fread (&b, 1, 1, fp) < 1) {
100 else if (192 <= b && b <= 223) {
101 material = (b - 192) * 256;
102 if (fread (&b, 1, 1, fp) < 1) {
111 material = 1 << (b & 0x1f);
118 unsigned char buf[4];
120 if (fread (buf, 4, 1, fp) < 1) {
124 /*assert( sizeof(material) >= 4 ); */
125 material = buf[0] << 24;
126 material |= buf[1] << 16;
127 material |= buf[2] << 8;
133 if (read_material (material, &used, fp) == -1)
144 pbuf[0] = 0x80 | ((ctb >> 2) & 0x0f);
147 switch (ctb & 0x03) {
150 if (fread (&b, 1, 1, fp) < 1) {
171 for (i = 0; i < bytes; i++) {
172 if (fread (&b, 1, 1, fp) < 1) {
177 material = (material << 8) + b;
186 if (read_material (material, &used, fp) == -1)
197 fseeko (fp, startpos, SEEK_SET);
201 void pgp_release_packet (void)