Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: third_party/WebKit/Source/wtf/CryptographicallyRandomNumber.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 1996, David Mazieres <dm@uun.org> 2 * Copyright (c) 1996, David Mazieres <dm@uun.org>
3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
4 * 4 *
5 * Permission to use, copy, modify, and distribute this software for any 5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above 6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies. 7 * copyright notice and this permission notice appear in all copies.
8 * 8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */ 16 */
17 17
18 #include "wtf/CryptographicallyRandomNumber.h" 18 #include "wtf/CryptographicallyRandomNumber.h"
19 19
20 #include "base/rand_util.h" 20 #include "base/rand_util.h"
21 #include <string.h> 21 #include <string.h>
22 22
23 namespace WTF { 23 namespace WTF {
24 24
25 static bool s_shouldUseAlwaysZeroRandomSourceForTesting = false; 25 static bool s_shouldUseAlwaysZeroRandomSourceForTesting = false;
26 26
27 void setAlwaysZeroRandomSourceForTesting() 27 void setAlwaysZeroRandomSourceForTesting() {
28 { 28 s_shouldUseAlwaysZeroRandomSourceForTesting = true;
29 s_shouldUseAlwaysZeroRandomSourceForTesting = true;
30 } 29 }
31 30
32 uint32_t cryptographicallyRandomNumber() 31 uint32_t cryptographicallyRandomNumber() {
33 { 32 uint32_t result;
34 uint32_t result; 33 cryptographicallyRandomValues(&result, sizeof(result));
35 cryptographicallyRandomValues(&result, sizeof(result)); 34 return result;
36 return result;
37 } 35 }
38 36
39 void cryptographicallyRandomValues(void* buffer, size_t length) 37 void cryptographicallyRandomValues(void* buffer, size_t length) {
40 { 38 if (s_shouldUseAlwaysZeroRandomSourceForTesting) {
41 if (s_shouldUseAlwaysZeroRandomSourceForTesting) { 39 memset(buffer, '\0', length);
42 memset(buffer, '\0', length); 40 return;
43 return; 41 }
44 }
45 42
46 // This should really be crypto::RandBytes(), but WTF can't depend on crypto . The implementation of 43 // This should really be crypto::RandBytes(), but WTF can't depend on crypto. The implementation of
47 // crypto::RandBytes() is just calling base::RandBytes(), so both are actual ly same. 44 // crypto::RandBytes() is just calling base::RandBytes(), so both are actually same.
48 base::RandBytes(buffer, length); 45 base::RandBytes(buffer, length);
49 } 46 }
50
51 } 47 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/CryptographicallyRandomNumber.h ('k') | third_party/WebKit/Source/wtf/CurrentTime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698