aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd/rng.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/rng.cpp')
-rw-r--r--src/cmd/rng.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/cmd/rng.cpp b/src/cmd/rng.cpp
index b89376b4c..3fe8719ce 100644
--- a/src/cmd/rng.cpp
+++ b/src/cmd/rng.cpp
@@ -14,39 +14,41 @@
namespace {
-int rng(int argc, char* argv[])
+int rng(const std::vector<std::string> &args)
{
- if(argc == 1)
+ if(args.size() == 1)
{
- std::cout << "Usage: " << argv[0] << " [--raw-entropy] [n]" << std::endl;
+ std::cout << "Usage: " << args[0] << " [--raw-entropy] n\n"
+ << "n: number of bytes"
+ << std::endl;
return 1;
}
try
{
- const size_t amt = to_u32bit(argv[argc-1]);
- const bool raw = (argc == 3 && std::string(argv[1]) == "--raw-entropy");
+ const size_t bytes_count = to_u32bit(args.back());
+ const bool raw = (args.size() == 3 && args[1] == "--raw-entropy");
#if defined(BOTAN_HAS_SYSTEM_RNG)
- std::cout << "System " << hex_encode(system_rng().random_vec(amt)) << std::endl;
+ std::cout << "System " << hex_encode(system_rng().random_vec(bytes_count)) << std::endl;
#endif
if(!raw)
{
AutoSeeded_RNG rng;
- std::cout << hex_encode(rng.random_vec(amt)) << std::endl;
+ std::cout << hex_encode(rng.random_vec(bytes_count)) << std::endl;
}
else
{
double total_collected = 0;
Entropy_Accumulator accum(
- [amt,&total_collected](const byte in[], size_t in_len, double entropy_estimate)
+ [bytes_count,&total_collected](const byte in[], size_t in_len, double entropy_estimate)
{
std::cout << "Collected estimated "<< entropy_estimate << " bits in "
<< hex_encode(in, in_len) << std::endl;
total_collected += entropy_estimate;
- return total_collected >= amt;
+ return total_collected >= bytes_count;
});
Entropy_Sources::global_sources().poll(accum);