Unverified Commit de0b34bb authored by kladko's avatar kladko

bug/SKALE-3662 Adding libzmq

parent b8fceab6
//
// Created by kladko on 15.12.20.
//
#include "BLSSignReqMessage.h"
//
// Created by kladko on 15.12.20.
//
#ifndef SGXWALLET_BLSSIGNREQMSG_H
#define SGXWALLET_BLSSIGNREQMSG_H
#include "ZMQMessage.h"
class BLSSignReqMessage : public ZMQMessage {
public:
BLSSignReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
};
#endif //SGXWALLET_BLSSIGNREQMSG_H
//
// Created by kladko on 15.12.20.
//
#include "ECDSASignReqMessage.h"
//
// Created by kladko on 15.12.20.
//
#ifndef SGXWALLET_ECDSASIGNREQMESSAGE_H
#define SGXWALLET_ECDSASIGNREQMESSAGE_H
#include "ZMQMessage.h"
class ECDSASignReqMessage : public ZMQMessage {
public:
ECDSASignReqMessage(shared_ptr <rapidjson::Document> &_d) : ZMQMessage(_d) {};
};
#endif //SGXWALLET_ECDSASIGNREQMESSAGE_H
......@@ -23,9 +23,12 @@
#include "common.h"
#include "BLSSignReqMessage.h"
#include "ECDSASignReqMessage.h"
#include "ZMQMessage.h"
uint64_t ZMQMessage::getUint64Rapid(const char *_name) {
CHECK_STATE(_name);
CHECK_STATE(d->HasMember(_name));
......@@ -52,6 +55,20 @@ shared_ptr<ZMQMessage> ZMQMessage::parse(vector<uint8_t>& _msg) {
CHECK_STATE(!d->HasParseError());
CHECK_STATE(d->IsObject())
CHECK_STATE(d->HasMember("type"));
CHECK_STATE((*d)["type"].IsString());
auto type = (*d)["type"].GetString();
shared_ptr<ZMQMessage> result;
if (type == ZMQMessage::BLS_SIGN_REQ) {
result = make_shared<BLSSignReqMessage>(d);
} else if (type == ZMQMessage::ECDSA_SIGN_REQ) {
result = make_shared<ECDSASignReqMessage>(d);
} else {
throw SGXException(-301, "Incorrect zmq message type: " + string(type));
}
return make_shared<ZMQMessage>(d);
}
......@@ -24,28 +24,34 @@
#pragma once
#include "document.h"
#include "SGXException.h"
using namespace std;
class ZMQMessage {
shared_ptr<rapidjson::Document> d;
shared_ptr <rapidjson::Document> d;
static constexpr const char *BLS_SIGN_REQ = "BLSSignReq";
static constexpr const char *BLS_SIGN_RSP = "BLSSignRsp";
static constexpr const char *ECDSA_SIGN_REQ = "ECDSASignReq";
static constexpr const char *ECDSA_SIGN_RSP = "ECDSASignRsp";
protected:
public:
explicit ZMQMessage(shared_ptr<rapidjson::Document>& _d) : d(_d) {};
public:
explicit ZMQMessage(shared_ptr <rapidjson::Document> &_d) : d(_d) {
};
string getStringRapid(const char *_name);
uint64_t getUint64Rapid(const char *_name);
static shared_ptr<ZMQMessage> parse(vector<uint8_t>& _msg);
static shared_ptr <ZMQMessage> parse(vector <uint8_t> &_msg);
};
\ No newline at end of file
......@@ -38,6 +38,7 @@ using namespace std;
#include <gmp.h>
#include "secure_enclave/Verify.h"
#include "InvalidStateException.h"
#include "SGXException.h"
#define SAFE_FREE(__POINTER__) {if (__POINTER__) {free(__POINTER__); __POINTER__ = NULL;}}
......@@ -73,7 +74,7 @@ inline void print_stack() {
if (!(_EXPRESSION_)) { \
auto __msg__ = std::string("State check failed::") + #_EXPRESSION_ + " " + std::string(__FILE__) + ":" + std::to_string(__LINE__); \
print_stack(); \
throw InvalidStateException(__msg__, __CLASS_NAME__);}
BOOST_THROW_EXCEPTION(SGXException(-100, string(__CLASS_NAME__) + ":" + __msg__));}
#define HANDLE_TRUSTED_FUNCTION_ERROR(__STATUS__, __ERR_STATUS__, __ERR_MSG__) \
......@@ -82,7 +83,7 @@ string __ERR_STRING__ = string("SGX enclave call to ") + \
__FUNCTION__ + " failed with status:" \
+ to_string(__STATUS__) + \
" Err message:" + __ERR_MSG__; \
BOOST_THROW_EXCEPTION(runtime_error(__ERR_MSG__)); \
BOOST_THROW_EXCEPTION(SGXException(-102, string(__ERR_MSG__))); \
}\
\
if (__ERR_STATUS__ != 0) {\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment