| 142 | } |
| 143 | |
| 144 | [[nodiscard]] static bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet, int max_ret_len) |
| 145 | { |
| 146 | if (!DecodeBase58(psz, vchRet, max_ret_len > std::numeric_limits<int>::max() - 4 ? std::numeric_limits<int>::max() : max_ret_len + 4) || |
| 147 | (vchRet.size() < 4)) { |
| 148 | vchRet.clear(); |
| 149 | return false; |
| 150 | } |
| 151 | // re-calculate the checksum, ensure it matches the included 4-byte checksum |
| 152 | uint256 hash = Hash(Span{vchRet}.first(vchRet.size() - 4)); |
| 153 | if (memcmp(&hash, &vchRet[vchRet.size() - 4], 4) != 0) { |
| 154 | vchRet.clear(); |
| 155 | return false; |
| 156 | } |
| 157 | vchRet.resize(vchRet.size() - 4); |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret) |
| 162 | { |