#pragma once #include #include #include namespace nn { namespace pki { template class SignedData : public fnd::ISerialisable { public: SignedData(); SignedData(const SignedData& other); void operator=(const SignedData& other); bool operator==(const SignedData& other) const; bool operator!=(const SignedData& other) const; // export/import void toBytes(); void fromBytes(const byte_t* src, size_t size); const fnd::Vec& getBytes() const; // variables void clear(); const pki::SignatureBlock& getSignature() const; void setSignature(const SignatureBlock& signature); const T& getBody() const; void setBody(const T& body); private: const std::string kModuleName = "SIGNED_DATA"; // raw binary fnd::Vec mRawBinary; // variables SignatureBlock mSignature; T mBody; }; template inline SignedData::SignedData() { clear(); } template inline SignedData::SignedData(const SignedData& other) { *this = other; } template inline void SignedData::operator=(const SignedData& other) { mRawBinary = other.mRawBinary; mSignature = other.mSignature; mBody = other.mBody; } template inline bool SignedData::operator==(const SignedData& other) const { return (mSignature == other.mSignature) \ && (mBody == other.mBody); } template inline bool SignedData::operator!=(const SignedData& other) const { return !(*this == other); } template inline void SignedData::toBytes() { mSignature.toBytes(); mBody.toBytes(); mRawBinary.alloc(mSignature.getBytes().size() + mBody.getBytes().size()); memcpy(mRawBinary.data(), mSignature.getBytes().data(), mSignature.getBytes().size()); memcpy(mRawBinary.data() + mSignature.getBytes().size(), mBody.getBytes().data(), mBody.getBytes().size()); } template inline void SignedData::fromBytes(const byte_t* src, size_t size) { mSignature.fromBytes(src, size); mBody.fromBytes(src + mSignature.getBytes().size(), size - mSignature.getBytes().size()); mRawBinary.alloc(mSignature.getBytes().size() + mBody.getBytes().size()); memcpy(mRawBinary.data(), src, mRawBinary.size()); } template inline const fnd::Vec& SignedData::getBytes() const { return mRawBinary; } template inline void SignedData::clear() { mRawBinary.clear(); mSignature.clear(); mBody.clear(); } template inline const pki::SignatureBlock& SignedData::getSignature() const { return mSignature; } template inline void SignedData::setSignature(const SignatureBlock& signature) { mSignature = signature; } template inline const T& SignedData::getBody() const { return mBody; } template inline void SignedData::setBody(const T& body) { mBody = body; } } }