@@ -126,7 +126,7 @@ std::string EncodeBase64(Span<const unsigned char> input)
126126 return str;
127127}
128128
129- std::vector<unsigned char > DecodeBase64 (const char * p, bool * pf_invalid )
129+ std::optional<std:: vector<unsigned char >> DecodeBase64 (const char * p)
130130{
131131 static const int8_t decode64_table[256 ]{
132132 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
@@ -167,18 +167,17 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
167167 ++p;
168168 }
169169 valid = valid && (p - e) % 4 == 0 && p - q < 4 ;
170- *pf_invalid = !valid;
170+ if ( !valid) return {} ;
171171
172172 return ret;
173173}
174174
175- std::vector<unsigned char > DecodeBase64 (const std::string& str, bool * pf_invalid )
175+ std::optional<std:: vector<unsigned char >> DecodeBase64 (const std::string& str)
176176{
177177 if (!ValidAsCString (str)) {
178- *pf_invalid = true ;
179178 return {};
180179 }
181- return DecodeBase64 (str.c_str (), pf_invalid );
180+ return DecodeBase64 (str.c_str ());
182181}
183182
184183std::string EncodeBase32 (Span<const unsigned char > input, bool pad)
@@ -201,7 +200,7 @@ std::string EncodeBase32(const std::string& str, bool pad)
201200 return EncodeBase32 (MakeUCharSpan (str), pad);
202201}
203202
204- std::vector<unsigned char > DecodeBase32 (const char * p, bool * pf_invalid )
203+ std::optional<std:: vector<unsigned char >> DecodeBase32 (const char * p)
205204{
206205 static const int8_t decode32_table[256 ]{
207206 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
@@ -242,18 +241,17 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
242241 ++p;
243242 }
244243 valid = valid && (p - e) % 8 == 0 && p - q < 8 ;
245- *pf_invalid = !valid;
244+ if ( !valid) return {} ;
246245
247246 return ret;
248247}
249248
250- std::vector<unsigned char > DecodeBase32 (const std::string& str, bool * pf_invalid )
249+ std::optional<std:: vector<unsigned char >> DecodeBase32 (const std::string& str)
251250{
252251 if (!ValidAsCString (str)) {
253- *pf_invalid = true ;
254252 return {};
255253 }
256- return DecodeBase32 (str.c_str (), pf_invalid );
254+ return DecodeBase32 (str.c_str ());
257255}
258256
259257namespace {
0 commit comments