Fix references.
[dragonfly.git] / usr.sbin / pkg_install / sign / gzip.h
1 /*-
2  * Copyright (c) 1999 Marc Espie.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. All advertising materials mentioning features or use of this software
13  *    must display the following acknowledgement:
14  *      This product includes software developed by Marc Espie for the OpenBSD
15  * Project.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS 
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
20  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
21  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $OpenBSD: gzip.h,v 1.2 1999/10/04 21:46:28 espie Exp $
30  * $FreeBSD: src/usr.sbin/pkg_install/sign/gzip.h,v 1.2 2001/05/17 10:12:45 sobomax Exp $
31  * $DragonFly: src/usr.sbin/pkg_install/sign/Attic/gzip.h,v 1.4 2004/07/30 04:46:14 dillon Exp $
32  */
33
34 #define GZIP_MAGIC0     '\037'
35 #define GZIP_MAGIC1     '\213'
36 /* flags values */
37 #define CONTINUATION    0x02
38 #define EXTRA_FIELD     0x04
39
40 /*
41  * Meaningful fields in a gzip header, see gzip proper for details.
42  * This structure should not be fiddled with outside of gzip_read_header
43  * and gzip_write_header 
44  */
45 struct mygzip_header {
46         char method;
47         char flags;
48         char stamp[6];
49         char part[2];
50                 /* remaining extra, after know signs have been read */
51         unsigned int  remaining;
52 };
53         
54 #define TAGSIZE 8
55 #define TAGCHECK 6
56
57 typedef unsigned char SIGNTAG[8];
58
59 /* stack of signatures */
60 struct signature {
61         SIGNTAG tag;
62         int  type;
63         int  length;
64         char *data;
65         struct signature *next;
66 };
67
68 /* returns from gzip_read_header */
69 #define GZIP_UNSIGNED           0       /* gzip file, no signature */
70 #define GZIP_SIGNED             1       /* gzip file, signature parsed ok */
71 #define GZIP_NOT_GZIP           2       /* not a proper gzip file */
72 #define GZIP_NOT_PGPSIGNED      3       /* gzip file, unknown extension */
73 extern int gzip_read_header (FILE *f, /*@out@*/struct mygzip_header *h, \
74         /*@null@*/struct signature **sign);
75 /* gzip_write_header returns 1 for success */
76 extern int gzip_write_header (FILE *f, const struct mygzip_header *h, \
77         /*@null@*/struct signature *sign);
78 /*
79  * Writing header to memory. Returns size needed, or 0 if buffer too small
80  * buffer must be at least 14 characters
81  */
82 extern int gzip_copy_header (const struct mygzip_header *h, \
83         /*@null@*/struct signature *sign, \
84         void (*add)(void *, const char *, size_t), void *data);
85
86 extern void free_signature (/*@null@*/struct signature *sign);
87 extern void sign_fill_tag (struct signature *sign);
88 #define KNOWN_TAGS 4
89 #define TAG_PGP 0
90 #define TAG_SHA1 1
91 #define TAG_X509 2
92 #define TAG_OLD 3
93 #define TAG_ANY -1
94 #define pgptag (known_tags[TAG_PGP])
95 #define sha1tag (known_tags[TAG_SHA1])
96 #define x509tag (known_tags[TAG_X509])
97 extern SIGNTAG known_tags[KNOWN_TAGS];