| 637 | } |
| 638 | |
| 639 | bool CalculateHashes(const char *pFilename, int Type, SHA256_DIGEST *pSha256, unsigned *pCrc) override |
| 640 | { |
| 641 | dbg_assert(pSha256 != nullptr || pCrc != nullptr, "At least one output argument required"); |
| 642 | |
| 643 | IOHANDLE File = OpenFile(pFilename, IOFLAG_READ, Type); |
| 644 | if(!File) |
| 645 | return false; |
| 646 | |
| 647 | SHA256_CTX Sha256Ctxt; |
| 648 | if(pSha256 != nullptr) |
| 649 | sha256_init(&Sha256Ctxt); |
| 650 | if(pCrc != nullptr) |
| 651 | *pCrc = 0; |
| 652 | unsigned char aBuffer[64 * 1024]; |
| 653 | while(true) |
| 654 | { |
| 655 | unsigned Bytes = io_read(File, aBuffer, sizeof(aBuffer)); |
| 656 | if(Bytes == 0) |
| 657 | break; |
| 658 | if(pSha256 != nullptr) |
| 659 | sha256_update(&Sha256Ctxt, aBuffer, Bytes); |
| 660 | if(pCrc != nullptr) |
| 661 | *pCrc = crc32(*pCrc, aBuffer, Bytes); |
| 662 | } |
| 663 | if(pSha256 != nullptr) |
| 664 | *pSha256 = sha256_finish(&Sha256Ctxt); |
| 665 | |
| 666 | io_close(File); |
| 667 | return true; |
| 668 | } |
| 669 | |
| 670 | struct CFindCBData |
| 671 | { |
no test coverage detected