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