MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / DecodeBase64

Function DecodeBase64

src/util/strencodings.cpp:108–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108std::optional<std::vector<unsigned char>> DecodeBase64(std::string_view str)
109{
110 static const int8_t decode64_table[256]{
111 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
112 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
113 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
114 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
115 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
116 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
117 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
118 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
119 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
120 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
121 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
122 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
123 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
124 };
125
126 if (str.size() % 4 != 0) return {};
127 /* One or two = characters at the end are permitted. */
128 if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
129 if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
130
131 std::vector<unsigned char> ret;
132 ret.reserve((str.size() * 3) / 4);
133 bool valid = ConvertBits<6, 8, false>(
134 [&](unsigned char c) { ret.push_back(c); },
135 str.begin(), str.end(),
136 [](char c) { return decode64_table[uint8_t(c)]; }
137 );
138 if (!valid) return {};
139
140 return ret;
141}
142
143std::string EncodeBase32(std::span<const unsigned char> input, bool pad)
144{

Callers 8

DecodeI2PBase64Function · 0.85
RPCAuthorizedFunction · 0.85
DecodeBase64PSBTFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGETFunction · 0.85
gotoLoadPSBTMethod · 0.85
TestGUIWatchOnlyFunction · 0.85
MessageVerifyFunction · 0.85

Calls 6

sizeMethod · 0.45
backMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGETFunction · 0.68
TestGUIWatchOnlyFunction · 0.68