ZipConstants.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. using System;
  2. namespace ICSharpCode.SharpZipLib.Zip
  3. {
  4. #region Enumerations
  5. /// <summary>
  6. /// Determines how entries are tested to see if they should use Zip64 extensions or not.
  7. /// </summary>
  8. public enum UseZip64
  9. {
  10. /// <summary>
  11. /// Zip64 will not be forced on entries during processing.
  12. /// </summary>
  13. /// <remarks>An entry can have this overridden if required <see cref="ZipEntry.ForceZip64"></see></remarks>
  14. Off,
  15. /// <summary>
  16. /// Zip64 should always be used.
  17. /// </summary>
  18. On,
  19. /// <summary>
  20. /// #ZipLib will determine use based on entry values when added to archive.
  21. /// </summary>
  22. Dynamic,
  23. }
  24. /// <summary>
  25. /// The kind of compression used for an entry in an archive
  26. /// </summary>
  27. public enum CompressionMethod
  28. {
  29. /// <summary>
  30. /// A direct copy of the file contents is held in the archive
  31. /// </summary>
  32. Stored = 0,
  33. /// <summary>
  34. /// Common Zip compression method using a sliding dictionary
  35. /// of up to 32KB and secondary compression from Huffman/Shannon-Fano trees
  36. /// </summary>
  37. Deflated = 8,
  38. /// <summary>
  39. /// An extension to deflate with a 64KB window. Not supported by #Zip currently
  40. /// </summary>
  41. Deflate64 = 9,
  42. /// <summary>
  43. /// BZip2 compression. Not supported by #Zip.
  44. /// </summary>
  45. BZip2 = 12,
  46. /// <summary>
  47. /// LZMA compression. Not supported by #Zip.
  48. /// </summary>
  49. LZMA = 14,
  50. /// <summary>
  51. /// PPMd compression. Not supported by #Zip.
  52. /// </summary>
  53. PPMd = 98,
  54. /// <summary>
  55. /// WinZip special for AES encryption, Now supported by #Zip.
  56. /// </summary>
  57. WinZipAES = 99,
  58. }
  59. /// <summary>
  60. /// Identifies the encryption algorithm used for an entry
  61. /// </summary>
  62. public enum EncryptionAlgorithm
  63. {
  64. /// <summary>
  65. /// No encryption has been used.
  66. /// </summary>
  67. None = 0,
  68. /// <summary>
  69. /// Encrypted using PKZIP 2.0 or 'classic' encryption.
  70. /// </summary>
  71. PkzipClassic = 1,
  72. /// <summary>
  73. /// DES encryption has been used.
  74. /// </summary>
  75. Des = 0x6601,
  76. /// <summary>
  77. /// RC2 encryption has been used for encryption.
  78. /// </summary>
  79. RC2 = 0x6602,
  80. /// <summary>
  81. /// Triple DES encryption with 168 bit keys has been used for this entry.
  82. /// </summary>
  83. TripleDes168 = 0x6603,
  84. /// <summary>
  85. /// Triple DES with 112 bit keys has been used for this entry.
  86. /// </summary>
  87. TripleDes112 = 0x6609,
  88. /// <summary>
  89. /// AES 128 has been used for encryption.
  90. /// </summary>
  91. Aes128 = 0x660e,
  92. /// <summary>
  93. /// AES 192 has been used for encryption.
  94. /// </summary>
  95. Aes192 = 0x660f,
  96. /// <summary>
  97. /// AES 256 has been used for encryption.
  98. /// </summary>
  99. Aes256 = 0x6610,
  100. /// <summary>
  101. /// RC2 corrected has been used for encryption.
  102. /// </summary>
  103. RC2Corrected = 0x6702,
  104. /// <summary>
  105. /// Blowfish has been used for encryption.
  106. /// </summary>
  107. Blowfish = 0x6720,
  108. /// <summary>
  109. /// Twofish has been used for encryption.
  110. /// </summary>
  111. Twofish = 0x6721,
  112. /// <summary>
  113. /// RC4 has been used for encryption.
  114. /// </summary>
  115. RC4 = 0x6801,
  116. /// <summary>
  117. /// An unknown algorithm has been used for encryption.
  118. /// </summary>
  119. Unknown = 0xffff
  120. }
  121. /// <summary>
  122. /// Defines the contents of the general bit flags field for an archive entry.
  123. /// </summary>
  124. [Flags]
  125. public enum GeneralBitFlags
  126. {
  127. /// <summary>
  128. /// Bit 0 if set indicates that the file is encrypted
  129. /// </summary>
  130. Encrypted = 0x0001,
  131. /// <summary>
  132. /// Bits 1 and 2 - Two bits defining the compression method (only for Method 6 Imploding and 8,9 Deflating)
  133. /// </summary>
  134. Method = 0x0006,
  135. /// <summary>
  136. /// Bit 3 if set indicates a trailing data desciptor is appended to the entry data
  137. /// </summary>
  138. Descriptor = 0x0008,
  139. /// <summary>
  140. /// Bit 4 is reserved for use with method 8 for enhanced deflation
  141. /// </summary>
  142. ReservedPKware4 = 0x0010,
  143. /// <summary>
  144. /// Bit 5 if set indicates the file contains Pkzip compressed patched data.
  145. /// Requires version 2.7 or greater.
  146. /// </summary>
  147. Patched = 0x0020,
  148. /// <summary>
  149. /// Bit 6 if set indicates strong encryption has been used for this entry.
  150. /// </summary>
  151. StrongEncryption = 0x0040,
  152. /// <summary>
  153. /// Bit 7 is currently unused
  154. /// </summary>
  155. Unused7 = 0x0080,
  156. /// <summary>
  157. /// Bit 8 is currently unused
  158. /// </summary>
  159. Unused8 = 0x0100,
  160. /// <summary>
  161. /// Bit 9 is currently unused
  162. /// </summary>
  163. Unused9 = 0x0200,
  164. /// <summary>
  165. /// Bit 10 is currently unused
  166. /// </summary>
  167. Unused10 = 0x0400,
  168. /// <summary>
  169. /// Bit 11 if set indicates the filename and
  170. /// comment fields for this file must be encoded using UTF-8.
  171. /// </summary>
  172. UnicodeText = 0x0800,
  173. /// <summary>
  174. /// Bit 12 is documented as being reserved by PKware for enhanced compression.
  175. /// </summary>
  176. EnhancedCompress = 0x1000,
  177. /// <summary>
  178. /// Bit 13 if set indicates that values in the local header are masked to hide
  179. /// their actual values, and the central directory is encrypted.
  180. /// </summary>
  181. /// <remarks>
  182. /// Used when encrypting the central directory contents.
  183. /// </remarks>
  184. HeaderMasked = 0x2000,
  185. /// <summary>
  186. /// Bit 14 is documented as being reserved for use by PKware
  187. /// </summary>
  188. ReservedPkware14 = 0x4000,
  189. /// <summary>
  190. /// Bit 15 is documented as being reserved for use by PKware
  191. /// </summary>
  192. ReservedPkware15 = 0x8000
  193. }
  194. #endregion Enumerations
  195. /// <summary>
  196. /// This class contains constants used for Zip format files
  197. /// </summary>
  198. public static class ZipConstants
  199. {
  200. #region Versions
  201. /// <summary>
  202. /// The version made by field for entries in the central header when created by this library
  203. /// </summary>
  204. /// <remarks>
  205. /// This is also the Zip version for the library when comparing against the version required to extract
  206. /// for an entry. See <see cref="ZipEntry.CanDecompress"/>.
  207. /// </remarks>
  208. public const int VersionMadeBy = 51; // was 45 before AES
  209. /// <summary>
  210. /// The version made by field for entries in the central header when created by this library
  211. /// </summary>
  212. /// <remarks>
  213. /// This is also the Zip version for the library when comparing against the version required to extract
  214. /// for an entry. See <see cref="ZipInputStream.CanDecompressEntry">ZipInputStream.CanDecompressEntry</see>.
  215. /// </remarks>
  216. [Obsolete("Use VersionMadeBy instead")]
  217. public const int VERSION_MADE_BY = 51;
  218. /// <summary>
  219. /// The minimum version required to support strong encryption
  220. /// </summary>
  221. public const int VersionStrongEncryption = 50;
  222. /// <summary>
  223. /// The minimum version required to support strong encryption
  224. /// </summary>
  225. [Obsolete("Use VersionStrongEncryption instead")]
  226. public const int VERSION_STRONG_ENCRYPTION = 50;
  227. /// <summary>
  228. /// Version indicating AES encryption
  229. /// </summary>
  230. public const int VERSION_AES = 51;
  231. /// <summary>
  232. /// The version required for Zip64 extensions (4.5 or higher)
  233. /// </summary>
  234. public const int VersionZip64 = 45;
  235. #endregion Versions
  236. #region Header Sizes
  237. /// <summary>
  238. /// Size of local entry header (excluding variable length fields at end)
  239. /// </summary>
  240. public const int LocalHeaderBaseSize = 30;
  241. /// <summary>
  242. /// Size of local entry header (excluding variable length fields at end)
  243. /// </summary>
  244. [Obsolete("Use LocalHeaderBaseSize instead")]
  245. public const int LOCHDR = 30;
  246. /// <summary>
  247. /// Size of Zip64 data descriptor
  248. /// </summary>
  249. public const int Zip64DataDescriptorSize = 24;
  250. /// <summary>
  251. /// Size of data descriptor
  252. /// </summary>
  253. public const int DataDescriptorSize = 16;
  254. /// <summary>
  255. /// Size of data descriptor
  256. /// </summary>
  257. [Obsolete("Use DataDescriptorSize instead")]
  258. public const int EXTHDR = 16;
  259. /// <summary>
  260. /// Size of central header entry (excluding variable fields)
  261. /// </summary>
  262. public const int CentralHeaderBaseSize = 46;
  263. /// <summary>
  264. /// Size of central header entry
  265. /// </summary>
  266. [Obsolete("Use CentralHeaderBaseSize instead")]
  267. public const int CENHDR = 46;
  268. /// <summary>
  269. /// Size of end of central record (excluding variable fields)
  270. /// </summary>
  271. public const int EndOfCentralRecordBaseSize = 22;
  272. /// <summary>
  273. /// Size of end of central record (excluding variable fields)
  274. /// </summary>
  275. [Obsolete("Use EndOfCentralRecordBaseSize instead")]
  276. public const int ENDHDR = 22;
  277. /// <summary>
  278. /// Size of 'classic' cryptographic header stored before any entry data
  279. /// </summary>
  280. public const int CryptoHeaderSize = 12;
  281. /// <summary>
  282. /// Size of cryptographic header stored before entry data
  283. /// </summary>
  284. [Obsolete("Use CryptoHeaderSize instead")]
  285. public const int CRYPTO_HEADER_SIZE = 12;
  286. /// <summary>
  287. /// The size of the Zip64 central directory locator.
  288. /// </summary>
  289. public const int Zip64EndOfCentralDirectoryLocatorSize = 20;
  290. #endregion Header Sizes
  291. #region Header Signatures
  292. /// <summary>
  293. /// Signature for local entry header
  294. /// </summary>
  295. public const int LocalHeaderSignature = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
  296. /// <summary>
  297. /// Signature for local entry header
  298. /// </summary>
  299. [Obsolete("Use LocalHeaderSignature instead")]
  300. public const int LOCSIG = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
  301. /// <summary>
  302. /// Signature for spanning entry
  303. /// </summary>
  304. public const int SpanningSignature = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
  305. /// <summary>
  306. /// Signature for spanning entry
  307. /// </summary>
  308. [Obsolete("Use SpanningSignature instead")]
  309. public const int SPANNINGSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
  310. /// <summary>
  311. /// Signature for temporary spanning entry
  312. /// </summary>
  313. public const int SpanningTempSignature = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
  314. /// <summary>
  315. /// Signature for temporary spanning entry
  316. /// </summary>
  317. [Obsolete("Use SpanningTempSignature instead")]
  318. public const int SPANTEMPSIG = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
  319. /// <summary>
  320. /// Signature for data descriptor
  321. /// </summary>
  322. /// <remarks>
  323. /// This is only used where the length, Crc, or compressed size isnt known when the
  324. /// entry is created and the output stream doesnt support seeking.
  325. /// The local entry cannot be 'patched' with the correct values in this case
  326. /// so the values are recorded after the data prefixed by this header, as well as in the central directory.
  327. /// </remarks>
  328. public const int DataDescriptorSignature = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
  329. /// <summary>
  330. /// Signature for data descriptor
  331. /// </summary>
  332. /// <remarks>
  333. /// This is only used where the length, Crc, or compressed size isnt known when the
  334. /// entry is created and the output stream doesnt support seeking.
  335. /// The local entry cannot be 'patched' with the correct values in this case
  336. /// so the values are recorded after the data prefixed by this header, as well as in the central directory.
  337. /// </remarks>
  338. [Obsolete("Use DataDescriptorSignature instead")]
  339. public const int EXTSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
  340. /// <summary>
  341. /// Signature for central header
  342. /// </summary>
  343. [Obsolete("Use CentralHeaderSignature instead")]
  344. public const int CENSIG = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
  345. /// <summary>
  346. /// Signature for central header
  347. /// </summary>
  348. public const int CentralHeaderSignature = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
  349. /// <summary>
  350. /// Signature for Zip64 central file header
  351. /// </summary>
  352. public const int Zip64CentralFileHeaderSignature = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
  353. /// <summary>
  354. /// Signature for Zip64 central file header
  355. /// </summary>
  356. [Obsolete("Use Zip64CentralFileHeaderSignature instead")]
  357. public const int CENSIG64 = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
  358. /// <summary>
  359. /// Signature for Zip64 central directory locator
  360. /// </summary>
  361. public const int Zip64CentralDirLocatorSignature = 'P' | ('K' << 8) | (6 << 16) | (7 << 24);
  362. /// <summary>
  363. /// Signature for archive extra data signature (were headers are encrypted).
  364. /// </summary>
  365. public const int ArchiveExtraDataSignature = 'P' | ('K' << 8) | (6 << 16) | (7 << 24);
  366. /// <summary>
  367. /// Central header digitial signature
  368. /// </summary>
  369. public const int CentralHeaderDigitalSignature = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
  370. /// <summary>
  371. /// Central header digitial signature
  372. /// </summary>
  373. [Obsolete("Use CentralHeaderDigitalSignaure instead")]
  374. public const int CENDIGITALSIG = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
  375. /// <summary>
  376. /// End of central directory record signature
  377. /// </summary>
  378. public const int EndOfCentralDirectorySignature = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
  379. /// <summary>
  380. /// End of central directory record signature
  381. /// </summary>
  382. [Obsolete("Use EndOfCentralDirectorySignature instead")]
  383. public const int ENDSIG = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
  384. #endregion Header Signatures
  385. /// <summary>
  386. /// Default encoding used for string conversion. 0 gives the default system OEM code page.
  387. /// Using the default code page isnt the full solution neccessarily
  388. /// there are many variable factors, codepage 850 is often a good choice for
  389. /// European users, however be careful about compatability.
  390. /// </summary>
  391. [Obsolete("Use ZipStrings instead")]
  392. public static int DefaultCodePage
  393. {
  394. get => ZipStrings.CodePage;
  395. set => ZipStrings.CodePage = value;
  396. }
  397. /// <summary> Depracated wrapper for <see cref="ZipStrings.ConvertToString(byte[], int)"/></summary>
  398. [Obsolete("Use ZipStrings.ConvertToString instead")]
  399. public static string ConvertToString(byte[] data, int count)
  400. => ZipStrings.ConvertToString(data, count);
  401. /// <summary> Depracated wrapper for <see cref="ZipStrings.ConvertToString(byte[])"/></summary>
  402. [Obsolete("Use ZipStrings.ConvertToString instead")]
  403. public static string ConvertToString(byte[] data)
  404. => ZipStrings.ConvertToString(data);
  405. /// <summary> Depracated wrapper for <see cref="ZipStrings.ConvertToStringExt(int, byte[], int)"/></summary>
  406. [Obsolete("Use ZipStrings.ConvertToStringExt instead")]
  407. public static string ConvertToStringExt(int flags, byte[] data, int count)
  408. => ZipStrings.ConvertToStringExt(flags, data, count);
  409. /// <summary> Depracated wrapper for <see cref="ZipStrings.ConvertToStringExt(int, byte[])"/></summary>
  410. [Obsolete("Use ZipStrings.ConvertToStringExt instead")]
  411. public static string ConvertToStringExt(int flags, byte[] data)
  412. => ZipStrings.ConvertToStringExt(flags, data);
  413. /// <summary> Depracated wrapper for <see cref="ZipStrings.ConvertToArray(string)"/></summary>
  414. [Obsolete("Use ZipStrings.ConvertToArray instead")]
  415. public static byte[] ConvertToArray(string str)
  416. => ZipStrings.ConvertToArray(str);
  417. /// <summary> Depracated wrapper for <see cref="ZipStrings.ConvertToArray(int, string)"/></summary>
  418. [Obsolete("Use ZipStrings.ConvertToArray instead")]
  419. public static byte[] ConvertToArray(int flags, string str)
  420. => ZipStrings.ConvertToArray(flags, str);
  421. }
  422. }