From 40b1dad10e304ce5c79f24ef99dc62868ecb1289 Mon Sep 17 00:00:00 2001 From: jakcron Date: Sat, 23 Jun 2018 11:32:38 +0800 Subject: [PATCH] [es] Remove es::TicketBinary Add es::SignedData --- lib/libes/include/es/SignedData.h | 113 ++++++++++++++++++++++++++++ lib/libes/include/es/TicketBinary.h | 29 ------- 2 files changed, 113 insertions(+), 29 deletions(-) create mode 100644 lib/libes/include/es/SignedData.h delete mode 100644 lib/libes/include/es/TicketBinary.h 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