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_token.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 NonceToken::NonceToken(uint64_t high, uint64_t low) : high_(high), low_(low) {} |
| 14 |
| 15 std::string NonceToken::ToString() const { |
| 16 return base::StringPrintf("(%" PRIu64 ":%" PRIu64 ")", high_, low_); |
| 17 } |
| 18 |
| 19 // static |
| 20 NonceToken NonceToken::Create() { |
| 21 NonceToken token; |
| 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(&token, sizeof(token)); |
| 25 return token; |
| 26 } |
| 27 |
| 28 void NonceToken::Serialize(uint64_t* high_out, uint64_t* low_out) const { |
| 29 // Serializing an uninitialized NonceToken is a security issue. |
| 30 CHECK(!is_empty()); |
| 31 *high_out = high_; |
| 32 *low_out = low_; |
| 33 } |
| 34 |
| 35 // static |
| 36 NonceToken NonceToken::Deserialize(uint64_t high, uint64_t low) { |
| 37 // Sending a zeroed out NonceToken across processes means that it was never |
| 38 // initialized via NonceToken::Create(), which is a security issue. |
| 39 CHECK(!NonceToken::IsZeroData(high, low)); |
| 40 return NonceToken(high, low); |
| 41 } |
| 42 |
| 43 } // namespace base |
OLD | NEW |