[es] Remove es::TicketBinary Add es::SignedData

This commit is contained in:
jakcron 2018-06-23 11:32:38 +08:00
parent 8f15dd693e
commit 40b1dad10e
2 changed files with 113 additions and 29 deletions

View file

@ -0,0 +1,113 @@
#pragma once
#include <string>
#include <fnd/MemoryBlob.h>
#include <fnd/ISerialiseableBinary.h>
#include <es/SignatureBlock.h>
namespace es
{
template <class T>
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;
}
};
}

View file

@ -1,29 +0,0 @@
#pragma once
#include <string>
#include <fnd/MemoryBlob.h>
#include <fnd/ISerialiseableBinary.h>
#include <es/ticket.h>
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:
};
}