mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 11:54:01 +00:00
checksums: add functions for returning results as a hex string
This commit is contained in:
parent
07eaeb0cda
commit
3669c5bc58
@ -91,6 +91,36 @@ calculate_as_uint(algorithm_e algorithm,
|
||||
return dynamic_cast<uint_result_c &>(*worker).get_result_as_uint();
|
||||
}
|
||||
|
||||
std::string
|
||||
calculate_as_hex_string(algorithm_e algorithm,
|
||||
memory_c const &buffer,
|
||||
uint64_t initial_value) {
|
||||
return calculate_as_hex_string(algorithm, buffer.get_buffer(), buffer.get_size(), initial_value);
|
||||
}
|
||||
|
||||
std::string
|
||||
calculate_as_hex_string(algorithm_e algorithm,
|
||||
void const *buffer,
|
||||
size_t size,
|
||||
uint64_t initial_value) {
|
||||
auto worker = for_algorithm(algorithm, initial_value);
|
||||
|
||||
worker->add(buffer, size);
|
||||
worker->finish();
|
||||
|
||||
auto result = worker->get_result();
|
||||
auto result_size = result->get_size();
|
||||
auto result_buffer = result->get_buffer();
|
||||
|
||||
std::string hex_string;
|
||||
hex_string.reserve(result_size * 2);
|
||||
|
||||
for (auto idx = 0u; idx < result_size; ++idx)
|
||||
hex_string += fmt::format("{0:02x}", result_buffer[idx]);
|
||||
|
||||
return hex_string;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
base_c &
|
||||
|
@ -39,5 +39,7 @@ memory_cptr calculate(algorithm_e algorithm, memory_c const &buffer, uint64_t in
|
||||
memory_cptr calculate(algorithm_e algorithm, void const *buffer, size_t size, uint64_t initial_value = 0);
|
||||
uint64_t calculate_as_uint(algorithm_e algorithm, memory_c const &buffer, uint64_t initial_value = 0);
|
||||
uint64_t calculate_as_uint(algorithm_e algorithm, void const *buffer, size_t size, uint64_t initial_value = 0);
|
||||
std::string calculate_as_hex_string(algorithm_e algorithm, memory_c const &buffer, uint64_t initial_value = 0);
|
||||
std::string calculate_as_hex_string(algorithm_e algorithm, void const *buffer, size_t size, uint64_t initial_value = 0);
|
||||
|
||||
} // namespace mtx::checksum
|
||||
|
Loading…
Reference in New Issue
Block a user