1 /* filter.h 2 * Copyright (C) 1998, 1999, 2000, 2001, 2003, 3 * 2005 Free Software Foundation, Inc. 4 * 5 * This file is part of GnuPG. 6 * 7 * GnuPG is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * GnuPG is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, see <http://www.gnu.org/licenses/>. 19 */ 20 #ifndef G10_FILTER_H 21 #define G10_FILTER_H 22 23 #include "types.h" 24 #include "cipher.h" 25 26 typedef struct { 27 MD_HANDLE md; /* catch all */ 28 MD_HANDLE md2; /* if we want to calculate an alternate hash */ 29 size_t maxbuf_size; 30 } md_filter_context_t; 31 32 typedef struct { 33 int refcount; /* Reference counter. If 0 this structure 34 is not allocated on the heap. */ 35 36 /* these fields may be initialized */ 37 int what; /* what kind of armor headers to write */ 38 int only_keyblocks; /* skip all headers but ".... key block" */ 39 const char *hdrlines; /* write these headerlines */ 40 41 /* these fileds must be initialized to zero */ 42 int no_openpgp_data; /* output flag: "No valid OpenPGP data found" */ 43 int key_failed_code; /* Error code from the first gpgkkeys_* 44 "KEY <keyid> FAILED <err>" line. */ 45 46 /* the following fields must be initialized to zero */ 47 int inp_checked; /* set if the input has been checked */ 48 int inp_bypass; /* set if the input is not armored */ 49 int in_cleartext; /* clear text message */ 50 int not_dash_escaped; /* clear text is not dash escaped */ 51 int hashes; /* detected hash algorithms */ 52 int faked; /* we are faking a literal data packet */ 53 int truncated; /* number of truncated lines */ 54 int qp_detected; 55 int pgp2mode; 56 byte eol[3]; /* The end of line characters as a 57 zero-terminated string. Defaults 58 (eol[0]=='\0') to whatever the local 59 platform uses. */ 60 61 byte *buffer; /* malloced buffer */ 62 unsigned buffer_size; /* and size of this buffer */ 63 unsigned buffer_len; /* used length of the buffer */ 64 unsigned buffer_pos; /* read position */ 65 66 byte radbuf[4]; 67 int idx, idx2; 68 u32 crc; 69 70 int status; /* an internal state flag */ 71 int cancel; 72 int any_data; /* any valid armored data seen */ 73 int pending_lf; /* used together with faked */ 74 } armor_filter_context_t; 75 76 struct unarmor_pump_s; 77 typedef struct unarmor_pump_s *UnarmorPump; 78 79 80 struct compress_filter_context_s { 81 int status; 82 void *opaque; /* (used for z_stream) */ 83 byte *inbuf; 84 unsigned inbufsize; 85 byte *outbuf; 86 unsigned outbufsize; 87 int algo; /* compress algo */ 88 int algo1hack; 89 int new_ctb; 90 void (*release)(struct compress_filter_context_s*); 91 }; 92 typedef struct compress_filter_context_s compress_filter_context_t; 93 94 95 typedef struct { 96 DEK *dek; 97 u32 datalen; 98 CIPHER_HANDLE cipher_hd; 99 int header; 100 MD_HANDLE mdc_hash; 101 byte enchash[20]; 102 int create_mdc; /* flag will be set by the cipher filter */ 103 } cipher_filter_context_t; 104 105 106 107 typedef struct { 108 byte *buffer; /* malloced buffer */ 109 unsigned buffer_size; /* and size of this buffer */ 110 unsigned buffer_len; /* used length of the buffer */ 111 unsigned buffer_pos; /* read position */ 112 int truncated; /* number of truncated lines */ 113 int not_dash_escaped; 114 int escape_from; 115 MD_HANDLE md; 116 int pending_lf; 117 int pending_esc; 118 } text_filter_context_t; 119 120 121 typedef struct { 122 char *what; /* description */ 123 u32 last_time; /* last time reported */ 124 unsigned long last; /* last amount reported */ 125 unsigned long offset; /* current amount */ 126 unsigned long total; /* total amount */ 127 } progress_filter_context_t; 128 129 /* encrypt_filter_context_t defined in main.h */ 130 131 /*-- mdfilter.c --*/ 132 int md_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len); 133 void free_md_filter_context( md_filter_context_t *mfx ); 134 135 /*-- armor.c --*/ 136 armor_filter_context_t *new_armor_context (void); 137 void release_armor_context (armor_filter_context_t *afx); 138 int push_armor_filter (armor_filter_context_t *afx, IOBUF iobuf); 139 int use_armor_filter( IOBUF a ); 140 int armor_filter( void *opaque, int control, 141 IOBUF chain, byte *buf, size_t *ret_len); 142 UnarmorPump unarmor_pump_new (void); 143 void unarmor_pump_release (UnarmorPump x); 144 int unarmor_pump (UnarmorPump x, int c); 145 146 /*-- compress.c --*/ 147 void push_compress_filter(IOBUF out,compress_filter_context_t *zfx,int algo); 148 void push_compress_filter2(IOBUF out,compress_filter_context_t *zfx, 149 int algo,int rel); 150 151 /*-- cipher.c --*/ 152 int cipher_filter( void *opaque, int control, 153 IOBUF chain, byte *buf, size_t *ret_len); 154 155 /*-- textfilter.c --*/ 156 int text_filter( void *opaque, int control, 157 IOBUF chain, byte *buf, size_t *ret_len); 158 int copy_clearsig_text( IOBUF out, IOBUF inp, MD_HANDLE md, 159 int escape_dash, int escape_from, int pgp2mode ); 160 161 /*-- progress.c --*/ 162 int progress_filter (void *opaque, int control, 163 IOBUF a, byte *buf, size_t *ret_len); 164 void handle_progress (progress_filter_context_t *pfx, 165 IOBUF inp, const char *name); 166 167 #endif /*G10_FILTER_H*/ 168