Index: base/nonce.cc |
diff --git a/base/nonce.cc b/base/nonce.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7e7991891f8a24e31d31acff0e4622322cbdd0db |
--- /dev/null |
+++ b/base/nonce.cc |
@@ -0,0 +1,35 @@ |
+// Copyright 2016 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 "base/nonce.h" |
+ |
+#include "base/format_macros.h" |
+#include "base/rand_util.h" |
+#include "base/strings/stringprintf.h" |
+ |
+namespace base { |
+ |
+Nonce::Nonce() : high_(0), low_(0) {} |
+ |
+Nonce::Nonce(uint64_t high, uint64_t low) : high_(high), low_(low) {} |
+ |
+std::string Nonce::ToString() const { |
+ return base::StringPrintf("(%" PRIu64 ":%" PRIu64 ")", high_, low_); |
+} |
+ |
+// Static |
Ken Rockot(use gerrit already)
2016/09/13 23:21:13
nit: lowercase
|
+Nonce Nonce::Generate() { |
+ Nonce nonce; |
+ // Use base::RandBytes instead of crypto::RandBytes, because crypto calls the |
+ // base version directly, and to prevent the dependency from base/ to crypto/. |
+ base::RandBytes(&nonce, sizeof(nonce)); |
+ return nonce; |
+} |
+ |
+// Static |
+Nonce Nonce::Deserialize(uint64_t high, uint64_t low) { |
+ return Nonce(high, low); |
+} |
+ |
+} // namespace base |