nstool/lib/libnx/source/NpdmBinary.cpp

111 lines
1.9 KiB
C++
Raw Normal View History

#include <nx/NpdmBinary.h>
nx::NpdmBinary::NpdmBinary() :
mAci(),
mAcid()
{
clear();
}
nx::NpdmBinary::NpdmBinary(const NpdmBinary & other) :
mAci(),
mAcid()
{
2018-06-24 08:18:54 +00:00
*this = other;
}
2018-06-24 08:18:54 +00:00
void nx::NpdmBinary::operator=(const NpdmBinary & other)
{
2018-06-24 08:18:54 +00:00
if (other.getBytes().size())
{
fromBytes(other.getBytes().data(), other.getBytes().size());
}
else
{
NpdmHeader::operator=(other);
mAci = other.mAci;
mAcid = other.mAcid;
}
}
bool nx::NpdmBinary::operator==(const NpdmBinary & other) const
{
2018-06-24 08:18:54 +00:00
return (NpdmHeader::operator==(other)) \
&& (mAci == other.mAci) \
&& (mAcid == other.mAcid);
}
bool nx::NpdmBinary::operator!=(const NpdmBinary & other) const
{
2018-06-24 08:18:54 +00:00
return !(*this == other);
}
2018-06-24 08:18:54 +00:00
void nx::NpdmBinary::toBytes()
{
mAci.exportBinary();
mAcid.exportBinary();
2018-06-24 08:18:54 +00:00
setAciSize(mAci.getBytes().size());
setAcidSize(mAcid.getBytes().size());
}
2018-06-24 08:18:54 +00:00
void nx::NpdmBinary::fromBytes(const byte_t* data, size_t len)
{
// clear
clear();
// import header
2018-06-24 08:18:54 +00:00
NpdmHeader::fromBytes(data, len);
// check size
if (getNpdmSize() > len)
{
throw fnd::Exception(kModuleName, "NPDM binary too small");
}
// save local copy
2018-06-24 08:18:54 +00:00
mRawBinary.alloc(getNpdmSize());
memcpy(mRawBinary.data(), data, mRawBinary.size());
// import Aci/Acid
if (getAciPos().size)
{
2018-06-24 08:18:54 +00:00
mAci.importBinary(mRawBinary.data() + getAciPos().offset, getAciPos().size);
}
if (getAcidPos().size)
{
2018-06-24 08:18:54 +00:00
mAcid.importBinary(mRawBinary.data() + getAcidPos().offset, getAcidPos().size);
}
}
const fnd::Vec<byte_t>& nx::NpdmBinary::getBytes() const
{
return mRawBinary;
}
void nx::NpdmBinary::clear()
{
NpdmHeader::clear();
mAci.clear();
mAcid.clear();
}
const nx::AciBinary & nx::NpdmBinary::getAci() const
{
return mAci;
}
void nx::NpdmBinary::setAci(const AciBinary & aci)
{
mAci = aci;
}
const nx::AcidBinary & nx::NpdmBinary::getAcid() const
{
return mAcid;
}
void nx::NpdmBinary::setAcid(const AcidBinary & acid)
{
mAcid = acid;
2018-06-24 08:18:54 +00:00
}