1 /* mz.h -- Errors codes, zip flags and magic
2    Version 2.8.1, December 1, 2018
3    part of the MiniZip project
4 
5    Copyright (C) 2010-2018 Nathan Moinvaziri
6      https://github.com/nmoinvaz/minizip
7 
8    This program is distributed under the terms of the same license as zlib.
9    See the accompanying LICENSE file for the full text of the license.
10 */
11 
12 #ifndef MZ_H
13 #define MZ_H
14 
15 /***************************************************************************/
16 
17 /* MZ_VERSION */
18 #define MZ_VERSION                      ("2.8.1")
19 
20 /* MZ_ERROR */
21 #define MZ_OK                           (0)  /* zlib */
22 #define MZ_STREAM_ERROR                 (-1) /* zlib */
23 #define MZ_DATA_ERROR                   (-3) /* zlib */
24 #define MZ_MEM_ERROR                    (-4) /* zlib */
25 #define MZ_BUF_ERROR                    (-5) /* zlib */
26 #define MZ_VERSION_ERROR                (-6) /* zlib */
27 
28 #define MZ_END_OF_LIST                  (-100)
29 #define MZ_END_OF_STREAM                (-101)
30 
31 #define MZ_PARAM_ERROR                  (-102)
32 #define MZ_FORMAT_ERROR                 (-103)
33 #define MZ_INTERNAL_ERROR               (-104)
34 #define MZ_CRC_ERROR                    (-105)
35 #define MZ_CRYPT_ERROR                  (-106)
36 #define MZ_EXIST_ERROR                  (-107)
37 #define MZ_PASSWORD_ERROR               (-108)
38 #define MZ_SUPPORT_ERROR                (-109)
39 #define MZ_HASH_ERROR                   (-110)
40 #define MZ_OPEN_ERROR                   (-111)
41 #define MZ_CLOSE_ERROR                  (-112)
42 #define MZ_SEEK_ERROR                   (-113)
43 #define MZ_TELL_ERROR                   (-114)
44 #define MZ_READ_ERROR                   (-115)
45 #define MZ_WRITE_ERROR                  (-116)
46 #define MZ_SIGN_ERROR                   (-117)
47 
48 /* MZ_OPEN */
49 #define MZ_OPEN_MODE_READ               (0x01)
50 #define MZ_OPEN_MODE_WRITE              (0x02)
51 #define MZ_OPEN_MODE_READWRITE          (MZ_OPEN_MODE_READ | MZ_OPEN_MODE_WRITE)
52 #define MZ_OPEN_MODE_APPEND             (0x04)
53 #define MZ_OPEN_MODE_CREATE             (0x08)
54 #define MZ_OPEN_MODE_EXISTING           (0x10)
55 
56 /* MZ_SEEK */
57 #define MZ_SEEK_SET                     (0)
58 #define MZ_SEEK_CUR                     (1)
59 #define MZ_SEEK_END                     (2)
60 
61 /* MZ_COMPRESS */
62 #define MZ_COMPRESS_METHOD_STORE        (0)
63 #define MZ_COMPRESS_METHOD_DEFLATE      (8)
64 #define MZ_COMPRESS_METHOD_BZIP2        (12)
65 #define MZ_COMPRESS_METHOD_LZMA         (14)
66 #define MZ_COMPRESS_METHOD_AES          (99)
67 
68 #define MZ_COMPRESS_LEVEL_DEFAULT       (-1)
69 #define MZ_COMPRESS_LEVEL_FAST          (2)
70 #define MZ_COMPRESS_LEVEL_NORMAL        (6)
71 #define MZ_COMPRESS_LEVEL_BEST          (9)
72 
73 /* MZ_ZIP_FLAG */
74 #define MZ_ZIP_FLAG_ENCRYPTED           (1 << 0)
75 #define MZ_ZIP_FLAG_LZMA_EOS_MARKER     (1 << 1)
76 #define MZ_ZIP_FLAG_DEFLATE_MAX         (1 << 1)
77 #define MZ_ZIP_FLAG_DEFLATE_NORMAL      (0)
78 #define MZ_ZIP_FLAG_DEFLATE_FAST        (1 << 2)
79 #define MZ_ZIP_FLAG_DEFLATE_SUPER_FAST  (MZ_ZIP_FLAG_DEFLATE_FAST | \
80                                          MZ_ZIP_FLAG_DEFLATE_MAX)
81 #define MZ_ZIP_FLAG_DATA_DESCRIPTOR     (1 << 3)
82 #define MZ_ZIP_FLAG_UTF8                (1 << 11)
83 #define MZ_ZIP_FLAG_MASK_LOCAL_INFO     (1 << 13)
84 
85 /* MZ_ZIP_EXTENSION */
86 #define MZ_ZIP_EXTENSION_ZIP64          (0x0001)
87 #define MZ_ZIP_EXTENSION_NTFS           (0x000a)
88 #define MZ_ZIP_EXTENSION_AES            (0x9901)
89 #define MZ_ZIP_EXTENSION_UNIX1          (0x000d)
90 #define MZ_ZIP_EXTENSION_SIGN           (0x10c5)
91 #define MZ_ZIP_EXTENSION_HASH           (0x1a51)
92 #define MZ_ZIP_EXTENSION_CDCD           (0xcdcd)
93 
94 /* MZ_ZIP64 */
95 #define MZ_ZIP64_AUTO                   (0)
96 #define MZ_ZIP64_FORCE                  (1)
97 #define MZ_ZIP64_DISABLE                (2)
98 
99 /* MZ_HOST_SYSTEM */
100 #define MZ_HOST_SYSTEM(VERSION_MADEBY)  ((uint8_t)(VERSION_MADEBY >> 8))
101 #define MZ_HOST_SYSTEM_MSDOS            (0)
102 #define MZ_HOST_SYSTEM_UNIX             (3)
103 #define MZ_HOST_SYSTEM_WINDOWS_NTFS     (10)
104 #define MZ_HOST_SYSTEM_OSX_DARWIN       (19)
105 
106 /* MZ_PKCRYPT */
107 #define MZ_PKCRYPT_HEADER_SIZE          (12)
108 
109 /* MZ_AES */
110 #define MZ_AES_VERSION                  (1)
111 #define MZ_AES_ENCRYPTION_MODE_128      (0x01)
112 #define MZ_AES_ENCRYPTION_MODE_192      (0x02)
113 #define MZ_AES_ENCRYPTION_MODE_256      (0x03)
114 #define MZ_AES_KEY_LENGTH(MODE)         (8 * (MODE & 3) + 8)
115 #define MZ_AES_KEY_LENGTH_MAX           (32)
116 #define MZ_AES_BLOCK_SIZE               (16)
117 #define MZ_AES_HEADER_SIZE(MODE)        ((4 * (MODE & 3) + 4) + 2)
118 #define MZ_AES_FOOTER_SIZE              (10)
119 
120 /* MZ_HASH */
121 #define MZ_HASH_MD5                     (10)
122 #define MZ_HASH_MD5_SIZE                (16)
123 #define MZ_HASH_SHA1                    (20)
124 #define MZ_HASH_SHA1_SIZE               (20)
125 #define MZ_HASH_SHA256                  (23)
126 #define MZ_HASH_SHA256_SIZE             (32)
127 #define MZ_HASH_MAX_SIZE                (256)
128 
129 /* MZ_ENCODING */
130 #define MZ_ENCODING_CODEPAGE_437        (437)
131 #define MZ_ENCODING_CODEPAGE_932        (932)
132 #define MZ_ENCODING_CODEPAGE_936        (936)
133 #define MZ_ENCODING_CODEPAGE_950        (950)
134 #define MZ_ENCODING_UTF8                (65001)
135 
136 /* MZ_UTILITY */
137 #define MZ_UNUSED(SYMBOL)               ((void)SYMBOL)
138 
139 #ifndef MZ_CUSTOM_ALLOC
140 #define MZ_ALLOC(SIZE)                  (malloc(SIZE))
141 #endif
142 #ifndef MZ_CUSTOM_FREE
143 #define MZ_FREE(PTR)                    (free(PTR))
144 #endif
145 
146 /***************************************************************************/
147 
148 #include <stdlib.h> /* size_t, NULL, malloc */
149 #include <time.h>   /* time_t, time() */
150 #include <string.h> /* memset, strncpy, strlen */
151 #include <limits.h>
152 
153 #ifdef HAVE_STDINT_H
154 #  include <stdint.h>
155 #endif
156 
157 #ifndef __INT8_TYPE__
158 typedef signed char        int8_t;
159 #endif
160 #ifndef __INT16_TYPE__
161 typedef short              int16_t;
162 #endif
163 #ifndef __INT32_TYPE__
164 typedef int                int32_t;
165 #endif
166 #ifndef __INT64_TYPE__
167 typedef long long          int64_t;
168 #endif
169 #ifndef __UINT8_TYPE__
170 typedef unsigned char      uint8_t;
171 #endif
172 #ifndef __UINT16_TYPE__
173 typedef unsigned short     uint16_t;
174 #endif
175 #ifndef __UINT32_TYPE__
176 typedef unsigned int       uint32_t;
177 #endif
178 #ifndef __UINT64_TYPE__
179 typedef unsigned long long uint64_t;
180 #endif
181 
182 #ifdef HAVE_INTTYPES_H
183 #  include <inttypes.h>
184 #endif
185 
186 #ifndef PRId8
187 #  define PRId8  "hhd"
188 #endif
189 #ifndef PRId16
190 #  define PRId16 "hd"
191 #endif
192 #ifndef PRId32
193 #  define PRId32 "d"
194 #endif
195 #ifndef PRIu32
196 #  define PRIu32 "u"
197 #endif
198 #ifndef PRIx32
199 #  define PRIx32 "x"
200 #endif
201 #if ULONG_MAX == 4294967295UL
202 #  ifndef PRId64
203 #    define PRId64 "lld"
204 #  endif
205 #  ifndef PRIu64
206 #    define PRIu64 "llu"
207 #  endif
208 #  ifndef PRIx64
209 #    define PRIx64 "llx"
210 #  endif
211 #else
212 #  ifndef PRId64
213 #    define PRId64 "ld"
214 #  endif
215 #  ifndef PRIu64
216 #    define PRIu64 "lu"
217 #  endif
218 #  ifndef PRIx64
219 #    define PRIx64 "lx"
220 #  endif
221 #endif
222 
223 #ifndef INT16_MAX
224 #  define INT16_MAX   32767
225 #endif
226 #ifndef INT32_MAX
227 #  define INT32_MAX   2147483647L
228 #endif
229 #ifndef INT64_MAX
230 #  define INT64_MAX   9223372036854775807LL
231 #endif
232 #ifndef UINT16_MAX
233 #  define UINT16_MAX  65535U
234 #endif
235 #ifndef UINT32_MAX
236 #  define UINT32_MAX  4294967295UL
237 #endif
238 #ifndef UINT64_MAX
239 #  define UINT64_MAX  18446744073709551615ULL
240 #endif
241 
242 /***************************************************************************/
243 
244 #endif