Adding exceptions

parent 9a071923
......@@ -10,6 +10,9 @@
#include <exception>
class RPCException : public std::exception {
public:
int32_t status;
std::string errString;
......
......@@ -18,9 +18,9 @@
#include <stdio.h>
#include "SGXWalletServer.h"
#include "RPCException.h"
#include "LevelDB.h"
#include "SGXWalletServer.h"
......@@ -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,
......@@ -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 result;
result["status"] = 0;
result["errorMessage"] = "";
result["encryptedKeyShare"] = "";
try {
checkKeyShareDoesNotExist(keyShare);
} catch (RPCException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
return result;
}
Json::Value SGXWalletServer::blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash) {
......@@ -112,6 +135,17 @@ Json::Value SGXWalletServer::blsSignMessageHash(const std::string& keyShareName,
result["status"] = 0;
result["errorMessage"] = "";
result["signatureShare"] = "";
try {
checkKeyShareDoesExist(keyShareName);
} catch (RPCException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
return result;
}
......@@ -123,20 +157,53 @@ Json::Value SGXWalletServer::importECDSAKey(const std::string& key, const std::s
return result;
}
Json::Value SGXWalletServer::generateECDSAKey(const std::string& keyName) {
Json::Value SGXWalletServer::generateECDSAKey(const std::string& _keyName) {
Json::Value result;
result["status"] = 0;
result["errorMessage"] = "";
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;
result["status"] = 0;
result["errorMessage"] = "";
result["signature"] = "";
try {
checkECDSAKeyDoesExist(_keyShareName);
} catch (RPCException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
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