diff --git a/lib/libes/include/es/SignedData.h b/lib/libes/include/es/SignedData.h new file mode 100644 index 0000000..6f4a7e1 --- /dev/null +++ b/lib/libes/include/es/SignedData.h @@ -0,0 +1,113 @@ +#pragma once +#include +#include +#include +#include + +namespace es +{ + template + class SignedData + : public fnd::ISerialiseableBinary + { + public: + SignedData() + { + clear(); + } + SignedData(const SignedData& other) + { + copyFrom(other); + } + + void operator=(const SignedData& other) + { + copyFrom(other); + } + bool operator==(const SignedData& other) const + { + return isEqual(other); + } + bool operator!=(const SignedData& other) const + { + return !(*this == other); + } + + void importBinary(const byte_t* src, size_t size) + { + mSignature.importBinary(src, size); + mBody.importBinary(src + mSignature.getSize(), size - mSignature.getSize()); + + mBinaryBlob.alloc(mSignature.getSize() + mBody.getSize()); + memcpy(mBinaryBlob.getBytes(), src, mBinaryBlob.getSize()); + } + + void exportBinary() + { + mSignature.exportBinary(); + mBody.exportBinary(); + + mBinaryBlob.alloc(mSignature.getSize() + mBody.getSize()); + + memcpy(mBinaryBlob.getBytes(), mSignature.getBytes(), mSignature.getSize()); + memcpy(mBinaryBlob.getBytes() + mSignature.getSize(), mBody.getBytes(), mBody.getSize()); + } + + const byte_t* getBytes() const + { + return mBinaryBlob.getBytes(); + } + size_t getSize() const + { + return mBinaryBlob.getSize(); + } + + void clear() + { + mBinaryBlob.clear(); + mSignature.clear(); + mBody.clear(); + } + + const es::SignatureBlock& getSignature() const + { + return mSignature; + } + void setSignature(const SignatureBlock& signature) + { + mSignature = signature; + } + + const T& getBody() const + { + return mBody; + } + void setBody(const T& body) + { + mBody = body; + } + private: + const std::string kModuleName = "SIGNED_DATA"; + + // raw binary + fnd::MemoryBlob mBinaryBlob; + + // variables + SignatureBlock mSignature; + T mBody; + + // helpers + bool isEqual(const SignedData& other) const + { + return (mSignature == other.mSignature) \ + && (mBody == other.mBody); + } + void copyFrom(const SignedData& other) + { + mBinaryBlob = other.mBinaryBlob; + mSignature = other.mSignature; + mBody = other.mBody; + } + }; +} + diff --git a/lib/libes/include/es/TicketBinary.h b/lib/libes/include/es/TicketBinary.h deleted file mode 100644 index a762336..0000000 --- a/lib/libes/include/es/TicketBinary.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include -#include -#include -#include - -namespace es -{ - class TicketBinary - : public fnd::ISerialiseableBinary - { - public: - TicketBinary(); - TicketBinary(const TicketBinary& other); - - void operator=(const TicketBinary& other); - bool operator==(const TicketBinary& other) const; - bool operator!=(const TicketBinary& other) const; - - void importBinary(byte_t* src, size_t size); - void exportBinary(); - - const byte_t* getBytes() const; - size_t getSize() const; - - - private: - }; -} \ No newline at end of file