20 #include <ripple/basics/Log.h>
21 #include <ripple/basics/Slice.h>
22 #include <ripple/basics/contract.h>
23 #include <ripple/basics/safe_cast.h>
24 #include <ripple/beast/core/LexicalCast.h>
25 #include <ripple/protocol/HashPrefix.h>
26 #include <ripple/protocol/digest.h>
27 #include <ripple/shamap/SHAMapTreeNode.h>
30 #include <openssl/sha.h>
41 auto p = std::make_shared<SHAMapInnerNode>(seq);
47 for (
int i = 0; i < 16; ++i)
64 assert(
mItem->peekData().size() >= 12);
75 assert(
mItem->peekData().size() >= 12);
88 auto item = std::make_shared<SHAMapItem const>(
92 return std::make_shared<SHAMapTreeNode>(
95 return std::make_shared<SHAMapTreeNode>(
111 Throw<std::runtime_error>(
"Short TXN+MD node");
115 Throw<std::out_of_range>(
120 auto item = std::make_shared<SHAMapItem const>(tag, s.
peekData());
123 return std::make_shared<SHAMapTreeNode>(
126 return std::make_shared<SHAMapTreeNode>(
142 Throw<std::runtime_error>(
"short AS node");
146 Throw<std::out_of_range>(
152 Throw<std::runtime_error>(
"Invalid AS node");
154 auto item = std::make_shared<SHAMapItem const>(tag, s.
peekData());
157 return std::make_shared<SHAMapTreeNode>(
160 return std::make_shared<SHAMapTreeNode>(
171 if (data.size() != 512)
172 Throw<std::runtime_error>(
"Invalid FI node");
174 auto ret = std::make_shared<SHAMapInnerNode>(seq);
178 for (
int i = 0; i < 16; ++i)
182 if (ret->mHashes[i].isNonZero())
183 ret->mIsBranch |= (1 << i);
200 auto ret = std::make_shared<SHAMapInnerNode>(seq);
202 for (
int i = 0; i < (len / 33); ++i)
206 if (!s.
get8(pos, 32 + (i * 33)))
207 Throw<std::runtime_error>(
"short CI node");
209 if ((pos < 0) || (pos >= 16))
210 Throw<std::runtime_error>(
"invalid CI node");
214 if (ret->mHashes[pos].isNonZero())
215 ret->mIsBranch |= (1 << pos);
229 auto const type = rawNode[rawNode.
size() - 1];
233 bool const hashValid =
false;
253 Throw<std::runtime_error>(
260 if (rawNode.
size() < 4)
261 Throw<std::runtime_error>(
"prefix: short node");
265 auto const type = safe_cast<HashPrefix>(
266 (safe_cast<std::uint32_t>(rawNode[0]) << 24) +
267 (safe_cast<std::uint32_t>(rawNode[1]) << 16) +
268 (safe_cast<std::uint32_t>(rawNode[2]) << 8) +
269 (safe_cast<std::uint32_t>(rawNode[3])));
273 bool const hashValid =
true;
288 Throw<std::runtime_error>(
289 "prefix: unknown type (" +
316 for (
auto pos = 0; pos < 16; ++pos)
359 Throw<std::runtime_error>(
"invalid I node type");
381 for (
int i = 0; i <
mHashes.size(); ++i)
409 Throw<std::runtime_error>(
"invalid I node type");
466 mItem = std::move(i);
484 for (
int i = 0; i < 16; ++i)
495 ret += beast::lexicalCastThrow<std::string>(
id.getDepth());
506 for (
int i = 0; i <
mHashes.size(); ++i)
511 ret += beast::lexicalCastThrow<std::string>(i);
537 ret += beast::lexicalCast<std::string>(
mItem->size());
547 assert((m >= 0) && (m < 16));
550 assert(child.get() !=
this);
566 assert((m >= 0) && (m < 16));
570 assert(child.get() !=
this);
578 assert(branch >= 0 && branch < 16);
588 assert(branch >= 0 && branch < 16);
600 assert(branch >= 0 && branch < 16);
603 assert(node->getNodeHash() ==
mHashes[branch]);
622 Throw<std::logic_error>(
"SHAMapInnerNode::key() should never be called");
638 for (
int i = 0; i < 16; ++i)
665 assert(
mItem !=
nullptr);