mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
refactor: possible FTBFS fix on arm7 (#4492)
* refactor: possible FTBFS fix on arm7 * chore: remove tr_rand_int_weak() from crypto-test-ref * refactor: move tr_rand_int() to header
This commit is contained in:
@@ -31,23 +31,6 @@ using namespace std::literals;
|
|||||||
|
|
||||||
///
|
///
|
||||||
|
|
||||||
template<class T>
|
|
||||||
[[nodiscard]] T tr_rand_int(T upper_bound)
|
|
||||||
{
|
|
||||||
static_assert(!std::is_signed<T>());
|
|
||||||
TR_ASSERT(upper_bound > std::numeric_limits<T>::min());
|
|
||||||
|
|
||||||
using dist_type = std::uniform_int_distribution<T>;
|
|
||||||
thread_local auto rng = tr_urbg<T>{};
|
|
||||||
thread_local auto dist = dist_type{};
|
|
||||||
return dist(rng, typename dist_type::param_type(0, upper_bound - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
template size_t tr_rand_int(size_t upper_bound);
|
|
||||||
template unsigned int tr_rand_int(unsigned int upper_bound);
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
namespace ssha1_impl
|
namespace ssha1_impl
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <random> // for std::uniform_int_distribution<T>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
@@ -87,12 +88,6 @@ tr_x509_cert_t tr_x509_cert_new(void const* der, size_t der_length);
|
|||||||
*/
|
*/
|
||||||
void tr_x509_cert_free(tr_x509_cert_t handle);
|
void tr_x509_cert_free(tr_x509_cert_t handle);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns a random number in the range of [0...upper_bound).
|
|
||||||
*/
|
|
||||||
template<class IntType>
|
|
||||||
[[nodiscard]] IntType tr_rand_int(IntType upper_bound);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fill a buffer with random bytes.
|
* @brief Fill a buffer with random bytes.
|
||||||
*/
|
*/
|
||||||
@@ -212,6 +207,20 @@ private:
|
|||||||
tr_salt_shaker<T, N> buf_;
|
tr_salt_shaker<T, N> buf_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a random number in the range of [0...upper_bound).
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
[[nodiscard]] T tr_rand_int(T upper_bound)
|
||||||
|
{
|
||||||
|
static_assert(!std::is_signed<T>());
|
||||||
|
using dist_type = std::uniform_int_distribution<T>;
|
||||||
|
|
||||||
|
thread_local auto rng = tr_urbg<T>{};
|
||||||
|
thread_local auto dist = dist_type{};
|
||||||
|
return dist(rng, typename dist_type::param_type(0, upper_bound - 1));
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* TR_CRYPTO_UTILS_H */
|
#endif /* TR_CRYPTO_UTILS_H */
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#define tr_rand_buffer_crypto tr_rand_buffer_crypto_
|
#define tr_rand_buffer_crypto tr_rand_buffer_crypto_
|
||||||
#define tr_rand_buffer_std tr_rand_buffer_std_
|
#define tr_rand_buffer_std tr_rand_buffer_std_
|
||||||
#define tr_rand_int tr_rand_int_
|
#define tr_rand_int tr_rand_int_
|
||||||
#define tr_rand_int_weak tr_rand_int_weak_
|
|
||||||
#define tr_rand_obj tr_rand_obj_
|
#define tr_rand_obj tr_rand_obj_
|
||||||
#define tr_salt_shaker tr_salt_shaker_
|
#define tr_salt_shaker tr_salt_shaker_
|
||||||
#define tr_sha1 tr_sha1_
|
#define tr_sha1 tr_sha1_
|
||||||
@@ -54,7 +53,6 @@
|
|||||||
#undef tr_rand_buffer_crypto
|
#undef tr_rand_buffer_crypto
|
||||||
#undef tr_rand_buffer_std
|
#undef tr_rand_buffer_std
|
||||||
#undef tr_rand_int
|
#undef tr_rand_int
|
||||||
#undef tr_rand_int_weak
|
|
||||||
#undef tr_rand_obj
|
#undef tr_rand_obj
|
||||||
#undef tr_salt_shaker
|
#undef tr_salt_shaker
|
||||||
#undef tr_sha1
|
#undef tr_sha1
|
||||||
@@ -85,7 +83,6 @@
|
|||||||
#define tr_rand_buffer_crypto_ tr_rand_buffer_crypto
|
#define tr_rand_buffer_crypto_ tr_rand_buffer_crypto
|
||||||
#define tr_rand_buffer_std_ tr_rand_buffer_std
|
#define tr_rand_buffer_std_ tr_rand_buffer_std
|
||||||
#define tr_rand_int_ tr_rand_int
|
#define tr_rand_int_ tr_rand_int
|
||||||
#define tr_rand_int_weak_ tr_rand_int_weak
|
|
||||||
#define tr_rand_obj_ tr_rand_obj
|
#define tr_rand_obj_ tr_rand_obj
|
||||||
#define tr_salt_shaker_ tr_salt_shaker
|
#define tr_salt_shaker_ tr_salt_shaker
|
||||||
#define tr_sha1_ tr_sha1
|
#define tr_sha1_ tr_sha1
|
||||||
|
|||||||
Reference in New Issue
Block a user