"Fossies" - the Fresh Open Source Software Archive

Member "gnupg-2.2.17/g10/filter.h" (9 Jul 2019, 5543 Bytes) of package /linux/misc/gnupg-2.2.17.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "filter.h" see the Fossies "Dox" file reference documentation.

    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 <https://www.gnu.org/licenses/>.
   19  */
   20 #ifndef G10_FILTER_H
   21 #define G10_FILTER_H
   22 
   23 #include "../common/types.h"
   24 #include "dek.h"
   25 
   26 typedef struct {
   27     gcry_md_hd_t md;      /* catch all */
   28     gcry_md_hd_t 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;          /* Initialized to 1.  */
   34 
   35     /* these fields may be initialized */
   36     int what;           /* what kind of armor headers to write */
   37     int only_keyblocks;     /* skip all headers but ".... key block" */
   38     const char *hdrlines;   /* write these headerlines */
   39 
   40     /* these fields must be initialized to zero */
   41     int no_openpgp_data;    /* output flag: "No valid OpenPGP data found" */
   42 
   43     /* the following fields must be initialized to zero */
   44     int inp_checked;        /* set if the input has been checked */
   45     int inp_bypass;     /* set if the input is not armored */
   46     int in_cleartext;       /* clear text message */
   47     int not_dash_escaped;   /* clear text is not dash escaped */
   48     int hashes;         /* detected hash algorithms */
   49     int faked;          /* we are faking a literal data packet */
   50     int truncated;      /* number of truncated lines */
   51     int qp_detected;
   52     byte eol[3];            /* The end of line characters as a
   53                    zero-terminated string.  Defaults
   54                    (eol[0]=='\0') to whatever the local
   55                    platform uses. */
   56 
   57     byte *buffer;       /* malloced buffer */
   58     unsigned buffer_size;   /* and size of this buffer */
   59     unsigned buffer_len;    /* used length of the buffer */
   60     unsigned buffer_pos;    /* read position */
   61 
   62     byte radbuf[4];
   63     int idx, idx2;
   64     u32 crc;
   65 
   66     int status;         /* an internal state flag */
   67     int cancel;
   68     int any_data;       /* any valid armored data seen */
   69     int pending_lf;     /* used together with faked */
   70 } armor_filter_context_t;
   71 
   72 struct unarmor_pump_s;
   73 typedef struct unarmor_pump_s *UnarmorPump;
   74 
   75 
   76 struct compress_filter_context_s {
   77     int status;
   78     void *opaque;   /* (used for z_stream) */
   79     byte *inbuf;
   80     unsigned inbufsize;
   81     byte *outbuf;
   82     unsigned outbufsize;
   83     int algo;    /* compress algo */
   84     int algo1hack;
   85     int new_ctb;
   86     void (*release)(struct compress_filter_context_s*);
   87 };
   88 typedef struct compress_filter_context_s compress_filter_context_t;
   89 
   90 
   91 typedef struct {
   92     DEK *dek;
   93     u32 datalen;
   94     gcry_cipher_hd_t cipher_hd;
   95     unsigned int wrote_header : 1;
   96     unsigned int short_blklen_warn : 1;
   97     unsigned long short_blklen_count;
   98     gcry_md_hd_t mdc_hash;
   99     byte enchash[20];
  100 } cipher_filter_context_t;
  101 
  102 
  103 
  104 typedef struct {
  105     byte *buffer;       /* malloced buffer */
  106     unsigned buffer_size;   /* and size of this buffer */
  107     unsigned buffer_len;    /* used length of the buffer */
  108     unsigned buffer_pos;    /* read position */
  109     int truncated;      /* number of truncated lines */
  110     int not_dash_escaped;
  111     int escape_from;
  112     gcry_md_hd_t md;
  113     int pending_lf;
  114     int pending_esc;
  115 } text_filter_context_t;
  116 
  117 
  118 typedef struct {
  119     char *what;             /* description */
  120     u32 last_time;      /* last time reported */
  121     unsigned long last;     /* last amount reported */
  122     unsigned long offset;   /* current amount */
  123     unsigned long total;    /* total amount */
  124     int  refcount;
  125 } progress_filter_context_t;
  126 
  127 /* encrypt_filter_context_t defined in main.h */
  128 
  129 /*-- mdfilter.c --*/
  130 int md_filter( void *opaque, int control, iobuf_t a, byte *buf, size_t *ret_len);
  131 void free_md_filter_context( md_filter_context_t *mfx );
  132 
  133 /*-- armor.c --*/
  134 armor_filter_context_t *new_armor_context (void);
  135 void release_armor_context (armor_filter_context_t *afx);
  136 int push_armor_filter (armor_filter_context_t *afx, iobuf_t iobuf);
  137 int use_armor_filter( iobuf_t a );
  138 UnarmorPump unarmor_pump_new (void);
  139 void        unarmor_pump_release (UnarmorPump x);
  140 int         unarmor_pump (UnarmorPump x, int c);
  141 
  142 /*-- compress.c --*/
  143 gpg_error_t push_compress_filter (iobuf_t out, compress_filter_context_t *zfx,
  144                                   int algo);
  145 gpg_error_t push_compress_filter2 (iobuf_t out,compress_filter_context_t *zfx,
  146                                    int algo, int rel);
  147 
  148 /*-- cipher.c --*/
  149 int cipher_filter( void *opaque, int control,
  150            iobuf_t chain, byte *buf, size_t *ret_len);
  151 
  152 /*-- textfilter.c --*/
  153 int text_filter( void *opaque, int control,
  154          iobuf_t chain, byte *buf, size_t *ret_len);
  155 int copy_clearsig_text (iobuf_t out, iobuf_t inp, gcry_md_hd_t md,
  156                         int escape_dash, int escape_from);
  157 
  158 /*-- progress.c --*/
  159 progress_filter_context_t *new_progress_context (void);
  160 void release_progress_context (progress_filter_context_t *pfx);
  161 void handle_progress (progress_filter_context_t *pfx,
  162               iobuf_t inp, const char *name);
  163 
  164 #endif /*G10_FILTER_H*/