| 21 | |
| 22 | template <typename Container> |
| 23 | void base58_to_binary(Container& result, const std::string_view& s) { |
| 24 | std::size_t offset = result.size(); |
| 25 | for (auto& src_digit : s) { |
| 26 | int carry = base58_map[static_cast<uint8_t>(src_digit)]; |
| 27 | if (carry < 0) |
| 28 | throw std::runtime_error( "error parsing base58" ); |
| 29 | |
| 30 | for (std::size_t i = offset; i < result.size(); ++i) { |
| 31 | auto& result_byte = result[i]; |
| 32 | int x = static_cast<uint8_t>(result_byte) * 58 + carry; |
| 33 | result_byte = x; |
| 34 | carry = x >> 8; |
| 35 | } |
| 36 | if (carry) |
| 37 | result.push_back(static_cast<uint8_t>(carry)); |
| 38 | } |
| 39 | for (auto& src_digit : s) |
| 40 | if (src_digit == '1') |
| 41 | result.push_back(0); |
| 42 | else |
| 43 | break; |
| 44 | std::reverse(result.begin() + offset, result.end()); |
| 45 | } |
| 46 | |
| 47 | template <typename Container> |
| 48 | std::string binary_to_base58(const Container& bin) { |
no test coverage detected