1 /*
2  * Portions copyright 2002, 2003 Richard Laager.
3  * Copyright (c) 1996, 1997, 1998, 1999, Marc Horowitz.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Marc Horowitz.
17  * 4. The name of the author may not be used to endorse or promote
18  *    products derived from this software without specific prior written
19  *    permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY MARC HOROWITZ ``AS IS'' AND ANY EXPRESS
22  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED.  IN NO EVENT SHALL MARC HOROWITZ BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37 
38 #ifndef _PGPUTIL_H_
39 #define _PGPUTIL_H_
40 
41 /*
42  * $Id: pgputil.h,v 1.5 2003/02/28 17:17:27 rlaager Exp $
43  */
44 
45 #if HAVE_TIME_H
46 #include <time.h>
47 #endif
48 
49 typedef struct _ddesc
50 {
51   unsigned char *data;
52   long size;
53   long offset;
54 }
55 ddesc;
56 
57 typedef struct _mpidesc
58 {
59   long nbits;
60   ddesc number;
61 }
62 mpidesc;
63 
64 #define DECODE_READABLE(data, length) \
65 	((data)->size >= ((data)->offset + (length)))
66 
67 typedef int (*packet_handler) (ddesc * packet, void *closure);
68 
69 int decode_num (ddesc * data, long size, long *num);
70 int decode_psf (ddesc * data, long *ptype, long *plen);
71 int decode_pubkey (ddesc * data, long len, mpidesc * modulus,
72 		   mpidesc * exponent, unsigned char *keyid,
73 		   unsigned char *keytype, time_t * create_time,
74 		   int *keyversion);
75 int decode_userid (ddesc * data, long len, ddesc * userid);
76 int decode_sig (ddesc * data, long len, ddesc * keyid, long *sigclass,
77 		time_t * sigtime);
78 int decode_file (ddesc * data, packet_handler h, void *c);
79 int decode_binary (ddesc * data, packet_handler h, void *c);
80 
81 #endif
82