Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_BASE_HELPERS_H_ | 11 #ifndef WEBRTC_BASE_HELPERS_H_ |
| 12 #define WEBRTC_BASE_HELPERS_H_ | 12 #define WEBRTC_BASE_HELPERS_H_ |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 #include "webrtc/base/basictypes.h" | 15 #include "webrtc/base/basictypes.h" |
| 16 | 16 |
| 17 namespace rtc { | 17 namespace rtc { |
| 18 | 18 |
| 19 // For testing, we can return predictable data. | 19 // For testing, we can return predictable data. |
| 20 void SetRandomTestMode(bool test); | 20 void SetRandomTestMode(bool test); |
| 21 | 21 |
| 22 // Initializes the RNG, and seeds it with the specified entropy. | 22 // Initializes the RNG, and seeds it with the specified entropy. |
| 23 bool InitRandom(int seed); | 23 bool InitRandom(int seed); |
| 24 bool InitRandom(const char* seed, size_t len); | 24 bool InitRandom(const char* seed, size_t len); |
| 25 | 25 |
| 26 // Generates a (cryptographically) random string of the given length. | 26 // Generates a (cryptographically) random string of the given length. |
| 27 // We generate base64 values so that they will be printable. | 27 // We generate base64 values so that they will be printable. |
| 28 // WARNING: could silently fail. Use the version below instead. | 28 // WARNING: will abort() if the RNG fails! Use the version below instead. |
| 29 std::string CreateRandomString(size_t length); | 29 std::string CreateRandomString(size_t length); |
| 30 | 30 |
| 31 // Generates a (cryptographically) random string of the given length. | 31 // Generates a (cryptographically) random string of the given length. |
| 32 // We generate base64 values so that they will be printable. | 32 // We generate base64 values so that they will be printable. |
| 33 // Return false if the random number generator failed. | 33 // Return false if the random number generator failed. |
| 34 bool CreateRandomString(size_t length, std::string* str); | 34 bool CreateRandomString(size_t length, std::string* str); |
| 35 | 35 |
| 36 // Generates a (cryptographically) random string of the given length, | 36 // Generates a (cryptographically) random string of the given length, |
| 37 // with characters from the given table. Return false if the random | 37 // with characters from the given table. Return false if the random |
| 38 // number generator failed. | 38 // number generator failed. |
| 39 bool CreateRandomString(size_t length, const std::string& table, | 39 bool CreateRandomString(size_t length, const std::string& table, |
| 40 std::string* str); | 40 std::string* str); |
| 41 | 41 |
| 42 // Generates a (cryptographically) random UUID version 4 string. | 42 // Generates a (cryptographically) random UUID version 4 string. |
| 43 // WARNING: will abort() if the RNG fails! Use the version below instead. | |
|
mattdr-at-webrtc.org
2016/07/01 23:57:39
Suggest removing these warnings. The RNG will almo
joachim
2016/07/02 00:12:01
Done.
| |
| 43 std::string CreateRandomUuid(); | 44 std::string CreateRandomUuid(); |
| 44 | 45 |
| 46 // Generates a (cryptographically) random UUID version 4 string. | |
| 47 bool CreateRandomUuid(std::string* uuid); | |
|
mattdr-at-webrtc.org
2016/07/01 23:57:39
Likewise, no need to increase the surface area by
joachim
2016/07/02 00:12:01
Done.
| |
| 48 | |
| 45 // Generates a random id. | 49 // Generates a random id. |
| 50 // WARNING: will abort() if the RNG fails! Use the version below instead. | |
| 46 uint32_t CreateRandomId(); | 51 uint32_t CreateRandomId(); |
| 47 | 52 |
| 53 // Generates a random id. | |
| 54 bool CreateRandomId(uint32_t* id); | |
| 55 | |
| 48 // Generates a 64 bit random id. | 56 // Generates a 64 bit random id. |
| 57 // WARNING: will abort() if the RNG fails! Use the version below instead. | |
| 49 uint64_t CreateRandomId64(); | 58 uint64_t CreateRandomId64(); |
| 50 | 59 |
| 60 // Generates a 64 bit random id. | |
| 61 bool CreateRandomId64(uint64_t* id); | |
| 62 | |
| 51 // Generates a random id > 0. | 63 // Generates a random id > 0. |
| 64 // WARNING: will abort() if the RNG fails! Use the version below instead. | |
| 52 uint32_t CreateRandomNonZeroId(); | 65 uint32_t CreateRandomNonZeroId(); |
| 53 | 66 |
| 67 // Generates a random id > 0. | |
| 68 bool CreateRandomNonZeroId(uint32_t* id); | |
| 69 | |
| 54 // Generates a random double between 0.0 (inclusive) and 1.0 (exclusive). | 70 // Generates a random double between 0.0 (inclusive) and 1.0 (exclusive). |
| 71 // WARNING: will abort() if the RNG fails! Use the version below instead. | |
| 55 double CreateRandomDouble(); | 72 double CreateRandomDouble(); |
| 56 | 73 |
| 74 // Generates a random double between 0.0 (inclusive) and 1.0 (exclusive). | |
| 75 bool CreateRandomDouble(double* value); | |
| 76 | |
| 57 } // namespace rtc | 77 } // namespace rtc |
| 58 | 78 |
| 59 #endif // WEBRTC_BASE_HELPERS_H_ | 79 #endif // WEBRTC_BASE_HELPERS_H_ |
| OLD | NEW |