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

Function CheckChecksum

src/script/descriptor.cpp:2921–2952  ·  view source on GitHub ↗

Check a descriptor checksum, and update desc to be the checksum-less part. */

Source from the content-addressed store, hash-verified

2919
2920/** Check a descriptor checksum, and update desc to be the checksum-less part. */
2921bool CheckChecksum(std::span<const char>& sp, bool require_checksum, std::string& error, std::string* out_checksum = nullptr)
2922{
2923 auto check_split = Split(sp, '#');
2924 if (check_split.size() > 2) {
2925 error = "Multiple '#' symbols";
2926 return false;
2927 }
2928 if (check_split.size() == 1 && require_checksum){
2929 error = "Missing checksum";
2930 return false;
2931 }
2932 if (check_split.size() == 2) {
2933 if (check_split[1].size() != 8) {
2934 error = strprintf("Expected 8 character checksum, not %u characters", check_split[1].size());
2935 return false;
2936 }
2937 }
2938 auto checksum = DescriptorChecksum(check_split[0]);
2939 if (checksum.empty()) {
2940 error = "Invalid characters in payload";
2941 return false;
2942 }
2943 if (check_split.size() == 2) {
2944 if (!std::equal(checksum.begin(), checksum.end(), check_split[1].begin())) {
2945 error = strprintf("Provided checksum '%s' does not match computed checksum '%s'", std::string(check_split[1].begin(), check_split[1].end()), checksum);
2946 return false;
2947 }
2948 }
2949 if (out_checksum) *out_checksum = std::move(checksum);
2950 sp = check_split[0];
2951 return true;
2952}
2953
2954std::vector<std::unique_ptr<Descriptor>> Parse(std::string_view descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum)
2955{

Callers 2

ParseFunction · 0.85
GetDescriptorChecksumFunction · 0.85

Calls 6

DescriptorChecksumFunction · 0.85
SplitFunction · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected