Commit 1f3b3e2f authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Add base::UnguessableToken::Null() helper.

Provide a global constant for a null unguessable token, for functions
that need to return a const base::UnguessableToken&.

Change-Id: Ib07dde7862dcab19baac409eaecda3482cfc5f4d
Reviewed-on: https://chromium-review.googlesource.com/1162986Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580761}
parent f8d545d6
......@@ -5,6 +5,7 @@
#include "base/unguessable_token.h"
#include "base/format_macros.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
......@@ -26,6 +27,12 @@ UnguessableToken UnguessableToken::Create() {
return token;
}
// static
const UnguessableToken& UnguessableToken::Null() {
static const NoDestructor<UnguessableToken> null_token;
return *null_token;
}
// static
UnguessableToken UnguessableToken::Deserialize(uint64_t high, uint64_t low) {
// Receiving a zeroed out UnguessableToken from another process means that it
......
......@@ -42,6 +42,12 @@ class BASE_EXPORT UnguessableToken {
// Create a unique UnguessableToken.
static UnguessableToken Create();
// Returns a reference to a global null UnguessableToken. This should only be
// used for functions that need to return a reference to an UnguessableToken,
// and should not be used as a general-purpose substitute for invoking the
// default constructor.
static const UnguessableToken& Null();
// Return a UnguessableToken built from the high/low bytes provided.
// It should only be used in deserialization scenarios.
//
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment