[nstool] Add flag to signal hash calc aligning.

This commit is contained in:
jakcron 2018-05-21 23:03:28 +08:00
parent bd991a25e1
commit c1f343d052
2 changed files with 26 additions and 5 deletions

View file

@ -3,7 +3,8 @@
HashTreeMeta::HashTreeMeta() : HashTreeMeta::HashTreeMeta() :
mLayerInfo(), mLayerInfo(),
mDataLayer(), mDataLayer(),
mMasterHashList() mMasterHashList(),
mDoAlignHashToBlock(false)
{ {
} }
@ -11,7 +12,8 @@ HashTreeMeta::HashTreeMeta() :
HashTreeMeta::HashTreeMeta(const nx::HierarchicalIntegrityHeader& hdr) : HashTreeMeta::HashTreeMeta(const nx::HierarchicalIntegrityHeader& hdr) :
mLayerInfo(), mLayerInfo(),
mDataLayer(), mDataLayer(),
mMasterHashList() mMasterHashList(),
mDoAlignHashToBlock(false)
{ {
importHierarchicalIntergityHeader(hdr); importHierarchicalIntergityHeader(hdr);
} }
@ -19,7 +21,8 @@ HashTreeMeta::HashTreeMeta(const nx::HierarchicalIntegrityHeader& hdr) :
HashTreeMeta::HashTreeMeta(const nx::HierarchicalSha256Header& hdr) : HashTreeMeta::HashTreeMeta(const nx::HierarchicalSha256Header& hdr) :
mLayerInfo(), mLayerInfo(),
mDataLayer(), mDataLayer(),
mMasterHashList() mMasterHashList(),
mDoAlignHashToBlock(false)
{ {
importHierarchicalSha256Header(hdr); importHierarchicalSha256Header(hdr);
} }
@ -41,6 +44,7 @@ void HashTreeMeta::operator=(const HashTreeMeta& other)
void HashTreeMeta::importHierarchicalIntergityHeader(const nx::HierarchicalIntegrityHeader& hdr) void HashTreeMeta::importHierarchicalIntergityHeader(const nx::HierarchicalIntegrityHeader& hdr)
{ {
mDoAlignHashToBlock = true;
for (size_t i = 0; i < hdr.getLayerInfo().getSize(); i++) for (size_t i = 0; i < hdr.getLayerInfo().getSize(); i++)
{ {
sLayer layer; sLayer layer;
@ -61,6 +65,7 @@ void HashTreeMeta::importHierarchicalIntergityHeader(const nx::HierarchicalInteg
void HashTreeMeta::importHierarchicalSha256Header(const nx::HierarchicalSha256Header& hdr) void HashTreeMeta::importHierarchicalSha256Header(const nx::HierarchicalSha256Header& hdr)
{ {
mDoAlignHashToBlock = false;
for (size_t i = 0; i < hdr.getLayerInfo().getSize(); i++) for (size_t i = 0; i < hdr.getLayerInfo().getSize(); i++)
{ {
sLayer layer; sLayer layer;
@ -109,11 +114,22 @@ void HashTreeMeta::setMasterHashList(const fnd::List<crypto::sha::sSha256Hash>&
mMasterHashList = master_hash_list; mMasterHashList = master_hash_list;
} }
bool HashTreeMeta::getAlignHashToBlock() const
{
return mDoAlignHashToBlock;
}
void HashTreeMeta::setAlignHashToBlock(bool doAlign)
{
mDoAlignHashToBlock = doAlign;
}
bool HashTreeMeta::isEqual(const HashTreeMeta& other) const bool HashTreeMeta::isEqual(const HashTreeMeta& other) const
{ {
return (mLayerInfo == other.mLayerInfo) \ return (mLayerInfo == other.mLayerInfo) \
&& (mDataLayer == other.mDataLayer) \ && (mDataLayer == other.mDataLayer) \
&& (mMasterHashList == other.mMasterHashList); && (mMasterHashList == other.mMasterHashList) \
&& (mDoAlignHashToBlock == other.mDoAlignHashToBlock);
} }
void HashTreeMeta::copyFrom(const HashTreeMeta& other) void HashTreeMeta::copyFrom(const HashTreeMeta& other)
@ -121,4 +137,5 @@ void HashTreeMeta::copyFrom(const HashTreeMeta& other)
mLayerInfo = other.mLayerInfo; mLayerInfo = other.mLayerInfo;
mDataLayer = other.mDataLayer; mDataLayer = other.mDataLayer;
mMasterHashList = other.mMasterHashList; mMasterHashList = other.mMasterHashList;
mDoAlignHashToBlock = other.mDoAlignHashToBlock;
} }

View file

@ -48,12 +48,16 @@ public:
const fnd::List<crypto::sha::sSha256Hash>& getMasterHashList() const; const fnd::List<crypto::sha::sSha256Hash>& getMasterHashList() const;
void setMasterHashList(const fnd::List<crypto::sha::sSha256Hash>& master_hash_list); void setMasterHashList(const fnd::List<crypto::sha::sSha256Hash>& master_hash_list);
bool getAlignHashToBlock() const;
void setAlignHashToBlock(bool doAlign);
private: private:
// data // data
fnd::List<sLayer> mLayerInfo; fnd::List<sLayer> mLayerInfo;
sLayer mDataLayer; sLayer mDataLayer;
fnd::List<crypto::sha::sSha256Hash> mMasterHashList; fnd::List<crypto::sha::sSha256Hash> mMasterHashList;
bool mDoAlignHashToBlock;
bool isEqual(const HashTreeMeta& other) const; bool isEqual(const HashTreeMeta& other) const;
void copyFrom(const HashTreeMeta& other); void copyFrom(const HashTreeMeta& other);