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

Side by Side Diff: base/nonce.cc

Issue 2333443002: Add base::UnguessableToken (Closed)
Patch Set: Addressed comments. Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
(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 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
OLDNEW
« base/nonce.h ('K') | « base/nonce.h ('k') | base/nonce_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698