2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/NpdmBinary.h>
|
2017-07-17 08:21:39 +00:00
|
|
|
|
2018-06-27 05:03:46 +00:00
|
|
|
#include <fnd/SimpleTextOutput.h>
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
nx::NpdmBinary::NpdmBinary() :
|
|
|
|
mAci(),
|
|
|
|
mAcid()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nx::NpdmBinary::NpdmBinary(const NpdmBinary & other) :
|
|
|
|
mAci(),
|
|
|
|
mAcid()
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
*this = other;
|
2017-07-17 08:21:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::NpdmBinary::operator=(const NpdmBinary & other)
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
2017-07-17 08:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-07-17 08:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::NpdmBinary::operator!=(const NpdmBinary & other) const
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return !(*this == other);
|
2017-07-17 08:21:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::NpdmBinary::toBytes()
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
2018-06-27 05:03:46 +00:00
|
|
|
throw fnd::Exception(kModuleName, "toBytes() not implemented.");
|
2017-07-17 08:21:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::NpdmBinary::fromBytes(const byte_t* data, size_t len)
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
// clear
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// import header
|
2018-06-24 08:18:54 +00:00
|
|
|
NpdmHeader::fromBytes(data, len);
|
2017-07-17 08:21:39 +00:00
|
|
|
|
|
|
|
// 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());
|
2017-07-17 08:21:39 +00:00
|
|
|
|
|
|
|
// import Aci/Acid
|
|
|
|
if (getAciPos().size)
|
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
mAci.fromBytes(mRawBinary.data() + getAciPos().offset, getAciPos().size);
|
2017-07-17 08:21:39 +00:00
|
|
|
}
|
|
|
|
if (getAcidPos().size)
|
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
mAcid.fromBytes(mRawBinary.data() + getAcidPos().offset, getAcidPos().size);
|
2018-06-24 08:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const fnd::Vec<byte_t>& nx::NpdmBinary::getBytes() const
|
|
|
|
{
|
|
|
|
return mRawBinary;
|
2017-07-17 08:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nx::NpdmBinary::clear()
|
|
|
|
{
|
|
|
|
NpdmHeader::clear();
|
|
|
|
mAci.clear();
|
|
|
|
mAcid.clear();
|
|
|
|
}
|
|
|
|
|
2018-06-27 05:03:46 +00:00
|
|
|
const nx::AccessControlInfoBinary & nx::NpdmBinary::getAci() const
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
return mAci;
|
|
|
|
}
|
|
|
|
|
2018-06-27 05:03:46 +00:00
|
|
|
void nx::NpdmBinary::setAci(const AccessControlInfoBinary & aci)
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
mAci = aci;
|
|
|
|
}
|
|
|
|
|
2018-06-27 05:03:46 +00:00
|
|
|
const nx::AccessControlInfoDescBinary & nx::NpdmBinary::getAcid() const
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
return mAcid;
|
|
|
|
}
|
|
|
|
|
2018-06-27 05:03:46 +00:00
|
|
|
void nx::NpdmBinary::setAcid(const AccessControlInfoDescBinary & acid)
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
mAcid = acid;
|
2018-06-24 08:18:54 +00:00
|
|
|
}
|