backupandrestore/backupengine/inc/sbecompressionandencryption.h
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 /**
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Declaration of CSBECompressionAndEncryption class.
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file
       
    24 */
       
    25 #ifndef __SBECOMPRESSIONANDENCRYPTION_H__
       
    26 #define __SBECOMPRESSIONANDENCRYPTION_H__
       
    27 
       
    28 #include <e32base.h>
       
    29 
       
    30 #include "sbtypes.h"
       
    31 
       
    32 // Forwards
       
    33 class CARC4;
       
    34 
       
    35 namespace conn
       
    36 	{
       
    37 	// Forwards
       
    38 	class CSecureBUREncryptKeySource;
       
    39 	
       
    40 	/** Constants used in the class below
       
    41 	@internalTechnology
       
    42 	*/	
       
    43 	const TInt KKeySize = 32;
       
    44 	/** Constants used in the class below
       
    45 	@internalTechnology
       
    46 	*/	
       
    47 	const TInt KEncryptionBufferSize = 256;
       
    48 	
       
    49 	// Template classes for handling byte alignment issues
       
    50 	template<class T> void ReadL(T& aT, TPtr8& aBuffer);
       
    51 	template<class T> void WriteL(T& aT, TPtr8& aBuffer);
       
    52 	
       
    53 	/** Type: Compression Header
       
    54 	@internalTechnology
       
    55 	*/
       
    56 	class TCompressionHeader
       
    57 		{
       
    58 	public:
       
    59 		TInt	iCompressedSize;
       
    60 		TInt	iUncompressedSize;
       
    61 		};
       
    62 		
       
    63 	/** Type: Encryption Header
       
    64 	@internalTechnology
       
    65 	*/
       
    66 	class TEncryptionHeader 
       
    67 		{
       
    68 	public:
       
    69 		TBool	iEncrypted;
       
    70 		TInt	iBufferSize;
       
    71 		TInt	iTotalSize;
       
    72 		};
       
    73 	
       
    74 	/** Handles compression and encryption
       
    75 	@internalTechnology
       
    76 	*/
       
    77 	class CSBECompressAndEncrypt : public CBase
       
    78 		{
       
    79 		public:
       
    80 			// Construtors
       
    81 			static CSBECompressAndEncrypt* NewLC(CSBGenericTransferType*& apTransferType, TPtr8& aInputBlock);
       
    82 			~CSBECompressAndEncrypt();
       
    83 			
       
    84 			// Methods
       
    85 			void PackL(TPtr8& aOutputData);
       
    86 			void FreeReservedSpace(TPtr8& aOutputData);
       
    87 		private:
       
    88 			// Constructors
       
    89 			CSBECompressAndEncrypt();
       
    90 			void ConstructL(CSBGenericTransferType*& apTransferType, TPtr8& aInputBlock);
       
    91 		private:
       
    92 			// Compression statics
       
    93 			const static TInt iCompressionGrowthSize;
       
    94 			
       
    95 			// Members
       
    96 			TBool							iDoEncrypt; /*<! To encryption */
       
    97 			TBool							iGotBuffer; /*<! Do we have an encryption buffer */
       
    98 			TBuf8<KKeySize>					iKey; /*<! Encryption key */
       
    99 			TBuf<KEncryptionBufferSize>		iBuffer; /*<! Encryption buffer */
       
   100 			TPtr8							iActualStart; /*<! Real start of data block */
       
   101 			TPtr8*							iOffsetStart; /*<! Star of data */
       
   102 		
       
   103 			// Encryption
       
   104 			CARC4*							iCipher; /*<! Used for encryption */
       
   105 			TBool							iIsFreed;	/*Is freed reserved memory*/
       
   106 		};
       
   107 		
       
   108 	/** Handles decompression and decryption
       
   109 	@internalTechnology
       
   110 	*/
       
   111 	class CSBEDecompressAndEncrypt : public CBase
       
   112 		{
       
   113 		public:
       
   114 			// Constructors
       
   115 			static CSBEDecompressAndEncrypt* NewL();
       
   116 			static CSBEDecompressAndEncrypt* NewLC();
       
   117 			~CSBEDecompressAndEncrypt();
       
   118 			
       
   119 			// Methods
       
   120 			void SetGenericTransferTypeL(CSBGenericTransferType*& apTransferType);
       
   121 			void SetBuffer(TDesC8& aOutputData);
       
   122 			TBool NextLC(HBufC8*& apOutput, TBool& aFinished);
       
   123 		private:
       
   124 			// Constructors
       
   125 			CSBEDecompressAndEncrypt();
       
   126 
       
   127 			// Methods
       
   128 			void Reset();
       
   129 			TBool CreateCipherL();
       
   130 			void MoveAlongL(TPtr8& aPtr, TInt aAmount);
       
   131 		private:
       
   132 			// Enum
       
   133 			enum TTransferType {ENotSet, ESid, EJava, EPackage};
       
   134 			
       
   135 			
       
   136 			// Members
       
   137 			TBool 							iDoDecrypt; /*<! Do decryption */
       
   138 			TTransferType					iType;
       
   139 			TPtr8							iCurrentPtr; /*<! Pointer to the current work position */
       
   140 			TEncryptionHeader				iEncryptionHeader; /*<! An encryption headear */
       
   141 			TDriveNumber					iDriveNumber; /*<! Drive number */
       
   142 			TSecureId						iSecureId; /*<! Secure Id */
       
   143 			TInt							iCount; /*<! Count of data unpacked */
       
   144 			TCompressionHeader				iCompressionHeader; /*<! A compression header */
       
   145 			TUid							iPackageId; /*<! A package header */
       
   146 			HBufC*							iJavaHash; /*<! For storing the java hash */
       
   147 			
       
   148 			// Buffering
       
   149 			TBool							iGotCompressionHeader; /*<! Have we got the compression header */
       
   150 			TBool							iDoneDecompression;
       
   151 			TBool							iGotCipher;
       
   152 			TInt							iCompressionSizeRead; /*<! Used for buffering */
       
   153 			TInt							iEncryptionSizeRead; 
       
   154 			HBufC8*							iBuffer;
       
   155 		
       
   156 			// Encryption
       
   157 			CARC4*							iCipher; /*<! Used for encryption */
       
   158 		};
       
   159 	}
       
   160 #endif // __SBECOMPRESSIONANDENCRYPTION_H__