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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details refer to the License.txt file.
//
// Web Site: http://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipCryptograph.h
* Includes the CZipCryptograph class.
*
*/
#if !defined(ZIPARCHIVE_ZIPCRYPTOGRAPH_DOT_H)
#define ZIPARCHIVE_ZIPCRYPTOGRAPH_DOT_H
#if _MSC_VER > 1000
#pragma once
#pragma warning( push )
#pragma warning (disable : 4100) // unreferenced formal parameter
#endif // _MSC_VER > 1000
#include "ZipAutoBuffer.h"
#include "ZipStorage.h"
class CZipFileHeader;
/**
The base class for cryptographs used in encryption and decryption of file data.
\see
<a href="kb">0610201627</a>
*/
class ZIP_API CZipCryptograph
{
public:
/**
The encryption method.
\see
<a href="kb">0610201627</a>
*/
enum EncryptionMethod
{
encStandard, ///< The traditional zip encryption.
encWinZipAes128, ///< WinZip AES 128-bit encryption.
encWinZipAes192, ///< WinZip AES 192-bit encryption.
encWinZipAes256, ///< WinZip AES 256-bit encryption.
encNone = 0xFF ///< Indicates no encryption.
};
/**
A factory method that creates an appropriate cryptograph for the given method.
\param iEncryptionMethod
The encryption method to create a cryptograph for. Can be one of #EncryptionMethod values.
\return
The new cryptograph. The caller is responsible for destroying the object.
If the method is not supported, creates CZipCrc32Cryptograph.
*/
static CZipCryptograph* CreateCryptograph(int iEncryptionMethod);
/**
Determines if the given method is one of the WinZip AES encryption method.
\param iEncryptionMethod
The encryption method to test. Can be one of #EncryptionMethod values.
\return
\c true, if the method is one the WinZip AES encryption methods; \c false otherwise.
*/
static bool IsWinZipAesEncryption(int iEncryptionMethod)
{
return iEncryptionMethod == encWinZipAes128 || iEncryptionMethod == encWinZipAes192 || iEncryptionMethod == encWinZipAes256;
}
/**
Returns the total size of the extra data that is added to the compression stream during encryption with the given method.
\param iEncryptionMethod
The encryption method. Can be one of #EncryptionMethod values.
\return
The total size of extra data for the given encryption method.
*/
static DWORD GetEncryptedInfoSize(int iEncryptionMethod);
/**
Returns the size of the extra data that is added before the compression stream during encryption with the given method.
\param iEncryptionMethod
The encryption method. Can be one of #EncryptionMethod values.
\return
The size of extra data at the beginning of the compression stream for the given encryption method.
*/
static DWORD GetEncryptedInfoSizeBeforeData(int iEncryptionMethod);
/**
Returns the size of the extra data that is added after the compression stream during encryption with the given method.
\param iEncryptionMethod
The encryption method. Can be one of #EncryptionMethod values.
\return
The size of extra data at the end of the compression stream for the given encryption method.
*/
static DWORD GetEncryptedInfoSizeAfterData(int iEncryptionMethod);
/**
Determines if the given encryption method is supported by the current compilation of the ZipArchive Library.
\param iEncryptionMethod
The encryption method to test. Can be one of #EncryptionMethod values.
\return
\c true, if the method is supported; \c false otherwise.
*/
static bool IsEncryptionSupported(int iEncryptionMethod)
{
return iEncryptionMethod == encStandard;
}
/**
The method called when an existing file is opened for extraction.
\param password
The supplied password with the CZipArchive::SetPassword method.
\param currentFile
The file being decoded and extracted.
\param storage
The current CZipStorage.
\return
\c true, if the password is initially considered correct; \c false otherwise.
*/
virtual bool InitDecode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage) = 0;
/**
The method called when a new file is opened for compression.
\param password
The supplied password with the CZipArchive::SetPassword method.
\param currentFile
The file being compressed and encoded.
\param storage
The current CZipStorage.
*/
virtual void InitEncode(CZipAutoBuffer& password, CZipFileHeader& currentFile, CZipStorage& storage) = 0;
/**
Decodes the given data.
\param pBuffer
The buffer that holds the data to decode and that receives the results.
\param uSize
The size of \a pBuffer.
*/
virtual void Decode(char* pBuffer, DWORD uSize) = 0;
/**
Encodes the given data.
\param pBuffer
The buffer that holds the data to encode and that receives the results.
\param uSize
The size of \a pBuffer.
*/
virtual void Encode(char* pBuffer, DWORD uSize) = 0;
/**
The method called at the end of the decoding process.
\param currentFile
The file being decoded and extracted.
\param storage
The current CZipStorage.
*/
virtual void FinishDecode(CZipFileHeader& currentFile, CZipStorage& storage){};
/**
The method called at the end of the decoding process.
\param currentFile
The file being compressed and encoded.
\param storage
The current CZipStorage.
*/
virtual void FinishEncode(CZipFileHeader& currentFile, CZipStorage& storage){};
/**
Returns the value indicating whether the current compressor can handle the given encryption method.
\param iEncryptionMethod
The encryption method to test. Can be one of #EncryptionMethod values.
\return
\c true, if the current compressor can handle the given encryption method; \c false otherwise.
*/
virtual bool CanHandle(int iEncryptionMethod)
{
return false;
}
virtual ~CZipCryptograph(){}
};
#if _MSC_VER > 1000
#pragma warning( pop )
#endif // _MSC_VER > 1000
#endif
|