2018-06-23 03:32:38 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
2018-06-24 04:46:11 +00:00
|
|
|
#include <fnd/ISerialisable.h>
|
2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/pki/SignatureBlock.h>
|
2018-06-23 03:32:38 +00:00
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
namespace nn
|
|
|
|
{
|
2018-08-06 08:59:56 +00:00
|
|
|
namespace pki
|
2018-06-23 03:32:38 +00:00
|
|
|
{
|
|
|
|
template <class T>
|
|
|
|
class SignedData
|
2018-06-24 15:01:16 +00:00
|
|
|
: public fnd::ISerialisable
|
2018-06-23 03:32:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-06-24 04:46:11 +00:00
|
|
|
SignedData();
|
|
|
|
SignedData(const SignedData& other);
|
|
|
|
|
|
|
|
void operator=(const SignedData& other);
|
|
|
|
bool operator==(const SignedData& other) const;
|
|
|
|
bool operator!=(const SignedData& other) const;
|
|
|
|
|
|
|
|
// export/import
|
2018-06-24 15:01:16 +00:00
|
|
|
void toBytes();
|
2018-06-24 04:46:11 +00:00
|
|
|
void fromBytes(const byte_t* src, size_t size);
|
|
|
|
const fnd::Vec<byte_t>& getBytes() const;
|
|
|
|
|
|
|
|
// variables
|
|
|
|
void clear();
|
|
|
|
|
2018-08-06 08:59:56 +00:00
|
|
|
const pki::SignatureBlock& getSignature() const;
|
2018-06-24 04:46:11 +00:00
|
|
|
void setSignature(const SignatureBlock& signature);
|
|
|
|
|
|
|
|
const T& getBody() const;
|
|
|
|
void setBody(const T& body);
|
2018-06-23 03:32:38 +00:00
|
|
|
private:
|
|
|
|
const std::string kModuleName = "SIGNED_DATA";
|
|
|
|
|
|
|
|
// raw binary
|
2018-06-24 04:46:11 +00:00
|
|
|
fnd::Vec<byte_t> mRawBinary;
|
2018-06-23 03:32:38 +00:00
|
|
|
|
|
|
|
// variables
|
|
|
|
SignatureBlock mSignature;
|
|
|
|
T mBody;
|
|
|
|
};
|
2018-06-24 04:46:11 +00:00
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline SignedData<T>::SignedData()
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline SignedData<T>::SignedData(const SignedData& other)
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline void SignedData<T>::operator=(const SignedData& other)
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
mRawBinary = other.mRawBinary;
|
|
|
|
mSignature = other.mSignature;
|
|
|
|
mBody = other.mBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline bool SignedData<T>::operator==(const SignedData& other) const
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
return (mSignature == other.mSignature) \
|
|
|
|
&& (mBody == other.mBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline bool SignedData<T>::operator!=(const SignedData& other) const
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline void SignedData<T>::toBytes()
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
mSignature.toBytes();
|
|
|
|
mBody.toBytes();
|
|
|
|
|
|
|
|
mRawBinary.alloc(mSignature.getBytes().size() + mBody.getBytes().size());
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
memcpy(mRawBinary.data(), mSignature.getBytes().data(), mSignature.getBytes().size());
|
|
|
|
memcpy(mRawBinary.data() + mSignature.getBytes().size(), mBody.getBytes().data(), mBody.getBytes().size());
|
2018-06-24 04:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline void SignedData<T>::fromBytes(const byte_t* src, size_t size)
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
mSignature.fromBytes(src, size);
|
|
|
|
mBody.fromBytes(src + mSignature.getBytes().size(), size - mSignature.getBytes().size());
|
|
|
|
|
|
|
|
mRawBinary.alloc(mSignature.getBytes().size() + mBody.getBytes().size());
|
2018-06-24 15:01:16 +00:00
|
|
|
memcpy(mRawBinary.data(), src, mRawBinary.size());
|
2018-06-24 04:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline const fnd::Vec<byte_t>& SignedData<T>::getBytes() const
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline void SignedData<T>::clear()
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
mRawBinary.clear();
|
|
|
|
mSignature.clear();
|
|
|
|
mBody.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-08-06 08:59:56 +00:00
|
|
|
inline const pki::SignatureBlock& SignedData<T>::getSignature() const
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
return mSignature;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline void SignedData<T>::setSignature(const SignatureBlock& signature)
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
mSignature = signature;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline const T& SignedData<T>::getBody() const
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
return mBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2018-06-24 15:01:16 +00:00
|
|
|
inline void SignedData<T>::setBody(const T& body)
|
2018-06-24 04:46:11 +00:00
|
|
|
{
|
|
|
|
mBody = body;
|
|
|
|
}
|
2018-06-23 03:32:38 +00:00
|
|
|
}
|
2018-08-07 08:13:18 +00:00
|
|
|
}
|