53 @param aBuffer the buffer |
57 @param aBuffer the buffer |
54 @param aStartAt offset of the data |
58 @param aStartAt offset of the data |
55 @param aToCopy the amount of data to copy |
59 @param aToCopy the amount of data to copy |
56 */ |
60 */ |
57 { |
61 { |
|
62 OstTraceFunctionEntry0( _CONN_READL_ENTRY ); |
58 TUint8* inData = const_cast<TUint8*>(aBuffer.Ptr()); |
63 TUint8* inData = const_cast<TUint8*>(aBuffer.Ptr()); |
59 TUint8* outData = (reinterpret_cast<TUint8*>(&aT)) + aStartAt; |
64 TUint8* outData = (reinterpret_cast<TUint8*>(&aT)) + aStartAt; |
60 for (TInt x = 0; x < aToCopy; x++) |
65 for (TInt x = 0; x < aToCopy; x++) |
61 { |
66 { |
62 *(outData++) = *(inData++); |
67 *(outData++) = *(inData++); |
63 } // for |
68 } // for |
|
69 OstTraceFunctionExit0( _CONN_READL_EXIT ); |
64 } |
70 } |
65 |
71 |
66 |
72 |
67 template<class T> void WriteL(T& aT, TPtr8& aBuffer, TInt aStartAt = 0, TInt aToCopy = sizeof(T)) |
73 template<class T> void WriteL(T& aT, TPtr8& aBuffer, TInt aStartAt = 0, TInt aToCopy = sizeof(T)) |
68 /** Writes data from aBuffer into any given type |
74 /** Writes data from aBuffer into any given type |
71 @param aBuffer the buffer |
77 @param aBuffer the buffer |
72 @param aStartAt offset of the data |
78 @param aStartAt offset of the data |
73 @param aToCopy the amount of data to copy |
79 @param aToCopy the amount of data to copy |
74 */ |
80 */ |
75 { |
81 { |
|
82 OstTraceFunctionEntry0( _CONN_WRITEL_ENTRY ); |
76 TUint8* inData = reinterpret_cast<TUint8*>(&aT); |
83 TUint8* inData = reinterpret_cast<TUint8*>(&aT); |
77 TUint8* outData = (const_cast<TUint8*>(aBuffer.Ptr())) + aStartAt; |
84 TUint8* outData = (const_cast<TUint8*>(aBuffer.Ptr())) + aStartAt; |
78 for (TInt x = 0; x < aToCopy; x++) |
85 for (TInt x = 0; x < aToCopy; x++) |
79 { |
86 { |
80 *(outData++) = *(inData++); |
87 *(outData++) = *(inData++); |
81 } // for |
88 } // for |
82 |
89 |
83 aBuffer.SetLength(aBuffer.Length() + sizeof(T)); |
90 aBuffer.SetLength(aBuffer.Length() + sizeof(T)); |
|
91 OstTraceFunctionExit0( _CONN_WRITEL_EXIT ); |
84 } |
92 } |
85 |
93 |
86 CSBECompressAndEncrypt* CSBECompressAndEncrypt::NewLC(CSBGenericTransferType*& apTransferType, TPtr8& aInputData) |
94 CSBECompressAndEncrypt* CSBECompressAndEncrypt::NewLC(CSBGenericTransferType*& apTransferType, TPtr8& aInputData) |
87 /** Standard Symbian constructor |
95 /** Standard Symbian constructor |
88 |
96 |
89 @param apTransferType transfer type of data. |
97 @param apTransferType transfer type of data. |
90 @param aInputData data block to be used. Start point will be changed to allow for compression. |
98 @param aInputData data block to be used. Start point will be changed to allow for compression. |
91 */ |
99 */ |
92 { |
100 { |
|
101 OstTraceFunctionEntry0( CSBECOMPRESSANDENCRYPT_NEWLC_ENTRY ); |
93 CSBECompressAndEncrypt* self = new(ELeave) CSBECompressAndEncrypt(); |
102 CSBECompressAndEncrypt* self = new(ELeave) CSBECompressAndEncrypt(); |
94 CleanupStack::PushL(self); |
103 CleanupStack::PushL(self); |
95 self->ConstructL(apTransferType, aInputData); |
104 self->ConstructL(apTransferType, aInputData); |
96 |
105 |
|
106 OstTraceFunctionExit0( CSBECOMPRESSANDENCRYPT_NEWLC_EXIT ); |
97 return self; |
107 return self; |
98 } |
108 } |
99 |
109 |
100 CSBECompressAndEncrypt::CSBECompressAndEncrypt() : |
110 CSBECompressAndEncrypt::CSBECompressAndEncrypt() : |
101 iActualStart(NULL, 0), iCipher(NULL), iIsFreed(EFalse) |
111 iActualStart(NULL, 0), iCipher(NULL), iIsFreed(EFalse) |
102 /** Standard C++ Constructor |
112 /** Standard C++ Constructor |
103 */ |
113 */ |
104 { |
114 { |
|
115 OstTraceFunctionEntry0( CSBECOMPRESSANDENCRYPT_CSBECOMPRESSANDENCRYPT_CONS_ENTRY ); |
|
116 OstTraceFunctionExit0( CSBECOMPRESSANDENCRYPT_CSBECOMPRESSANDENCRYPT_CONS_EXIT ); |
105 } |
117 } |
106 |
118 |
107 CSBECompressAndEncrypt::~CSBECompressAndEncrypt() |
119 CSBECompressAndEncrypt::~CSBECompressAndEncrypt() |
108 /** Standard C++ Destructor |
120 /** Standard C++ Destructor |
109 */ |
121 */ |
110 { |
122 { |
|
123 OstTraceFunctionEntry0( CSBECOMPRESSANDENCRYPT_CSBECOMPRESSANDENCRYPT_DES_ENTRY ); |
111 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
124 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
112 |
125 |
113 if( ! iIsFreed ) |
126 if( ! iIsFreed ) |
114 iOffsetStart->Set(iActualStart); // free reserved space when leave occurs. |
127 iOffsetStart->Set(iActualStart); // free reserved space when leave occurs. |
115 #endif |
128 #endif |
116 delete iCipher; |
129 delete iCipher; |
|
130 OstTraceFunctionExit0( CSBECOMPRESSANDENCRYPT_CSBECOMPRESSANDENCRYPT_DES_EXIT ); |
117 } |
131 } |
118 |
132 |
119 void CSBECompressAndEncrypt::ConstructL(CSBGenericTransferType*& apTransferType, TPtr8& aOutputData) |
133 void CSBECompressAndEncrypt::ConstructL(CSBGenericTransferType*& apTransferType, TPtr8& aOutputData) |
120 /** |
134 /** |
121 Standard Symbian second phase constructor |
135 Standard Symbian second phase constructor |
122 |
136 |
123 @param apTransferType transfer type of data. |
137 @param apTransferType transfer type of data. |
124 @param aInputData data block to be used. Start point will be changed to allow for compression. |
138 @param aInputData data block to be used. Start point will be changed to allow for compression. |
125 */ |
139 */ |
126 { |
140 { |
127 __LOG2("CSBECompressAndEncrypt::ConstructL() - START - aOutputData: 0x%08x (%d)", aOutputData.Ptr(), aOutputData.Length()); |
141 OstTraceFunctionEntry0( CSBECOMPRESSANDENCRYPT_CONSTRUCTL_ENTRY ); |
|
142 OstTraceExt2(TRACE_NORMAL, CSBECOMPRESSANDENCRYPT_CONSTRUCTL, "aOutputData: 0x%08x (%d)", reinterpret_cast<TInt32>(aOutputData.Ptr()), static_cast<TInt32>(aOutputData.Length())); |
128 |
143 |
129 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
144 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
130 // Do we need a key source and cipher? |
145 // Do we need a key source and cipher? |
131 TSBDerivedType derivedType = apTransferType->DerivedTypeL(); |
146 TSBDerivedType derivedType = apTransferType->DerivedTypeL(); |
132 TInt extraToReserve = 0; |
147 TInt extraToReserve = 0; |
168 CleanupStack::PopAndDestroy(keySource); |
183 CleanupStack::PopAndDestroy(keySource); |
169 |
184 |
170 // Create the cipher, if needed. |
185 // Create the cipher, if needed. |
171 if (iDoEncrypt) |
186 if (iDoEncrypt) |
172 { |
187 { |
173 __LOG1("Key length: %d", iKey.Length() * 4); |
188 OstTrace1(TRACE_NORMAL, DUP1_CSBECOMPRESSANDENCRYPT_CONSTRUCTL, "Key length: %d", iKey.Length() * 4); |
174 iCipher = CARC4::NewL(iKey); |
189 iCipher = CARC4::NewL(iKey); |
175 } // if |
190 } // if |
176 |
191 |
177 extraToReserve = sizeof(TEncryptionHeader) + iBuffer.Size(); |
192 extraToReserve = sizeof(TEncryptionHeader) + iBuffer.Size(); |
178 } // if |
193 } // if |
179 |
194 |
180 // Reserve the space required |
195 // Reserve the space required |
181 TInt numberBlocks = (aOutputData.MaxSize() / KCompressionBlockSize) + (((aOutputData.MaxSize() % KCompressionBlockSize) == 0) ? 0 : 1); |
196 TInt numberBlocks = (aOutputData.MaxSize() / KCompressionBlockSize) + (((aOutputData.MaxSize() % KCompressionBlockSize) == 0) ? 0 : 1); |
182 TInt reservedSpace = (numberBlocks * iCompressionGrowthSize) + extraToReserve; |
197 TInt reservedSpace = (numberBlocks * iCompressionGrowthSize) + extraToReserve; |
183 __LOG2("CSBECompressAndEncrypt::ConstructL() - numberBlocks: %d, reservedSpace: %d", numberBlocks, reservedSpace); |
198 OstTraceExt2(TRACE_NORMAL, DUP2_CSBECOMPRESSANDENCRYPT_CONSTRUCTL, "numberBlocks: %d, reservedSpace: %d", numberBlocks, reservedSpace); |
184 |
199 |
185 // Keep a copy of the acutual data block |
200 // Keep a copy of the acutual data block |
186 iActualStart.Set(const_cast<TUint8*>(aOutputData.Ptr()), 0, aOutputData.MaxSize()); |
201 iActualStart.Set(const_cast<TUint8*>(aOutputData.Ptr()), 0, aOutputData.MaxSize()); |
187 |
202 |
188 // Reserve the space in the input data |
203 // Reserve the space in the input data |
189 if (reservedSpace > aOutputData.MaxSize()) |
204 if (reservedSpace > aOutputData.MaxSize()) |
190 { |
205 { |
|
206 OstTrace0(TRACE_ERROR, DUP4_CSBECOMPRESSANDENCRYPT_CONSTRUCTL, "Leave: KErrOverflow"); |
191 User::Leave(KErrOverflow); |
207 User::Leave(KErrOverflow); |
192 } |
208 } |
193 aOutputData.Set((const_cast<TUint8*>(aOutputData.Ptr()) + reservedSpace), 0, aOutputData.MaxSize() - reservedSpace); |
209 aOutputData.Set((const_cast<TUint8*>(aOutputData.Ptr()) + reservedSpace), 0, aOutputData.MaxSize() - reservedSpace); |
194 iOffsetStart = &aOutputData; |
210 iOffsetStart = &aOutputData; |
195 #endif |
211 #endif |
196 __LOG2("CSBECompressAndEncrypt::ConstructL() - END - aOutputData: 0x%08x (%d)", aOutputData.Ptr(), aOutputData.Length()); |
212 OstTraceExt2(TRACE_NORMAL, DUP3_CSBECOMPRESSANDENCRYPT_CONSTRUCTL, "aOutputData: 0x%08x (%d)", reinterpret_cast<TInt32>(aOutputData.Ptr()), static_cast<TInt32>(aOutputData.Length())); |
|
213 OstTraceFunctionExit0( CSBECOMPRESSANDENCRYPT_CONSTRUCTL_EXIT ); |
197 } |
214 } |
198 |
215 |
199 void CSBECompressAndEncrypt::PackL(TPtr8& aOutputData) |
216 void CSBECompressAndEncrypt::PackL(TPtr8& aOutputData) |
200 /** Performs the compression and encryption |
217 /** Performs the compression and encryption |
201 |
218 |
202 @param aOutputData the compressed data |
219 @param aOutputData the compressed data |
203 */ |
220 */ |
204 { |
221 { |
205 __LOG4("CSBECompressAndEncrypt::PackL() - START - aOutputData: 0x%08x (%d), iActualStart: 0x%08x (%d)", aOutputData.Ptr(), aOutputData.Length(), iActualStart.Ptr(), iActualStart.Length()); |
222 OstTraceFunctionEntry0( CSBECOMPRESSANDENCRYPT_PACKL_ENTRY ); |
|
223 OstTraceExt4(TRACE_NORMAL, CSBECOMPRESSANDENCRYPT_PACKL, "aOutputData: 0x%08x (%d), iActualStart: 0x%08x (%d)", reinterpret_cast<TInt32>(aOutputData.Ptr()), static_cast<TInt32>(aOutputData.Length()), reinterpret_cast<TInt32>(iActualStart.Ptr()), static_cast<TInt32>(iActualStart.Length())); |
206 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
224 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
207 // Add the encryption header |
225 // Add the encryption header |
208 TEncryptionHeader encryptionHeader; |
226 TEncryptionHeader encryptionHeader; |
209 encryptionHeader.iEncrypted = iDoEncrypt; |
227 encryptionHeader.iEncrypted = iDoEncrypt; |
210 encryptionHeader.iBufferSize = iBuffer.Size(); |
228 encryptionHeader.iBufferSize = iBuffer.Size(); |
211 encryptionHeader.iTotalSize = sizeof(TEncryptionHeader) + encryptionHeader.iBufferSize; |
229 encryptionHeader.iTotalSize = sizeof(TEncryptionHeader) + encryptionHeader.iBufferSize; |
212 |
230 |
213 __LOG1("CSBECompressAndEncrypt::PackL() - Encryption Header: Encryption supported %d", encryptionHeader.iEncrypted); |
231 OstTrace1(TRACE_NORMAL, DUP1_CSBECOMPRESSANDENCRYPT_PACKL, "Encryption Header: Encryption supported %d", encryptionHeader.iEncrypted); |
214 __LOG1("CSBECompressAndEncrypt::PackL() - Encryption Header: BufferSize %d", encryptionHeader.iBufferSize); |
232 OstTrace1(TRACE_NORMAL, DUP2_CSBECOMPRESSANDENCRYPT_PACKL, "Encryption Header: BufferSize %d", encryptionHeader.iBufferSize); |
215 __LOG1("CSBECompressAndEncrypt::PackL() - Encryption Header: Total Size %d",encryptionHeader.iTotalSize); |
233 OstTrace1(TRACE_NORMAL, DUP3_CSBECOMPRESSANDENCRYPT_PACKL, "Encryption Header: Total Size %d",encryptionHeader.iTotalSize); |
216 |
234 |
217 // Move along |
235 // Move along |
218 TPtr8 encryptionOffset(const_cast<TUint8*>(iActualStart.Ptr()), 0, sizeof(TEncryptionHeader)); |
236 TPtr8 encryptionOffset(const_cast<TUint8*>(iActualStart.Ptr()), 0, sizeof(TEncryptionHeader)); |
219 iActualStart.SetLength(sizeof(TEncryptionHeader)); |
237 iActualStart.SetLength(sizeof(TEncryptionHeader)); |
220 |
238 |
251 // Add the header information |
269 // Add the header information |
252 TCompressionHeader compressionHeader; |
270 TCompressionHeader compressionHeader; |
253 compressionHeader.iCompressedSize = compressionBuffer->Size(); |
271 compressionHeader.iCompressedSize = compressionBuffer->Size(); |
254 compressionHeader.iUncompressedSize = toCompressSize; |
272 compressionHeader.iUncompressedSize = toCompressSize; |
255 |
273 |
256 __LOG1("CSBECompressAndEncrypt::PackL() - Compression Header: Compressed %d", compressionHeader.iCompressedSize); |
274 OstTrace1(TRACE_NORMAL, DUP4_CSBECOMPRESSANDENCRYPT_PACKL, "Compression Header: Compressed %d", compressionHeader.iCompressedSize); |
257 __LOG1("CSBECompressAndEncrypt::PackL() - Compression Header: UnCompressed %d", compressionHeader.iUncompressedSize); |
275 OstTrace1(TRACE_NORMAL, DUP5_CSBECOMPRESSANDENCRYPT_PACKL, "Compression Header: UnCompressed %d", compressionHeader.iUncompressedSize); |
258 |
276 |
259 if (iDoEncrypt) |
277 if (iDoEncrypt) |
260 { |
278 { |
261 encryptionBuffer->Des().Append(reinterpret_cast<TUint8*>(&compressionHeader), sizeof(TCompressionHeader)); |
279 encryptionBuffer->Des().Append(reinterpret_cast<TUint8*>(&compressionHeader), sizeof(TCompressionHeader)); |
262 encryptionBuffer->Des().Append(compressionBuffer->Des()); |
280 encryptionBuffer->Des().Append(compressionBuffer->Des()); |
289 CleanupStack::PopAndDestroy(compressionBuffer); |
307 CleanupStack::PopAndDestroy(compressionBuffer); |
290 |
308 |
291 aOutputData.Set(iActualStart); |
309 aOutputData.Set(iActualStart); |
292 iIsFreed = ETrue; |
310 iIsFreed = ETrue; |
293 #endif |
311 #endif |
294 __LOG("CSBECompressAndEncrypt::PackL() - END"); |
312 |
|
313 OstTraceFunctionExit0( CSBECOMPRESSANDENCRYPT_PACKL_EXIT ); |
295 } |
314 } |
296 void CSBECompressAndEncrypt::FreeReservedSpace(TPtr8& aOutputData) |
315 void CSBECompressAndEncrypt::FreeReservedSpace(TPtr8& aOutputData) |
297 /* |
316 /* |
298 Free space researved in ConstructL if no data to be compressed. |
317 Free space researved in ConstructL if no data to be compressed. |
299 @param aOutputData the compressed data |
318 @param aOutputData the compressed data |
300 */ |
319 */ |
301 { |
320 { |
302 __LOG("CSBECompressAndEncrypt::FreeReservedSpace() - START"); |
321 OstTraceFunctionEntry0( CSBECOMPRESSANDENCRYPT_FREERESERVEDSPACE_ENTRY ); |
303 |
322 |
304 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
323 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
305 |
324 |
306 __LOG1("CSBECompressAndEncrypt::FreeReservedSpace() aOutputData.Length(): %d", aOutputData.Length()); |
325 OstTrace1(TRACE_NORMAL, CSBECOMPRESSANDENCRYPT_FREERESERVEDSPACE, "aOutputData.Length(): %d", aOutputData.Length()); |
307 |
326 |
308 aOutputData.Set(iActualStart); |
327 aOutputData.Set(iActualStart); |
309 iIsFreed = ETrue; |
328 iIsFreed = ETrue; |
310 #endif |
329 #endif |
311 |
330 |
312 __LOG("CSBECompressAndEncrypt::FreeReservedSpace() - END"); |
331 OstTraceFunctionExit0( CSBECOMPRESSANDENCRYPT_FREERESERVEDSPACE_EXIT ); |
313 } |
332 } |
314 |
333 |
315 CSBEDecompressAndEncrypt* CSBEDecompressAndEncrypt::NewL() |
334 CSBEDecompressAndEncrypt* CSBEDecompressAndEncrypt::NewL() |
316 /** Standard Symbian constructor |
335 /** Standard Symbian constructor |
317 */ |
336 */ |
318 { |
337 { |
|
338 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_NEWL_ENTRY ); |
319 CSBEDecompressAndEncrypt* self = CSBEDecompressAndEncrypt::NewLC(); |
339 CSBEDecompressAndEncrypt* self = CSBEDecompressAndEncrypt::NewLC(); |
320 CleanupStack::Pop(self); |
340 CleanupStack::Pop(self); |
321 |
341 |
|
342 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_NEWL_EXIT ); |
322 return self; |
343 return self; |
323 } |
344 } |
324 |
345 |
325 CSBEDecompressAndEncrypt* CSBEDecompressAndEncrypt::NewLC() |
346 CSBEDecompressAndEncrypt* CSBEDecompressAndEncrypt::NewLC() |
326 /** Standard Symbian constructor |
347 /** Standard Symbian constructor |
327 */ |
348 */ |
328 { |
349 { |
|
350 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_NEWLC_ENTRY ); |
329 CSBEDecompressAndEncrypt* self = new(ELeave) CSBEDecompressAndEncrypt(); |
351 CSBEDecompressAndEncrypt* self = new(ELeave) CSBEDecompressAndEncrypt(); |
330 CleanupStack::PushL(self); |
352 CleanupStack::PushL(self); |
331 |
353 |
|
354 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_NEWLC_EXIT ); |
332 return self; |
355 return self; |
333 } |
356 } |
334 |
357 |
335 CSBEDecompressAndEncrypt::CSBEDecompressAndEncrypt() : |
358 CSBEDecompressAndEncrypt::CSBEDecompressAndEncrypt() : |
336 iType(ENotSet), iCurrentPtr(NULL, 0), iCount(0), iJavaHash(NULL), iCipher(NULL) |
359 iType(ENotSet), iCurrentPtr(NULL, 0), iCount(0), iJavaHash(NULL), iCipher(NULL) |
337 /** Stanard C++ Constructor |
360 /** Stanard C++ Constructor |
338 */ |
361 */ |
339 { |
362 { |
|
363 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_CSBEDECOMPRESSANDENCRYPT_ENTRY ); |
340 Reset(); |
364 Reset(); |
|
365 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_CSBEDECOMPRESSANDENCRYPT_EXIT ); |
341 } |
366 } |
342 |
367 |
343 CSBEDecompressAndEncrypt::~CSBEDecompressAndEncrypt() |
368 CSBEDecompressAndEncrypt::~CSBEDecompressAndEncrypt() |
344 /** Standard C++ Destructor |
369 /** Standard C++ Destructor |
345 */ |
370 */ |
346 { |
371 { |
|
372 OstTraceFunctionEntry0( DUP1_CSBEDECOMPRESSANDENCRYPT_CSBEDECOMPRESSANDENCRYPT_ENTRY ); |
347 delete iCipher; |
373 delete iCipher; |
348 delete iJavaHash; |
374 delete iJavaHash; |
349 delete iBuffer; |
375 delete iBuffer; |
|
376 OstTraceFunctionExit0( DUP1_CSBEDECOMPRESSANDENCRYPT_CSBEDECOMPRESSANDENCRYPT_EXIT ); |
350 } |
377 } |
351 |
378 |
352 void CSBEDecompressAndEncrypt::SetBuffer(TDesC8& aOutputData) |
379 void CSBEDecompressAndEncrypt::SetBuffer(TDesC8& aOutputData) |
353 { |
380 { |
|
381 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_SETBUFFER_ENTRY ); |
354 iCurrentPtr.Set(const_cast<TUint8*>(aOutputData.Ptr()), aOutputData.Size(), aOutputData.Size()); |
382 iCurrentPtr.Set(const_cast<TUint8*>(aOutputData.Ptr()), aOutputData.Size(), aOutputData.Size()); |
|
383 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_SETBUFFER_EXIT ); |
355 } |
384 } |
356 |
385 |
357 void CSBEDecompressAndEncrypt::SetGenericTransferTypeL(CSBGenericTransferType*& apTransferType) |
386 void CSBEDecompressAndEncrypt::SetGenericTransferTypeL(CSBGenericTransferType*& apTransferType) |
358 { |
387 { |
359 __LOG("CSBEDecompressAndEncrypt::SetGenericTransferTypeL() - START"); |
388 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_SETGENERICTRANSFERTYPEL_ENTRY ); |
|
389 |
360 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
390 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
361 TSBDerivedType derivedType = apTransferType->DerivedTypeL(); |
391 TSBDerivedType derivedType = apTransferType->DerivedTypeL(); |
362 if (derivedType == ESIDTransferDerivedType) |
392 if (derivedType == ESIDTransferDerivedType) |
363 { |
393 { |
364 // Need the Sid transfertype |
394 // Need the Sid transfertype |
417 if ((iType != EPackage) || |
447 if ((iType != EPackage) || |
418 (iPackageId != pPackageTransferType->PackageIdL())) |
448 (iPackageId != pPackageTransferType->PackageIdL())) |
419 { |
449 { |
420 Reset(); |
450 Reset(); |
421 iPackageId = pPackageTransferType->PackageIdL(); |
451 iPackageId = pPackageTransferType->PackageIdL(); |
422 __LOG1("CSBEDecompressAndEncrypt::SetGenericTransferTypeL() - Package ID 0x%08x", iPackageId.iUid); |
452 OstTrace1(TRACE_NORMAL, DUP2_CSBEDECOMPRESSANDENCRYPT_SETGENERICTRANSFERTYPEL, "Package ID 0x%08x", iPackageId.iUid); |
423 iType = EPackage; |
453 iType = EPackage; |
424 } |
454 } |
425 |
455 |
426 CleanupStack::PopAndDestroy(pPackageTransferType); |
456 CleanupStack::PopAndDestroy(pPackageTransferType); |
427 } // else if |
457 } // else if |
428 else |
458 else |
429 { |
459 { |
430 __LOG("CSBEDecompressAndEncrypt::SetGenericTransferTypeL() - DerivedType not supported"); |
460 OstTrace0(TRACE_ERROR, DUP3_CSBEDECOMPRESSANDENCRYPT_SETGENERICTRANSFERTYPEL, "DerivedType not supported"); |
431 User::Leave(KErrNotSupported); |
461 User::Leave(KErrNotSupported); |
432 } // else |
462 } // else |
433 #endif |
463 #endif |
434 __LOG("CSBEDecompressAndEncrypt::SetGenericTransferTypeL() - END"); |
464 |
|
465 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_SETGENERICTRANSFERTYPEL_EXIT ); |
435 } |
466 } |
436 |
467 |
437 void CSBEDecompressAndEncrypt::Reset() |
468 void CSBEDecompressAndEncrypt::Reset() |
438 /** Resets the data |
469 /** Resets the data |
439 */ |
470 */ |
440 { |
471 { |
441 __LOG("CSBEDecompressAndEncrypt::Reset()"); |
472 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_RESET_ENTRY ); |
442 iCount = 0; |
473 iCount = 0; |
443 iType = ENotSet; |
474 iType = ENotSet; |
444 iDoDecrypt = EFalse; |
475 iDoDecrypt = EFalse; |
445 iCurrentPtr.Set(NULL, 0, 0); |
476 iCurrentPtr.Set(NULL, 0, 0); |
446 iGotCompressionHeader = EFalse; |
477 iGotCompressionHeader = EFalse; |
448 iEncryptionSizeRead = 0; |
479 iEncryptionSizeRead = 0; |
449 iDoneDecompression = EFalse; |
480 iDoneDecompression = EFalse; |
450 iGotCipher = EFalse; |
481 iGotCipher = EFalse; |
451 delete iBuffer; |
482 delete iBuffer; |
452 iBuffer = NULL; |
483 iBuffer = NULL; |
|
484 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_RESET_EXIT ); |
453 } |
485 } |
454 |
486 |
455 void CSBEDecompressAndEncrypt::MoveAlongL(TPtr8& aPtr, TInt aAmount) |
487 void CSBEDecompressAndEncrypt::MoveAlongL(TPtr8& aPtr, TInt aAmount) |
456 /** Move a pointer along a given amount |
488 /** Move a pointer along a given amount |
457 |
489 |
458 @param aPtr pointer to move |
490 @param aPtr pointer to move |
459 @param aAmount amount to move |
491 @param aAmount amount to move |
460 */ |
492 */ |
461 { |
493 { |
|
494 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_MOVEALONGL_ENTRY ); |
462 TInt newSize = aPtr.Size() - aAmount; |
495 TInt newSize = aPtr.Size() - aAmount; |
463 // Check |
496 // Check |
464 if (newSize < 0) |
497 if (newSize < 0) |
465 { |
498 { |
466 __LOG("CSBEDecompressAndEncrypt::MoveAlong() - Overflow"); |
499 OstTrace0(TRACE_ERROR, CSBEDECOMPRESSANDENCRYPT_MOVEALONGL, "Overflow"); |
467 User::Leave(KErrOverflow); |
500 User::Leave(KErrOverflow); |
468 } |
501 } |
469 |
502 |
470 aPtr.Set(const_cast<TUint8*>(aPtr.Ptr()) + aAmount, newSize, newSize); |
503 aPtr.Set(const_cast<TUint8*>(aPtr.Ptr()) + aAmount, newSize, newSize); |
|
504 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_MOVEALONGL_EXIT ); |
471 } |
505 } |
472 |
506 |
473 TBool CSBEDecompressAndEncrypt::NextLC(HBufC8*& apOutput, TBool& aMoreData) |
507 TBool CSBEDecompressAndEncrypt::NextLC(HBufC8*& apOutput, TBool& aMoreData) |
474 /** Decompress a block of the data |
508 /** Decompress a block of the data |
475 |
509 |
476 @param apOutput on return the next block of uncompressed data. This must be deleted by the caller. |
510 @param apOutput on return the next block of uncompressed data. This must be deleted by the caller. |
477 @param aMoreData is there more data left in the compressed block. |
511 @param aMoreData is there more data left in the compressed block. |
478 */ |
512 */ |
479 { |
513 { |
480 __LOG("CSBEDecompressAndEncrypt::NextLC() - START"); |
514 OstTraceFunctionEntry0( CSBEDECOMPRESSANDENCRYPT_NEXTLC_ENTRY ); |
481 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
515 #ifndef TURN_OFF_COMPRESSION_AND_ENCRYPTION |
482 if (!iGotCipher) |
516 if (!iGotCipher) |
483 { |
517 { |
484 iGotCipher = CreateCipherL(); |
518 iGotCipher = CreateCipherL(); |
485 if (!iGotCipher) |
519 if (!iGotCipher) |
486 { |
520 { |
|
521 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_NEXTLC_EXIT ); |
487 return EFalse; |
522 return EFalse; |
488 } // if |
523 } // if |
489 } |
524 } |
490 |
525 |
491 if (!iGotCompressionHeader) |
526 if (!iGotCompressionHeader) |
492 { |
527 { |
493 __LOG("CSBEDecompressAndEncrypt::NextLC - No Header read yet"); |
528 OstTrace0(TRACE_NORMAL, CSBEDECOMPRESSANDENCRYPT_NEXTLC, "No Header read yet"); |
494 |
529 |
495 // Determine how much data we need to read to complete the header |
530 // Determine how much data we need to read to complete the header |
496 TInt dataAvail = iCurrentPtr.Size(); |
531 TInt dataAvail = iCurrentPtr.Size(); |
497 if (iCompressionSizeRead + dataAvail > sizeof(TCompressionHeader)) |
532 if (iCompressionSizeRead + dataAvail > sizeof(TCompressionHeader)) |
498 { |
533 { |
505 iCompressionSizeRead += dataAvail; |
540 iCompressionSizeRead += dataAvail; |
506 iCount += dataAvail; |
541 iCount += dataAvail; |
507 |
542 |
508 if (iCompressionSizeRead < sizeof(TCompressionHeader)) |
543 if (iCompressionSizeRead < sizeof(TCompressionHeader)) |
509 { |
544 { |
510 __LOG1("CSBEDecompressAndEncrypt::NextLC - Got partial compression header (%d bytes)",iCompressionSizeRead ); |
545 OstTrace1(TRACE_NORMAL, DUP1_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Got partial compression header (%d bytes)",iCompressionSizeRead ); |
|
546 OstTraceFunctionExit0( DUP1_CSBEDECOMPRESSANDENCRYPT_NEXTLC_EXIT ); |
511 return EFalse; |
547 return EFalse; |
512 } |
548 } |
513 |
549 |
514 __LOG2("CSBEDecompressAndEncrypt::NextLC - Got compression header (compressed size=%d, uncompressed=%d)", |
550 OstTraceExt2(TRACE_NORMAL, DUP2_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Got compression header (compressed size=%d, uncompressed=%d)", |
515 iCompressionHeader.iCompressedSize, iCompressionHeader.iUncompressedSize); |
551 iCompressionHeader.iCompressedSize, iCompressionHeader.iUncompressedSize); |
516 |
552 |
517 // Was the header encrypted? |
553 // Was the header encrypted? |
518 if (iEncryptionHeader.iEncrypted) |
554 if (iEncryptionHeader.iEncrypted) |
519 { |
555 { |
520 __LOG("CSBEDecompressAndEncrypt::NextLC - Header Encrypted!"); |
556 OstTrace0(TRACE_NORMAL, DUP3_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Header Encrypted!"); |
521 TCompressionHeader compressionHeader; |
557 TCompressionHeader compressionHeader; |
522 TPtr8 inData(reinterpret_cast<TUint8*>(&iCompressionHeader), sizeof(TCompressionHeader), sizeof(TCompressionHeader)); |
558 TPtr8 inData(reinterpret_cast<TUint8*>(&iCompressionHeader), sizeof(TCompressionHeader), sizeof(TCompressionHeader)); |
523 TPtr8 outData(reinterpret_cast<TUint8*>(&compressionHeader), 0, sizeof(TCompressionHeader)); |
559 TPtr8 outData(reinterpret_cast<TUint8*>(&compressionHeader), 0, sizeof(TCompressionHeader)); |
524 |
560 |
525 iCipher->Process(inData, outData); |
561 iCipher->Process(inData, outData); |
526 iCompressionHeader = compressionHeader; |
562 iCompressionHeader = compressionHeader; |
527 __LOG2("CSBEDecompressAndEncrypt::NextLC - unencrypted header, compressed size %d, uncompressed %d", iCompressionHeader.iCompressedSize, iCompressionHeader.iUncompressedSize); |
563 OstTraceExt2(TRACE_NORMAL, DUP4_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "unencrypted header, compressed size %d, uncompressed %d", iCompressionHeader.iCompressedSize, iCompressionHeader.iUncompressedSize); |
528 } |
564 } |
529 |
565 |
530 iCompressionSizeRead = 0; |
566 iCompressionSizeRead = 0; |
531 iGotCompressionHeader = ETrue; |
567 iGotCompressionHeader = ETrue; |
532 } // if |
568 } // if |
535 if ((iCompressionHeader.iCompressedSize < 0) || |
571 if ((iCompressionHeader.iCompressedSize < 0) || |
536 (iCompressionHeader.iUncompressedSize < 0) || |
572 (iCompressionHeader.iUncompressedSize < 0) || |
537 (iCompressionHeader.iCompressedSize >= KMaxHeapSize) || |
573 (iCompressionHeader.iCompressedSize >= KMaxHeapSize) || |
538 (iCompressionHeader.iUncompressedSize >= KMaxHeapSize)) |
574 (iCompressionHeader.iUncompressedSize >= KMaxHeapSize)) |
539 { |
575 { |
540 __LOG("CSBEDecompressAndEncrypt::NextLC() - Compression header is corrupt"); |
576 OstTrace0(TRACE_ERROR, DUP5_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Compression header is corrupt"); |
541 User::Leave(KErrCorrupt); |
577 User::Leave(KErrCorrupt); |
542 } |
578 } |
543 |
579 |
544 if (!iDoneDecompression) |
580 if (!iDoneDecompression) |
545 { |
581 { |
546 // Do we have enough data to decompress? |
582 // Do we have enough data to decompress? |
547 TInt dataSize = iCurrentPtr.Size(); |
583 TInt dataSize = iCurrentPtr.Size(); |
548 __LOG1("CSBEDecompressAndEncrypt::NextLC() - Doing Decompression - data size %d", dataSize); |
584 OstTrace1(TRACE_NORMAL, DUP6_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Doing Decompression - data size %d", dataSize); |
549 if (iBuffer != NULL) |
585 if (iBuffer != NULL) |
550 { |
586 { |
551 dataSize += iBuffer->Size(); |
587 dataSize += iBuffer->Size(); |
552 __LOG1("CSBEDecompressAndEncrypt::NextLC() - iBuffer not NULL new data size %d", dataSize) |
588 OstTrace1(TRACE_NORMAL, DUP7_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "iBuffer not NULL new data size %d", dataSize); |
553 } |
589 } |
554 if (dataSize < iCompressionHeader.iCompressedSize) |
590 if (dataSize < iCompressionHeader.iCompressedSize) |
555 { |
591 { |
556 __LOG("CSBEDecompressAndEncrypt::NextLC() - data size < compressed size"); |
592 OstTrace0(TRACE_NORMAL, DUP8_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "data size < compressed size"); |
557 // Need to buffer the buffer |
593 // Need to buffer the buffer |
558 if (iBuffer == NULL) |
594 if (iBuffer == NULL) |
559 { |
595 { |
560 __LOG1("CSBEDecompressAndEncrypt::NextLC() - Creating internal buffer of size %d",iCompressionHeader.iCompressedSize); |
596 OstTrace1(TRACE_NORMAL, DUP9_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Creating internal buffer of size %d",iCompressionHeader.iCompressedSize); |
561 iBuffer = HBufC8::NewL(iCompressionHeader.iCompressedSize); |
597 iBuffer = HBufC8::NewL(iCompressionHeader.iCompressedSize); |
562 } |
598 } |
563 |
599 |
564 iBuffer->Des().Append(const_cast<TUint8*>(iCurrentPtr.Ptr()), iCurrentPtr.Size()); |
600 iBuffer->Des().Append(const_cast<TUint8*>(iCurrentPtr.Ptr()), iCurrentPtr.Size()); |
565 __LOG("CSBEDecompressAndEncrypt::NextLC() - Appending data to internal buffer"); |
601 OstTrace0(TRACE_NORMAL, DUP10_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Appending data to internal buffer"); |
|
602 OstTraceFunctionExit0( DUP2_CSBEDECOMPRESSANDENCRYPT_NEXTLC_EXIT ); |
566 return EFalse; |
603 return EFalse; |
567 } // if |
604 } // if |
568 |
605 |
569 // Do we have a buffer? |
606 // Do we have a buffer? |
570 TPtr8 inData(NULL, 0); |
607 TPtr8 inData(NULL, 0); |
571 TInt toAppend = 0; |
608 TInt toAppend = 0; |
572 if (iBuffer != NULL) |
609 if (iBuffer != NULL) |
573 { |
610 { |
574 __LOG("CSBEDecompressAndEncrypt::NextLC() - Preparing inData from internal buffer"); |
611 OstTrace0(TRACE_NORMAL, DUP11_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Preparing inData from internal buffer"); |
575 toAppend = iCompressionHeader.iCompressedSize - iBuffer->Des().Size(); |
612 toAppend = iCompressionHeader.iCompressedSize - iBuffer->Des().Size(); |
576 iBuffer->Des().Append(const_cast<TUint8*>(iCurrentPtr.Ptr()), toAppend); |
613 iBuffer->Des().Append(const_cast<TUint8*>(iCurrentPtr.Ptr()), toAppend); |
577 |
614 |
578 inData.Set(const_cast<TUint8*>(iBuffer->Des().Ptr()), iBuffer->Des().Size(), iBuffer->Des().Size()); |
615 inData.Set(const_cast<TUint8*>(iBuffer->Des().Ptr()), iBuffer->Des().Size(), iBuffer->Des().Size()); |
579 } // if |
616 } // if |
580 else |
617 else |
581 { |
618 { |
582 __LOG("CSBEDecompressAndEncrypt::NextLC() - Preparing inData"); |
619 OstTrace0(TRACE_NORMAL, DUP12_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Preparing inData"); |
583 inData.Set(const_cast<TUint8*>(iCurrentPtr.Ptr()), iCompressionHeader.iCompressedSize, iCompressionHeader.iCompressedSize); |
620 inData.Set(const_cast<TUint8*>(iCurrentPtr.Ptr()), iCompressionHeader.iCompressedSize, iCompressionHeader.iCompressedSize); |
584 } // else |
621 } // else |
585 |
622 |
586 // Uncompress + Decrypt the buffer |
623 // Uncompress + Decrypt the buffer |
587 apOutput = HBufC8::NewLC(iCompressionHeader.iUncompressedSize); |
624 apOutput = HBufC8::NewLC(iCompressionHeader.iUncompressedSize); |
588 __LOG1("CSBEDecompressAndEncrypt::NextLC() - Allocated Output data for uncompressed data of size %d", iCompressionHeader.iUncompressedSize); |
625 OstTrace1(TRACE_NORMAL, DUP13_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Allocated Output data for uncompressed data of size %d", iCompressionHeader.iUncompressedSize); |
589 if (iEncryptionHeader.iEncrypted) |
626 if (iEncryptionHeader.iEncrypted) |
590 { |
627 { |
591 __LOG("CSBEDecompressAndEncrypt::NextLC() Encrypted data, trying to allocate temp"); |
628 OstTrace0(TRACE_NORMAL, DUP14_CSBEDECOMPRESSANDENCRYPT_NEXTLC, "Encrypted data, trying to allocate temp"); |
592 // Need another temp buffer |
629 // Need another temp buffer |
593 HBufC8* temp = HBufC8::NewLC(iCompressionHeader.iCompressedSize); |
630 HBufC8* temp = HBufC8::NewLC(iCompressionHeader.iCompressedSize); |
594 |
631 |
595 // Decrypt |
632 // Decrypt |
596 TPtr8 ptrTemp = temp->Des(); |
633 TPtr8 ptrTemp = temp->Des(); |
699 iEncryptionSizeRead += dataAvail; |
737 iEncryptionSizeRead += dataAvail; |
700 iCount += dataAvail; |
738 iCount += dataAvail; |
701 |
739 |
702 if (iEncryptionSizeRead < sizeof(TEncryptionHeader)) |
740 if (iEncryptionSizeRead < sizeof(TEncryptionHeader)) |
703 { |
741 { |
704 __LOG1("CSBEDecompressAndEncrypt::CreateCipherL - Got partial encryption header (%d bytes)",iEncryptionSizeRead); |
742 OstTrace1(TRACE_NORMAL, CSBEDECOMPRESSANDENCRYPT_CREATECIPHERL, "Got partial encryption header (%d bytes)",iEncryptionSizeRead); |
|
743 OstTraceFunctionExit0( CSBEDECOMPRESSANDENCRYPT_CREATECIPHERL_EXIT ); |
705 return EFalse; |
744 return EFalse; |
706 } |
745 } |
707 |
746 |
708 __LOG3("CSBEDecompressAndEncrypt::CreateCipherL - Got encryption header (encrypted=%d, buffer size=%d, total size=%d)", |
747 OstTraceExt3(TRACE_NORMAL, DUP1_CSBEDECOMPRESSANDENCRYPT_CREATECIPHERL, "Got encryption header (encrypted=%d, buffer size=%d, total size=%d)", |
709 iEncryptionHeader.iEncrypted, iEncryptionHeader.iBufferSize, iEncryptionHeader.iTotalSize); |
748 iEncryptionHeader.iEncrypted, iEncryptionHeader.iBufferSize, iEncryptionHeader.iTotalSize); |
710 |
749 |
711 // Check we have a sensible encryption header |
750 // Check we have a sensible encryption header |
712 if ((iEncryptionHeader.iBufferSize < 0) || (iEncryptionHeader.iBufferSize >= KMaxTInt/2) || |
751 if ((iEncryptionHeader.iBufferSize < 0) || (iEncryptionHeader.iBufferSize >= KMaxTInt/2) || |
713 (iEncryptionHeader.iTotalSize < 0)) |
752 (iEncryptionHeader.iTotalSize < 0)) |
714 { |
753 { |
715 __LOG("CSBEDecompressAndEncrypt::CreateCipherL() - Corrupt data"); |
754 OstTrace0(TRACE_ERROR, DUP2_CSBEDECOMPRESSANDENCRYPT_CREATECIPHERL, "Corrupt data"); |
716 User::Leave(KErrCorrupt); |
755 User::Leave(KErrCorrupt); |
717 } |
756 } |
718 if (iEncryptionHeader.iEncrypted) |
757 if (iEncryptionHeader.iEncrypted) |
719 { |
758 { |
720 // Get the decryption key |
759 // Get the decryption key |