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 { | |
12 | |
13 Nonce::Nonce() : high_(0), low_(0) {} | |
14 | |
15 Nonce::Nonce(uint64_t high, uint64_t low) : high_(high), low_(low) {} | |
16 | |
17 std::string Nonce::ToString() const { | |
18 return base::StringPrintf("(%" PRIu64 ":%" PRIu64 ")", high_, low_); | |
19 } | |
20 | |
21 // Static | |
Ken Rockot(use gerrit already)
2016/09/13 23:21:13
nit: lowercase
| |
22 Nonce Nonce::Generate() { | |
23 Nonce nonce; | |
24 // Use base::RandBytes instead of crypto::RandBytes, because crypto calls the | |
25 // base version directly, and to prevent the dependency from base/ to crypto/. | |
26 base::RandBytes(&nonce, sizeof(nonce)); | |
27 return nonce; | |
28 } | |
29 | |
30 // Static | |
31 Nonce Nonce::Deserialize(uint64_t high, uint64_t low) { | |
32 return Nonce(high, low); | |
33 } | |
34 | |
35 } // namespace base | |
OLD | NEW |