QHashSeed Struct

头: #include <QHashSeed>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Since: Qt 6.2

公共函数

QHashSeed (size_t data = 0)
size_t operator size_t () const

静态公共成员

QHashSeed globalSeed ()
void resetRandomGlobalSeed ()
void setDeterministicGlobalSeed ()

详细描述

The QHashSeed class is used to convey the QHash seed. This is used internally by QHash and provides three static member functions to allow users to obtain the hash and to reset it.

QHash and the qHash() functions implement what is called as "salted hash". The intent is that different applications and different instances of the same application will produce different hashing values for the same input, thus causing the ordering of elements in QHash to be unpredictable by external observers. This improves the applications' resilience against attacks that attempt to force hashing tables into degenerate mode.

Most applications will not need to deal directly with the hash seed, as QHash will do so when needed. However, applications may wish to use this for their own purposes in the same way as QHash does: as an application-global random value (but see QRandomGenerator too). Note that the global hash seed may change during the application's lifetime, if the resetRandomGlobalSeed () function is called. Users of the global hash need to store the value they are using and not rely on getting it again.

This class also implements functionality to set the hash seed to a deterministic value, which the qHash() functions will take to mean that they should use a fixed hashing function on their data too. This functionality is only meant to be used in debugging applications. This behavior can also be controlled by setting the QT_HASH_SEED environment variable to the value zero (any other value is ignored).

另请参阅 QHash and QRandomGenerator .

成员函数文档编制

[constexpr] QHashSeed:: QHashSeed ( size_t data = 0)

Constructs a new QHashSeed object using data as the seed.

[static] QHashSeed QHashSeed:: globalSeed ()

Returns the current global QHash seed. The value returned by this function will be zero if setDeterministicGlobalSeed () has been called or if the QT_HASH_SEED environment variable is set to zero.

注意: 此函数是 thread-safe .

[static] void QHashSeed:: resetRandomGlobalSeed ()

Reseeds the Qt hashing seed to a new, random value. Calling this function is not necessary, but long-running applications may want to do so after a long period of time in which information about its hash may have been exposed to potential attackers.

If the environment variable QT_HASH_SEED is set to zero, calling this function will result in a no-op.

Qt never calls this function during the execution of the application, but unless the QT_HASH_SEED variable is set to 0, the hash seed returned by globalSeed () will be a random value as if this function had been called.

注意: 此函数是 thread-safe .

[static] void QHashSeed:: setDeterministicGlobalSeed ()

Forces the Qt hash seed to a deterministic value (zero) and asks the qHash() functions to use a pre-determined hashing function. This mode is only useful for debugging and should not be used in production code.

Regular operation can be restored by calling resetRandomGlobalSeed ().

注意: 此函数是 thread-safe .

[constexpr] size_t QHashSeed:: operator size_t () const

Converts the returned hash seed into a size_t .