mirror of
https://github.com/transmission/transmission.git
synced 2026-04-19 08:20:22 +01:00
refactor: add tr_rand_obj() (#4238)
* refactor: add tr_rand_obj() There are a lot of places in the codebase where we need to populate an integral type or a fixed-size array with random data. To do this, we instantiate a local on the stack, fill it with tr_rand_buffer(), and then use it. This PR creates a helper function to make this a one-liner.
This commit is contained in:
@@ -91,8 +91,7 @@ std::string tr_ssha1(std::string_view plaintext)
|
||||
auto constexpr Salter = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./"sv;
|
||||
static_assert(std::size(Salter) == 64);
|
||||
auto constexpr SaltSize = size_t{ 8 };
|
||||
auto salt = std::array<char, SaltSize>{};
|
||||
tr_rand_buffer(std::data(salt), std::size(salt));
|
||||
auto salt = tr_rand_obj<std::array<char, SaltSize>>();
|
||||
std::transform(
|
||||
std::begin(salt),
|
||||
std::end(salt),
|
||||
|
||||
Reference in New Issue
Block a user