about summary refs log tree commit diff
path: root/src/usr.bin/gzsig/gzip.h
blob: 750a327d78d65a63e39a15c719b55a1fdb4d3f6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * gzip.h
 *
 * Copyright (c) 2001 Dug Song <dugsong@arbor.net>
 * Copyright (c) 2001 Arbor Networks, Inc.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 * 
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *   3. The names of the copyright holders may not be used to endorse or
 *      promote products derived from this software without specific
 *      prior written permission.
 * 
 *   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 *   THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 *   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 *   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 *   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 *   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Vendor: gzip.h,v 1.2 2005/04/01 16:47:31 dugsong Exp $
 */

#ifndef GZIP_H
#define GZIP_H

/* RFC 1952 is b0rked! This is from gzip-1.2.4's algorithm.doc... */

/* Magic header */
#define GZIP_MAGIC		"\037\213"

/* Compression methods */
#define GZIP_MSTORED		0
#define GZIP_MCOMPRESS		1
#define GZIP_MPACKED		2
#define GZIP_MLZHED		3
#define GZIP_MDEFLATE		8

/* Flags */
#define GZIP_FTEXT		0x01
#define GZIP_FCONT		0x02	/* never set by gzip-1.2.4 */
#define GZIP_FEXTRA		0x04
#define GZIP_FNAME		0x08
#define GZIP_FCOMMENT		0x10
#define GZIP_FENCRYPT		0x20
#define GZIP_FRESERVED		0xC0

#define GZIP_FENCRYPT_LEN	12

#define GZSIG_ID		"GS"
#define GZSIG_VERSION		1

struct gzsig_data {
	u_char	version;
#ifdef COMMENT_ONLY
	u_char	signature[];
#endif
};

/*
 * Note: all number fields below are in little-endian byte order.
 */

struct gzip_xfield {
	u_short	len;
	struct gzip_subfield {
		u_char	id[2];
		u_short	len;
#ifdef COMMENT_ONLY
		u_char	data[];
#endif
	} subfield;
};

struct gzip_header {
	u_char		magic[2];
	u_char		method;
	u_char		flags;
	u_char		mtime[4];
	u_char		xflags;
	u_char		os;
#if COMMENT_ONLY
	/* Optional fields */
	u_char		part[2];		/* flags & GZIP_FCONT */
	struct gzip_xfield xfield;		/* flags & GZIP_FEXTRA */
	char		filename[];		/* flags & GZIP_FNAME */
	char		comment[];		/* flags & GZIP_FCOMMENT */
	u_char		encrypt_hdr[12];	/* flags & GZIP_FENCRYPT */
#endif
};

struct gzip_trailer {
	u_int32_t	crc32[4];
	u_int32_t	size[4];
};

#endif /* GZIP_H */