getEntropy

fnEntropyResult getEntropy(scope void[] buffer) @safe

Retrieves random data from an applicable system CSPRNG.

Parameters

bufferAn output buffer to store the retrieved entropy in. The length of it will determine the amount of random data to be obtained. This function (and all overloads) always attempt to fill the entire buffer. Therefore, they can block, spin or report an error.

Returns

An EntropyResult that either reports success

or the type of error that has occurred.

In case of an error, the data in buffer MUST NOT be used. The recommended way to check for success is through the isOK() helper function.

fnEntropyResult getEntropy(scope ubyte[] buffer) @safe

ditto

fnEntropyResult getEntropy(scope void * buffer, size_t length) @system

ditto Retrieves random data from an applicable system CSPRNG.

Parameters

bufferAn output buffer to store the retrieved entropy in.
lengthLength of the provided buffer. Specifying a wrong value here, will lead to memory corruption.

Returns

An EntropyResult that either reports success

or the type of error that has occurred.

In case of an error, the data in buffer MUST NOT be used. The recommended way to check for success is through the isOK() helper function.

fnEntropyResult getEntropy(scope void * buffer, size_t length, EntropySource source) @system

Retrieves random data from the requested entropy source.

In general, it’s a bad idea to let users pick sources themselves. A sane option should be used by default instead.

This overload only exists because its used by Phobos.

See_also: Use forceEntropySource instead.

Parameters

bufferAn output buffer to store the retrieved entropy in. The length of it will determine the amount of entropy to be obtained.
lengthLength of the provided buffer. Specifying a wrong value here, will lead to memory corruption.
sourceThe entropy source to use for the operation.

Returns

An EntropyResult that either reports success

or the type of error that has occurred.

In case of an error, the data in buffer MUST NOT be used. The recommended way to check for success is through the isOK() helper function.