OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/crypto/quic_random.h" | 5 #include "net/quic/crypto/quic_random.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" |
8 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
9 #include "crypto/random.h" | 10 #include "crypto/random.h" |
10 | 11 |
11 namespace net { | 12 namespace net { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 class DefaultRandom : public QuicRandom { | 16 class DefaultRandom : public QuicRandom { |
16 public: | 17 public: |
17 static DefaultRandom* GetInstance(); | 18 static DefaultRandom* GetInstance(); |
18 | 19 |
19 // QuicRandom implementation | 20 // QuicRandom implementation |
20 void RandBytes(void* data, size_t len) override; | 21 void RandBytes(void* data, size_t len) override; |
21 uint64 RandUint64() override; | 22 uint64_t RandUint64() override; |
22 void Reseed(const void* additional_entropy, size_t entropy_len) override; | 23 void Reseed(const void* additional_entropy, size_t entropy_len) override; |
23 | 24 |
24 private: | 25 private: |
25 DefaultRandom() {} | 26 DefaultRandom() {} |
26 ~DefaultRandom() override {} | 27 ~DefaultRandom() override {} |
27 | 28 |
28 friend struct base::DefaultSingletonTraits<DefaultRandom>; | 29 friend struct base::DefaultSingletonTraits<DefaultRandom>; |
29 DISALLOW_COPY_AND_ASSIGN(DefaultRandom); | 30 DISALLOW_COPY_AND_ASSIGN(DefaultRandom); |
30 }; | 31 }; |
31 | 32 |
32 DefaultRandom* DefaultRandom::GetInstance() { | 33 DefaultRandom* DefaultRandom::GetInstance() { |
33 return base::Singleton<DefaultRandom>::get(); | 34 return base::Singleton<DefaultRandom>::get(); |
34 } | 35 } |
35 | 36 |
36 void DefaultRandom::RandBytes(void* data, size_t len) { | 37 void DefaultRandom::RandBytes(void* data, size_t len) { |
37 crypto::RandBytes(data, len); | 38 crypto::RandBytes(data, len); |
38 } | 39 } |
39 | 40 |
40 uint64 DefaultRandom::RandUint64() { | 41 uint64_t DefaultRandom::RandUint64() { |
41 uint64 value; | 42 uint64_t value; |
42 RandBytes(&value, sizeof(value)); | 43 RandBytes(&value, sizeof(value)); |
43 return value; | 44 return value; |
44 } | 45 } |
45 | 46 |
46 void DefaultRandom::Reseed(const void* additional_entropy, size_t entropy_len) { | 47 void DefaultRandom::Reseed(const void* additional_entropy, size_t entropy_len) { |
47 // No such function exists in crypto/random.h. | 48 // No such function exists in crypto/random.h. |
48 } | 49 } |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 // static | 53 // static |
53 QuicRandom* QuicRandom::GetInstance() { | 54 QuicRandom* QuicRandom::GetInstance() { |
54 return DefaultRandom::GetInstance(); | 55 return DefaultRandom::GetInstance(); |
55 } | 56 } |
56 | 57 |
57 } // namespace net | 58 } // namespace net |
OLD | NEW |