MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / Pump

Method Pump

src/twcrypto/cryptoarchive.cpp:363–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363unsigned 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
414unsigned long cCryptoSource::PumpAll()
415{

Callers 2

ExtractFunction · 0.80
ReadMethod · 0.80

Calls 5

GetBlockSizePlainMethod · 0.80
GetBlockSizeCipherMethod · 0.80
ReadBlobMethod · 0.45
ProcessBlockMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected