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

Unified Diff: net/quic/crypto/quic_random.cc

Issue 11476031: Add the QuicRandom interface with a default implementation that is (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Export QuicRandom for net_unittesrs Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/crypto/quic_random.h ('k') | net/quic/crypto/quic_random_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/crypto/quic_random.cc
===================================================================
--- net/quic/crypto/quic_random.cc (revision 0)
+++ net/quic/crypto/quic_random.cc (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/crypto/quic_random.h"
+
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "crypto/random.h"
+
+namespace net {
+
+namespace {
+
+class DefaultRandom : public QuicRandom {
+ public:
+ static DefaultRandom* GetInstance();
+
+ // QuicRandom implementation
+ virtual void RandBytes(void* data, size_t len);
+ virtual uint64 RandUint64();
+ virtual void Reseed(const void* additional_entropy, size_t entropy_len);
+
+ private:
+ DefaultRandom();
+ virtual ~DefaultRandom() {}
+
+ friend struct DefaultSingletonTraits<DefaultRandom>;
+ DISALLOW_COPY_AND_ASSIGN(DefaultRandom);
+};
+
+DefaultRandom* DefaultRandom::GetInstance() {
+ return Singleton<DefaultRandom>::get();
+}
+
+void DefaultRandom::RandBytes(void* data, size_t len) {
+ crypto::RandBytes(data, len);
+}
+
+uint64 DefaultRandom::RandUint64() {
+ uint64 value;
+ RandBytes(&value, sizeof(value));
+ return value;
+}
+
+void DefaultRandom::Reseed(const void* additional_entropy, size_t entropy_len) {
+ // No such function exists in crypto/random.h.
+}
+
+DefaultRandom::DefaultRandom() {
+}
+
+} // namespace
+
+// static
+QuicRandom* QuicRandom::GetInstance() {
+ return DefaultRandom::GetInstance();
+}
+
+} // namespace net
Property changes on: net/quic/crypto/quic_random.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « net/quic/crypto/quic_random.h ('k') | net/quic/crypto/quic_random_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698