Adding exceptions

parent 9a071923
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include <exception> #include <exception>
class RPCException : public std::exception { class RPCException : public std::exception {
public:
int32_t status; int32_t status;
std::string errString; std::string errString;
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#include <stdio.h> #include <stdio.h>
#include "SGXWalletServer.h" #include "RPCException.h"
#include "LevelDB.h" #include "LevelDB.h"
#include "SGXWalletServer.h"
...@@ -49,6 +49,17 @@ public: ...@@ -49,6 +49,17 @@ public:
void checkKeyShareDoesExist(const string& _keyShare);
void checkKeyShareDoesNotExist(const string& _keyShare);
void checkECDSAKeyDoesExist(const string& _keyShare);
void checkECDSAKeyDoesNotExist(const string& _keyShare);
}; };
SGXWalletServer::SGXWalletServer(AbstractServerConnector &connector, SGXWalletServer::SGXWalletServer(AbstractServerConnector &connector,
...@@ -102,9 +113,21 @@ int init_server() { ...@@ -102,9 +113,21 @@ int init_server() {
Json::Value SGXWalletServer::importBLSKeyShare(int index, const std::string& keyShare, const std::string& keyShareName, int n, int t) { Json::Value SGXWalletServer::importBLSKeyShare(int index, const std::string& keyShare, const std::string& keyShareName, int n, int t) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
result["encryptedKeyShare"] = ""; result["encryptedKeyShare"] = "";
try {
checkKeyShareDoesNotExist(keyShare);
} catch (RPCException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
return result; return result;
} }
Json::Value SGXWalletServer::blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash) { Json::Value SGXWalletServer::blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash) {
...@@ -112,6 +135,17 @@ Json::Value SGXWalletServer::blsSignMessageHash(const std::string& keyShareName, ...@@ -112,6 +135,17 @@ Json::Value SGXWalletServer::blsSignMessageHash(const std::string& keyShareName,
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
result["signatureShare"] = ""; result["signatureShare"] = "";
try {
checkKeyShareDoesExist(keyShareName);
} catch (RPCException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
return result; return result;
} }
...@@ -123,20 +157,53 @@ Json::Value SGXWalletServer::importECDSAKey(const std::string& key, const std::s ...@@ -123,20 +157,53 @@ Json::Value SGXWalletServer::importECDSAKey(const std::string& key, const std::s
return result; return result;
} }
Json::Value SGXWalletServer::generateECDSAKey(const std::string& keyName) { Json::Value SGXWalletServer::generateECDSAKey(const std::string& _keyName) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
result["encryptedKey"] = ""; result["encryptedKey"] = "";
try {
checkECDSAKeyDoesNotExist(_keyName);
} catch (RPCException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
} }
Json::Value SGXWalletServer::ecdsaSignMessageHash(const std::string& keyShareName, const std::string& messageHash) { Json::Value SGXWalletServer::ecdsaSignMessageHash(const std::string& _keyShareName, const std::string& messageHash) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
result["signature"] = ""; result["signature"] = "";
try {
checkECDSAKeyDoesExist(_keyShareName);
} catch (RPCException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
return result; return result;
} }
void SGXWalletServer::checkKeyShareDoesExist(const string& _keyShare) {
}
void SGXWalletServer::checkKeyShareDoesNotExist(const string& _keyShare) {
}
void SGXWalletServer::checkECDSAKeyDoesExist(const string& _keyShare) {
}
void SGXWalletServer::checkECDSAKeyDoesNotExist(const string& _keyShare) {
}
\ No newline at end of file
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