| 154 | } |
| 155 | |
| 156 | std::vector<unsigned char> cmCryptoHash::ByteHashStream(std::istream& sin) |
| 157 | { |
| 158 | if (sin) { |
| 159 | this->Initialize(); |
| 160 | { |
| 161 | // Should be efficient enough on most system: |
| 162 | KWIML_INT_uint64_t buffer[512]; |
| 163 | char* buffer_c = reinterpret_cast<char*>(buffer); |
| 164 | unsigned char const* buffer_uc = |
| 165 | reinterpret_cast<unsigned char const*>(buffer); |
| 166 | // This copy loop is very sensitive on certain platforms with |
| 167 | // slightly broken stream libraries (like HPUX). Normally, it is |
| 168 | // incorrect to not check the error condition on the fin.read() |
| 169 | // before using the data, but the fin.gcount() will be zero if an |
| 170 | // error occurred. Therefore, the loop should be safe everywhere. |
| 171 | while (sin) { |
| 172 | sin.read(buffer_c, sizeof(buffer)); |
| 173 | if (int gcount = static_cast<int>(sin.gcount())) { |
| 174 | this->Append(buffer_uc, gcount); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | if (sin.eof()) { |
| 179 | // Success |
| 180 | return this->Finalize(); |
| 181 | } |
| 182 | // Finalize anyway |
| 183 | this->Finalize(); |
| 184 | } |
| 185 | // Return without success |
| 186 | return std::vector<unsigned char>(); |
| 187 | } |
| 188 | |
| 189 | std::vector<unsigned char> cmCryptoHash::ByteHashFile(std::string const& file) |
| 190 | { |
no test coverage detected