// UnguessableToken is, like Token, a randomly chosen 128-bit value. Unlike // Token, a new UnguessableToken is always generated at runtime from a // cryptographically strong random source (or copied or serialized and // deserialized from another such UnguessableToken). Also unlike Token, the == // and != operators are constant time. It can be used as part of a larger // aggregate type, or as an ID in and of itself. // // An UnguessableToken is a strong *bearer token*. Bearer tokens are like HTTP // cookies: if a caller has the token, the callee thereby considers the caller // authorized to request the operation the callee performs. // // UnguessableToken can be used when the resource associated with the ID needs // to be protected against manipulation by other untrusted agents in the system, // and there is no other convenient way to verify the authority of the agent to // do so (because the resource is part of a table shared across processes, for // instance). In such a scheme, knowledge of the token value in and of itself is // sufficient proof of authority to carry out an operation on the associated // resource. // // Use Create() for creating new UnguessableTokens. // // NOTE: It is illegal to send empty UnguessableTokens across processes, and // sending/receiving empty tokens should be treated as a security issue. If // there is a valid scenario for sending "no token" across processes, use // absl::optional instead of an empty token.
class BASE_EXPORT UnguessableToken {
public: // Create a unique UnguessableToken. It's guaranteed to be nonempty. 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. staticconst UnguessableToken& Null();
// Return an UnguessableToken built from the high/low bytes provided. // It should only be used in deserialization scenarios. // // NOTE: If the returned `absl::optional` does not have a value, it means that // `high` and `low` correspond to an `UnguesssableToken` that was never // initialized via Create(). This is a security issue, and should be handled. static absl::optional<UnguessableToken> Deserialize(uint64_t high,
uint64_t low);
// Creates an empty UnguessableToken. // Assign to it with Create() before using it.
constexpr UnguessableToken() = default;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.