Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/nonce.h" | |
| 6 | |
| 7 #include "base/format_macros.h" | |
| 8 #include "base/rand_util.h" | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 | |
| 11 namespace base { | |
|
dcheng
2016/09/13 01:33:29
Nit: newlines after { here and before closing }, f
tguilbert
2016/09/13 01:50:11
Done.
| |
| 12 Nonce::Nonce(uint64_t high, uint64_t low) : high_(high), low_(low) {} | |
| 13 | |
| 14 std::string Nonce::ToString() const { | |
| 15 return base::StringPrintf("(%" PRIu64 ":%" PRIu64 ")", high_, low_); | |
| 16 } | |
| 17 | |
| 18 // Static | |
| 19 Nonce Nonce::Generate() { | |
| 20 Nonce nonce; | |
| 21 // Use base::RandBytes instead of crypto::RandBytes, because crypto calls the | |
| 22 // base version directly, and to prevent the dependency from base/ to crypto/. | |
| 23 base::RandBytes(&nonce, sizeof(nonce)); | |
| 24 return nonce; | |
| 25 } | |
| 26 | |
| 27 // Static | |
| 28 Nonce Nonce::Deserialize(uint64_t high, uint64_t low) { | |
| 29 return Nonce(high, low); | |
| 30 } | |
| 31 } // namespace base | |
| OLD | NEW |