mirror of
https://github.com/jakcron/nstool
synced 2024-11-22 21:49:30 +00:00
[es] Remove es::TicketBinary Add es::SignedData
This commit is contained in:
parent
8f15dd693e
commit
40b1dad10e
2 changed files with 113 additions and 29 deletions
113
lib/libes/include/es/SignedData.h
Normal file
113
lib/libes/include/es/SignedData.h
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -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:
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue