| 361 | } |
| 362 | |
| 363 | unsigned int cCryptoSource::Pump(unsigned int size) |
| 364 | { |
| 365 | if (mpBuffer == 0) |
| 366 | { |
| 367 | // first time this has been called |
| 368 | mBufferLen = mpCipher->GetBlockSizePlain(); |
| 369 | mpBuffer = new int8[mBufferLen]; |
| 370 | mBufferUsed = mBufferLen; |
| 371 | } |
| 372 | |
| 373 | // RAD: Cast to int (Why are these locals signed if the interface is unsigned?) |
| 374 | ASSERT(size <= std::numeric_limits<unsigned int>::max()); |
| 375 | int nSize = static_cast<int>(size); |
| 376 | |
| 377 | int i = 0; |
| 378 | while (i < nSize) |
| 379 | { |
| 380 | if (mBufferUsed >= mBufferLen) |
| 381 | { |
| 382 | ASSERT(mBufferUsed == mBufferLen); // should be if our math is right |
| 383 | |
| 384 | int8* pTmp = new int8[mpCipher->GetBlockSizeCipher()]; |
| 385 | |
| 386 | int l = mpSrcArchive->ReadBlob(pTmp, mpCipher->GetBlockSizeCipher()); |
| 387 | if (l != mpCipher->GetBlockSizeCipher()) |
| 388 | { |
| 389 | delete [] pTmp; |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | mpCipher->ProcessBlock(pTmp, mpBuffer); |
| 394 | |
| 395 | delete [] pTmp; |
| 396 | mBufferUsed = 0; |
| 397 | } |
| 398 | |
| 399 | int bytesToCopy = mBufferLen - mBufferUsed; |
| 400 | if (bytesToCopy > nSize - i) |
| 401 | bytesToCopy = nSize - i; |
| 402 | |
| 403 | outQueue->Put((byte*)(mpBuffer + mBufferUsed), bytesToCopy); |
| 404 | |
| 405 | mBufferUsed += bytesToCopy; |
| 406 | i += bytesToCopy; |
| 407 | } |
| 408 | |
| 409 | ASSERT(i == nSize); // should be if our math is right |
| 410 | |
| 411 | return i; |
| 412 | } |
| 413 | |
| 414 | unsigned long cCryptoSource::PumpAll() |
| 415 | { |
no test coverage detected