| 279 | } |
| 280 | |
| 281 | void 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 | |
| 324 | void cCryptoSink::InputFinished() |
| 325 | { |
no test coverage detected