Skip to content

Commit

Permalink
Simplify unhex
Browse files Browse the repository at this point in the history
  • Loading branch information
jedekar committed Jan 12, 2024
1 parent a1e314b commit 4dee600
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions packager/live_packager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,10 @@ std::vector<uint8_t> ReadTestDataFile(const std::string& name) {
return data;
}

uint8_t hex_char_to_int(const char& c) {
unsigned result = 0;
if (c >= '0' && c <= '9') {
result = c - '0';
} else if (c >= 'A' && c <= 'F') {
result = c - 'A' + 10;
} else if (c >= 'a' && c <= 'f') {
result = c - 'a' + 10;
} else {
throw std::out_of_range("input character is out of hex range");
}

return result;
}

std::vector<uint8_t> unhex(const std::string& in) {
std::vector<uint8_t> out;
for (std::size_t i = 1; i < in.size(); i += 2) {
out.push_back(16 * hex_char_to_int(in[i - 1]) + hex_char_to_int(in[i]));
}

return out;
auto converted = absl::HexStringToBytes(in);
return {converted.begin(), converted.end()};
}

std::vector<uint8_t> unbase64(const std::string& base64_string) {
Expand Down

0 comments on commit 4dee600

Please sign in to comment.