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(uint64_t high, uint64_t low) : high_(high), low_(low) {} | |
14 | |
15 std::string Nonce::ToString() const { | |
16 return base::StringPrintf("(%" PRIu64 ":%" PRIu64 ")", high_, low_); | |
17 } | |
18 | |
19 // Static | |
20 Nonce Nonce::Generate() { | |
21 Nonce nonce; | |
22 // Use base::RandBytes instead of crypto::RandBytes, because crypto calls the | |
23 // base version directly, and to prevent the dependency from base/ to crypto/. | |
24 base::RandBytes(&nonce, sizeof(nonce)); | |
Avi (use Gerrit)
2016/09/13 20:28:38
This potentially could scribble across padding. Al
tguilbert
2016/09/13 21:11:44
Since I have removed the call to memcpy and send t
| |
25 return nonce; | |
26 } | |
27 | |
28 // Static | |
29 Nonce Nonce::Deserialize(uint64_t high, uint64_t low) { | |
30 return Nonce(high, low); | |
31 } | |
32 | |
33 } // namespace base | |
OLD | NEW |