MCPcopy Create free account
hub / github.com/ElementsProject/elements / CheckChecksum

Function CheckChecksum

src/script/descriptor.cpp:1367–1400  ·  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

1365
1366/** Check a descriptor checksum, and update desc to be the checksum-less part. */
1367bool CheckChecksum(Span<const char>& sp, bool require_checksum, std::string& error, std::string* out_checksum = nullptr)
1368{
1369 using namespace spanparsing;
1370
1371 auto check_split = Split(sp, '#');
1372 if (check_split.size() > 2) {
1373 error = "Multiple '#' symbols";
1374 return false;
1375 }
1376 if (check_split.size() == 1 && require_checksum){
1377 error = "Missing checksum";
1378 return false;
1379 }
1380 if (check_split.size() == 2) {
1381 if (check_split[1].size() != 8) {
1382 error = strprintf("Expected 8 character checksum, not %u characters", check_split[1].size());
1383 return false;
1384 }
1385 }
1386 auto checksum = DescriptorChecksum(check_split[0]);
1387 if (checksum.empty()) {
1388 error = "Invalid characters in payload";
1389 return false;
1390 }
1391 if (check_split.size() == 2) {
1392 if (!std::equal(checksum.begin(), checksum.end(), check_split[1].begin())) {
1393 error = strprintf("Provided checksum '%s' does not match computed checksum '%s'", std::string(check_split[1].begin(), check_split[1].end()), checksum);
1394 return false;
1395 }
1396 }
1397 if (out_checksum) *out_checksum = std::move(checksum);
1398 sp = check_split[0];
1399 return true;
1400}
1401
1402std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum)
1403{

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