MCPcopy Create free account
hub / github.com/Clarionos/clarion / base58_to_binary

Function base58_to_binary

libraries/clcrypto/base58.cpp:23–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22template <typename Container>
23void 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
47template <typename Container>
48std::string binary_to_base58(const Container& bin) {

Callers 1

from_base58Function · 0.85

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected