1 #include "ostree_hash.h"
9 std::string trimmed_hash = hash.substr(0, hash.find_last_not_of(
" \t\n\r\f\v") + 1);
11 std::istringstream refstr(trimmed_hash);
13 if (trimmed_hash.size() != 64) {
14 std::cout <<
"HASH size: " << trimmed_hash.size() <<
"\n";
18 for (
int i = 0; i < 32; i++) {
23 refstr.read(byte_string, 2);
25 byte_holder = strtoul(byte_string, &next_char, 16);
26 if (next_char != &byte_string[2]) {
29 sha256[i] = byte_holder & 0xFF;
34 OSTreeHash::OSTreeHash(
const uint8_t hash[32]) { std::memcpy(hash_, hash, 32); }
36 std::string OSTreeHash::string()
const {
37 std::stringstream str_str;
41 for (
int i = 0; i < 32; i++) {
42 str_str << std::setw(2) << std::hex << static_cast<uint64_t>(hash_[i]);
47 bool OSTreeHash::operator<(
const OSTreeHash& other)
const {
return memcmp(hash_, other.hash_, 32) < 0; }
49 std::ostream& operator<<(std::ostream& os,
const OSTreeHash& obj) {