Improve RPC random.

This commit is contained in:
Arthur Britto
2012-12-04 23:56:05 -08:00
parent be243d5d34
commit 61596f0717
3 changed files with 18 additions and 4 deletions

View File

@@ -47,6 +47,7 @@ Json::Value rpcError(int iError, Json::Value jvResult)
{ rpcNO_PATH, "noPath", "Unable to find a ripple path." }, { rpcNO_PATH, "noPath", "Unable to find a ripple path." },
{ rpcNO_PERMISSION, "noPermission", "You don't have permission for this command." }, { rpcNO_PERMISSION, "noPermission", "You don't have permission for this command." },
{ rpcNOT_STANDALONE, "notStandAlone", "Operation valid in debug mode only." }, { rpcNOT_STANDALONE, "notStandAlone", "Operation valid in debug mode only." },
{ rpcNOT_SUPPORTED, "notSupported", "Operation not supported." },
{ rpcPASSWD_CHANGED, "passwdChanged", "Wrong key, password changed." }, { rpcPASSWD_CHANGED, "passwdChanged", "Wrong key, password changed." },
{ rpcPAYS_ACT_MALFORMED, "paysActMalformed", "Pays account malformed." }, { rpcPAYS_ACT_MALFORMED, "paysActMalformed", "Pays account malformed." },
{ rpcPAYS_AMT_MALFORMED, "paysAmtMalformed", "Pays amount malformed." }, { rpcPAYS_AMT_MALFORMED, "paysAmtMalformed", "Pays amount malformed." },

View File

@@ -67,6 +67,7 @@ enum {
rpcINTERNAL, // Generic internal error. rpcINTERNAL, // Generic internal error.
rpcFAIL_GEN_DECRPYT, rpcFAIL_GEN_DECRPYT,
rpcNOT_IMPL, rpcNOT_IMPL,
rpcNOT_SUPPORTED,
rpcNO_GEN_DECRPYT, rpcNO_GEN_DECRPYT,
}; };

View File

@@ -697,14 +697,26 @@ Json::Value RPCHandler::doRandom(Json::Value jvRequest)
{ {
uint160 uRandom; uint160 uRandom;
RAND_bytes(uRandom.begin(), uRandom.size()); switch (RAND_pseudo_bytes(uRandom.begin(), uRandom.size()))
{
case 0:
case 1:
{
Json::Value jvResult; Json::Value jvResult;
jvResult["random"] = uRandom.ToString(); jvResult["random"] = uRandom.ToString();
return jvResult; return jvResult;
} }
break;
case -1:
return rpcError(rpcNOT_SUPPORTED);
default:
return rpcError(rpcINTERNAL);
}
}
// TODO: // TODO:
// - Add support for specifying non-endpoint issuer. // - Add support for specifying non-endpoint issuer.