|
reSIProcate/rutil
9694
|
00001 #include <cstdlib> 00002 #include <iostream> 00003 #include <set> 00004 00005 #include "rutil/Data.hxx" 00006 #include "rutil/Random.hxx" 00007 00008 using namespace std; 00009 using namespace resip; 00010 00011 int main(int argc, char** argv) 00012 { 00013 int runs = 1000; 00014 int length = 8; 00015 00016 if(argc == 3) 00017 { 00018 runs = atoi(argv[1]); 00019 length = atoi(argv[2]); 00020 } 00021 00022 //Random::initialize(); 00023 00024 if (runs <= 0 || length <= 0) 00025 { 00026 cerr << "usage: testRandomHex number_of_tries string_length" << endl 00027 << "number_of_tries and string_length must be a positive integers." << endl; 00028 exit(-1); 00029 } 00030 00031 cerr << "Generating " << runs << " random " << length << " byte strings and checking for uniqueness." << endl; 00032 00033 set<Data> randomDatas; 00034 00035 for (int i = 0; i < runs; i++) 00036 { 00037 Data foo = Random::getRandomHex(length/2); 00038 cerr << foo << endl; 00039 if (randomDatas.insert(foo).second == false) 00040 { 00041 cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl; 00042 exit(-1); 00043 } 00044 } 00045 00046 cerr << endl << "Now doing crypto random" << endl; 00047 00048 for (int i = 0; i < runs; i++) 00049 { 00050 Data foo = Random::getCryptoRandomHex(length/2); 00051 cerr << foo << endl; 00052 if (randomDatas.insert(foo).second == false) 00053 { 00054 cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl; 00055 exit(-1); 00056 } 00057 } 00058 00059 cerr << "Success." << endl; 00060 return 0; 00061 } 00062 00063 00064 /* ==================================================================== 00065 * The Vovida Software License, Version 1.0 00066 * 00067 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00068 * 00069 * Redistribution and use in source and binary forms, with or without 00070 * modification, are permitted provided that the following conditions 00071 * are met: 00072 * 00073 * 1. Redistributions of source code must retain the above copyright 00074 * notice, this list of conditions and the following disclaimer. 00075 * 00076 * 2. Redistributions in binary form must reproduce the above copyright 00077 * notice, this list of conditions and the following disclaimer in 00078 * the documentation and/or other materials provided with the 00079 * distribution. 00080 * 00081 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00082 * and "Vovida Open Communication Application Library (VOCAL)" must 00083 * not be used to endorse or promote products derived from this 00084 * software without prior written permission. For written 00085 * permission, please contact vocal@vovida.org. 00086 * 00087 * 4. Products derived from this software may not be called "VOCAL", nor 00088 * may "VOCAL" appear in their name, without prior written 00089 * permission of Vovida Networks, Inc. 00090 * 00091 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00092 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00093 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00094 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00095 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00096 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00097 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00098 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00099 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00100 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00101 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00102 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00103 * DAMAGE. 00104 * 00105 * ==================================================================== 00106 * 00107 * This software consists of voluntary contributions made by Vovida 00108 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00109 * Inc. For more information on Vovida Networks, Inc., please see 00110 * <http://www.vovida.org/>. 00111 * 00112 */
1.7.5.1