| 1440 | } |
| 1441 | |
| 1442 | int WriteMemDataMD5( |
| 1443 | TFileStream * pStream, |
| 1444 | ULONGLONG RawDataOffs, |
| 1445 | void * pvRawData, |
| 1446 | DWORD dwRawDataSize, |
| 1447 | DWORD dwChunkSize, |
| 1448 | LPDWORD pcbTotalSize) |
| 1449 | { |
| 1450 | unsigned char * md5_array; |
| 1451 | unsigned char * md5; |
| 1452 | LPBYTE pbRawData = (LPBYTE)pvRawData; |
| 1453 | DWORD dwBytesRemaining = dwRawDataSize; |
| 1454 | DWORD dwMd5ArraySize = 0; |
| 1455 | int nError = ERROR_SUCCESS; |
| 1456 | |
| 1457 | // Allocate buffer for array of MD5 |
| 1458 | md5_array = md5 = AllocateMd5Buffer(dwRawDataSize, dwChunkSize, &dwMd5ArraySize); |
| 1459 | if(md5_array == NULL) |
| 1460 | return ERROR_NOT_ENOUGH_MEMORY; |
| 1461 | |
| 1462 | // For every file chunk, calculate MD5 |
| 1463 | while(dwBytesRemaining != 0) |
| 1464 | { |
| 1465 | // Get the remaining number of bytes to read |
| 1466 | dwChunkSize = STORMLIB_MIN(dwBytesRemaining, dwChunkSize); |
| 1467 | |
| 1468 | // Calculate MD5 |
| 1469 | CalculateDataBlockHash(pbRawData, dwChunkSize, md5); |
| 1470 | md5 += MD5_DIGEST_SIZE; |
| 1471 | |
| 1472 | // Move offset and size |
| 1473 | dwBytesRemaining -= dwChunkSize; |
| 1474 | pbRawData += dwChunkSize; |
| 1475 | } |
| 1476 | |
| 1477 | // Write the array od MD5's to the file |
| 1478 | RawDataOffs += dwRawDataSize; |
| 1479 | if(!FileStream_Write(pStream, &RawDataOffs, md5_array, dwMd5ArraySize)) |
| 1480 | nError = GetLastError(); |
| 1481 | |
| 1482 | // Give the caller the size of the MD5 array |
| 1483 | if(pcbTotalSize != NULL) |
| 1484 | *pcbTotalSize = dwRawDataSize + dwMd5ArraySize; |
| 1485 | |
| 1486 | // Free buffers and exit |
| 1487 | STORM_FREE(md5_array); |
| 1488 | return nError; |
| 1489 | } |
| 1490 | |
| 1491 | |
| 1492 | // Writes the MD5 for each chunk of the raw file data |
no test coverage detected