Files
rippled/Random_8cpp_source.html
2020-12-05 06:17:37 +00:00

150 lines
16 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>rippled: Random.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">rippled
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_df9c78dcf3f59a33b12284f95992a64b.html">ripple</a></li><li class="navelem"><a class="el" href="dir_f4afb74df24474efa0cc7e8ea3ddd5ce.html">rpc</a></li><li class="navelem"><a class="el" href="dir_72652aacd0eb4ee32af795650dd02b37.html">handlers</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Random.cpp</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">//------------------------------------------------------------------------------</span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment">/*</span></div>
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment"> This file is part of rippled: https://github.com/ripple/rippled</span></div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment"> Copyright (c) 2012-2014 Ripple Labs Inc.</span></div>
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="comment"></span> </div>
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="comment"> Permission to use, copy, modify, and/or distribute this software for any</span></div>
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="comment"> purpose with or without fee is hereby granted, provided that the above</span></div>
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="comment"> copyright notice and this permission notice appear in all copies.</span></div>
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="comment"></span> </div>
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;<span class="comment"> THE SOFTWARE IS PROVIDED &quot;AS IS&quot; AND THE AUTHOR DISCLAIMS ALL WARRANTIES</span></div>
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="comment"> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF</span></div>
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="comment"> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR</span></div>
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;<span class="comment"> ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES</span></div>
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="comment"> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN</span></div>
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="comment"> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF</span></div>
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="comment"> OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</span></div>
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;<span class="comment">*/</span></div>
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="comment">//==============================================================================</span></div>
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160; </div>
<div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="preprocessor">#include &lt;ripple/basics/base_uint.h&gt;</span></div>
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="preprocessor">#include &lt;ripple/beast/utility/rngfill.h&gt;</span></div>
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;<span class="preprocessor">#include &lt;ripple/crypto/csprng.h&gt;</span></div>
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="preprocessor">#include &lt;ripple/json/json_value.h&gt;</span></div>
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="preprocessor">#include &lt;ripple/net/RPCErr.h&gt;</span></div>
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="preprocessor">#include &lt;ripple/protocol/ErrorCodes.h&gt;</span></div>
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="preprocessor">#include &lt;ripple/protocol/jss.h&gt;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160; </div>
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceripple.html">ripple</a> {</div>
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160; </div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160;<span class="keyword">namespace </span>RPC {</div>
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160;<span class="keyword">struct </span>JsonContext;</div>
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;}</div>
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160; </div>
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;<span class="comment">// Result:</span></div>
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160;<span class="comment">// {</span></div>
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160;<span class="comment">// random: &lt;uint256&gt;</span></div>
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;<span class="comment">// }</span></div>
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160;<a class="code" href="classJson_1_1Value.html">Json::Value</a></div>
<div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="namespaceripple.html#a8d8b456b90badc34e0e52979f6364842"> 39</a></span>&#160;<a class="code" href="namespaceripple.html#a8d8b456b90badc34e0e52979f6364842">doRandom</a>(<a class="code" href="structripple_1_1RPC_1_1JsonContext.html">RPC::JsonContext</a>&amp; context)</div>
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;{</div>
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160; <span class="comment">// TODO(tom): the try/catch is almost certainly redundant, we catch at the</span></div>
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; <span class="comment">// top level too.</span></div>
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; <span class="keywordflow">try</span></div>
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160; {</div>
<div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160; <a class="code" href="classripple_1_1base__uint.html">uint256</a> rand;</div>
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160; <a class="code" href="namespacebeast.html#a6894f6dcd09bceda3986ebb1ea7a3eed">beast::rngfill</a>(rand.begin(), rand.size(), <a class="code" href="namespaceripple.html#a64faabbdff83da8b7fd7aaafbb937867">crypto_prng</a>());</div>
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160; </div>
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160; <a class="code" href="classJson_1_1Value.html">Json::Value</a> jvResult;</div>
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; jvResult[jss::random] = <a class="code" href="namespaceripple.html#a96888695e8d79474e080c334f149e30a">to_string</a>(rand);</div>
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; <span class="keywordflow">return</span> jvResult;</div>
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; }</div>
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160; <span class="keywordflow">catch</span> (<a class="codeRef" href="http://en.cppreference.com/w/cpp/error/exception.html">std::exception</a> <span class="keyword">const</span>&amp;)</div>
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; {</div>
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160; <span class="keywordflow">return</span> <a class="code" href="namespaceripple.html#ab114d40490d1a6a0ab2fa6053167d461">rpcError</a>(<a class="code" href="namespaceripple.html#a32d6d3ce1a48272b677d2c88b1d30932a839833d48b635d8df6a9176274ae922f">rpcINTERNAL</a>);</div>
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160; }</div>
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;}</div>
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; </div>
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160;} <span class="comment">// namespace ripple</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="astructripple_1_1RPC_1_1JsonContext_html"><div class="ttname"><a href="structripple_1_1RPC_1_1JsonContext.html">ripple::RPC::JsonContext</a></div><div class="ttdef"><b>Definition:</b> <a href="Context_8h_source.html#l00053">Context.h:53</a></div></div>
<div class="ttc" id="aexception_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/error/exception.html">std::exception</a></div><div class="ttdoc">STL class.</div></div>
<div class="ttc" id="anamespaceripple_html_a64faabbdff83da8b7fd7aaafbb937867"><div class="ttname"><a href="namespaceripple.html#a64faabbdff83da8b7fd7aaafbb937867">ripple::crypto_prng</a></div><div class="ttdeci">csprng_engine &amp; crypto_prng()</div><div class="ttdoc">The default cryptographically secure PRNG.</div><div class="ttdef"><b>Definition:</b> <a href="csprng_8cpp_source.html#l00108">csprng.cpp:108</a></div></div>
<div class="ttc" id="anamespaceripple_html_a96888695e8d79474e080c334f149e30a"><div class="ttname"><a href="namespaceripple.html#a96888695e8d79474e080c334f149e30a">ripple::to_string</a></div><div class="ttdeci">std::string to_string(ListDisposition disposition)</div><div class="ttdef"><b>Definition:</b> <a href="ValidatorList_8cpp_source.html#l00042">ValidatorList.cpp:42</a></div></div>
<div class="ttc" id="aclassripple_1_1base__uint_html"><div class="ttname"><a href="classripple_1_1base__uint.html">ripple::base_uint</a></div><div class="ttdoc">Integers of any length that is a multiple of 32-bits.</div><div class="ttdef"><b>Definition:</b> <a href="base__uint_8h_source.html#l00073">base_uint.h:73</a></div></div>
<div class="ttc" id="anamespaceripple_html_a8d8b456b90badc34e0e52979f6364842"><div class="ttname"><a href="namespaceripple.html#a8d8b456b90badc34e0e52979f6364842">ripple::doRandom</a></div><div class="ttdeci">Json::Value doRandom(RPC::JsonContext &amp;)</div><div class="ttdef"><b>Definition:</b> <a href="Random_8cpp_source.html#l00039">Random.cpp:39</a></div></div>
<div class="ttc" id="anamespaceripple_html_ab114d40490d1a6a0ab2fa6053167d461"><div class="ttname"><a href="namespaceripple.html#ab114d40490d1a6a0ab2fa6053167d461">ripple::rpcError</a></div><div class="ttdeci">Json::Value rpcError(int iError, Json::Value jvResult)</div><div class="ttdef"><b>Definition:</b> <a href="RPCErr_8cpp_source.html#l00029">RPCErr.cpp:29</a></div></div>
<div class="ttc" id="anamespaceripple_html_a32d6d3ce1a48272b677d2c88b1d30932a839833d48b635d8df6a9176274ae922f"><div class="ttname"><a href="namespaceripple.html#a32d6d3ce1a48272b677d2c88b1d30932a839833d48b635d8df6a9176274ae922f">ripple::rpcINTERNAL</a></div><div class="ttdeci">@ rpcINTERNAL</div><div class="ttdef"><b>Definition:</b> <a href="ErrorCodes_8h_source.html#l00130">ErrorCodes.h:130</a></div></div>
<div class="ttc" id="anamespaceripple_html"><div class="ttname"><a href="namespaceripple.html">ripple</a></div><div class="ttdoc">Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.</div><div class="ttdef"><b>Definition:</b> <a href="RCLCensorshipDetector_8h_source.html#l00029">RCLCensorshipDetector.h:29</a></div></div>
<div class="ttc" id="anamespacebeast_html_a6894f6dcd09bceda3986ebb1ea7a3eed"><div class="ttname"><a href="namespacebeast.html#a6894f6dcd09bceda3986ebb1ea7a3eed">beast::rngfill</a></div><div class="ttdeci">void rngfill(void *buffer, std::size_t bytes, Generator &amp;g)</div><div class="ttdef"><b>Definition:</b> <a href="rngfill_8h_source.html#l00032">rngfill.h:32</a></div></div>
<div class="ttc" id="aclassJson_1_1Value_html"><div class="ttname"><a href="classJson_1_1Value.html">Json::Value</a></div><div class="ttdoc">Represents a JSON value.</div><div class="ttdef"><b>Definition:</b> <a href="json__value_8h_source.html#l00145">json_value.h:145</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>