123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #ifndef BASE_UNGUESSABLE_TOKEN_H_
- #define BASE_UNGUESSABLE_TOKEN_H_
- #include <stdint.h>
- #include <string.h>
- #include <iosfwd>
- #include <tuple>
- #include "base/base_export.h"
- #include "base/check.h"
- #include "base/hash/hash.h"
- #include "base/token.h"
- namespace base {
- struct UnguessableTokenHash;
- class BASE_EXPORT UnguessableToken {
- public:
-
- static UnguessableToken Create();
-
-
-
-
- static const UnguessableToken& Null();
-
-
-
-
-
- static UnguessableToken Deserialize(uint64_t high, uint64_t low);
-
-
- constexpr UnguessableToken() = default;
- constexpr UnguessableToken(const UnguessableToken&) = default;
- constexpr UnguessableToken& operator=(const UnguessableToken&) = default;
- constexpr UnguessableToken(UnguessableToken&&) noexcept = default;
- constexpr UnguessableToken& operator=(UnguessableToken&&) = default;
-
- uint64_t GetHighForSerialization() const {
- DCHECK(!is_empty());
- return token_.high();
- }
-
- uint64_t GetLowForSerialization() const {
- DCHECK(!is_empty());
- return token_.low();
- }
- constexpr bool is_empty() const { return token_.is_zero(); }
-
- std::string ToString() const { return token_.ToString(); }
- explicit constexpr operator bool() const { return !is_empty(); }
- constexpr bool operator<(const UnguessableToken& other) const {
- return token_ < other.token_;
- }
- constexpr bool operator==(const UnguessableToken& other) const {
- return token_ == other.token_;
- }
- constexpr bool operator!=(const UnguessableToken& other) const {
- return !(*this == other);
- }
- private:
- friend struct UnguessableTokenHash;
- explicit UnguessableToken(const Token& token);
- base::Token token_;
- };
- BASE_EXPORT std::ostream& operator<<(std::ostream& out,
- const UnguessableToken& token);
- struct UnguessableTokenHash {
- size_t operator()(const base::UnguessableToken& token) const {
- DCHECK(token);
- return TokenHash()(token.token_);
- }
- };
- }
- #endif
|