MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / valid_external

Method valid_external

mlspp/src/state.cpp:1893–1933  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1891}
1892
1893bool
1894// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1895State::valid_external(const std::vector<CachedProposal>& proposals) const
1896{
1897 // Exactly one ExternalInit
1898 auto ext_init_count = stdx::count_if(proposals, [](const auto& cached) {
1899 return cached.proposal.proposal_type() == ProposalType::external_init;
1900 });
1901 auto one_ext_init = (ext_init_count == 1);
1902
1903 // At most one Remove proposal, with which the joiner removes an old version
1904 // of themselves. If a Remove proposal is present, then the LeafNode in the
1905 // path field of the external commit MUST meet the same criteria as would the
1906 // LeafNode in an Update for the removed leaf (see Section 12.1.2). In
1907 // particular, the credential in the LeafNode MUST present a set of
1908 // identifiers that is acceptable to the application for the removed
1909 // participant.
1910 // TODO(RLB) Verify that Remove is properly formed
1911 auto remove_count = stdx::count_if(proposals, [](const auto& cached) {
1912 return cached.proposal.proposal_type() == ProposalType::remove;
1913 });
1914 auto no_dup_remove = (remove_count <= 1);
1915
1916 // Zero or more PreSharedKey proposals.
1917 // No other proposals.
1918 auto no_disallowed = stdx::all_of(proposals, [&](const auto& cached) {
1919 switch (cached.proposal.proposal_type()) {
1920 case ProposalType::external_init:
1921 case ProposalType::remove:
1922 return true;
1923
1924 case ProposalType::psk:
1925 return valid(var::get<PreSharedKey>(cached.proposal.content));
1926
1927 default:
1928 return false;
1929 }
1930 });
1931
1932 return one_ext_init && no_dup_remove && no_disallowed;
1933}
1934
1935State::CommitParams
1936State::infer_commit_type(

Callers 1

handleMethod · 0.45

Calls 3

count_ifFunction · 0.85
all_ofFunction · 0.85
proposal_typeMethod · 0.80

Tested by

no test coverage detected