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

Method Put

src/twcrypto/cryptoarchive.cpp:281–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281void cCryptoSink::Put(const byte* inString, unsigned int length)
282{
283 if (mpBuffer == 0)
284 {
285 // this is the first write
286 mBufferLen = mpCipher->GetBlockSizePlain();
287 mpBuffer = new int8[mBufferLen];
288 mBufferUsed = 0;
289 }
290
291 // RAD: Cast to int
292 ASSERT(length <= std::numeric_limits<unsigned int>::max());
293 int nLength = static_cast<int>(length);
294
295 int i = 0;
296 while (i < nLength)
297 {
298 int bytesToCopy = mBufferLen - mBufferUsed;
299 if (bytesToCopy > nLength - i)
300 bytesToCopy = nLength - i;
301
302 memcpy(mpBuffer + mBufferUsed, (int8*)inString + i, bytesToCopy);
303 mBufferUsed += bytesToCopy;
304
305 if (mBufferUsed >= mBufferLen)
306 {
307 ASSERT(mBufferUsed == mBufferLen); // should be if our math is right
308
309 int8* pTmp = new int8[mpCipher->GetBlockSizeCipher()];
310 mpCipher->ProcessBlock(mpBuffer, pTmp);
311
312 mpDestArchive->WriteBlob(pTmp, mpCipher->GetBlockSizeCipher());
313
314 delete [] pTmp;
315 mBufferUsed = 0;
316 }
317
318 i += bytesToCopy;
319 }
320
321 ASSERT(i == nLength); // should be if our math is right
322}
323
324void cCryptoSink::InputFinished()
325{

Callers 2

WriteMethod · 0.45
PumpMethod · 0.45

Calls 4

GetBlockSizePlainMethod · 0.80
GetBlockSizeCipherMethod · 0.80
ProcessBlockMethod · 0.45
WriteBlobMethod · 0.45

Tested by

no test coverage detected