[M85 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / base / unguessable_token.cc
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/unguessable_token.h"
6
7 #include <ostream>
8
9 #include "base/format_macros.h"
10 #include "base/no_destructor.h"
11 #include "base/rand_util.h"
12 #include "base/strings/stringprintf.h"
13
14 namespace base {
15
16 UnguessableToken::UnguessableToken(const base::Token& token) : token_(token) {}
17
18 // static
19 UnguessableToken UnguessableToken::Create() {
20   return UnguessableToken(Token::CreateRandom());
21 }
22
23 // static
24 const UnguessableToken& UnguessableToken::Null() {
25   static const NoDestructor<UnguessableToken> null_token;
26   return *null_token;
27 }
28
29 // static
30 UnguessableToken UnguessableToken::Deserialize(uint64_t high, uint64_t low) {
31   // Receiving a zeroed out UnguessableToken from another process means that it
32   // was never initialized via Create(). Treat this case as a security issue.
33   DCHECK(!(high == 0 && low == 0));
34   return UnguessableToken(Token{high, low});
35 }
36
37 std::ostream& operator<<(std::ostream& out, const UnguessableToken& token) {
38   return out << "(" << token.ToString() << ")";
39 }
40
41 }  // namespace base