Skip to content

Commit 847a673

Browse files
rzvncjJenkins-dev
authored andcommitted
MTRand: Clean rndbytes() up
Our code pretends that `rndbytes()` returns a relevant boolean value. This patch clears that misconception up. Signed-off-by: Razvan Cojocaru <razvan.cojocaru@openvpn.com>
1 parent 5751c0b commit 847a673

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

openvpn/random/mtrandapi.hpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@ class MTRand : public WeakRandomAPI
5454
// Fill buffer with random bytes
5555
void rand_bytes(unsigned char *buf, size_t size) override
5656
{
57-
if (!rndbytes(buf, size))
58-
throw mtrand_error("rand_bytes failed");
57+
while (size--)
58+
*buf++ = rbs.get_byte(rng);
5959
}
6060

61-
// Like rand_bytes, but don't throw exception.
62-
// Return true on successs, false on fail.
61+
/**
62+
* Like rand_bytes, but don't throw exception. At least that's the
63+
* intent in the base class API. Here, neither function throws and
64+
* we always return true (success).
65+
**/
6366
bool rand_bytes_noexcept(unsigned char *buf, size_t size) override
6467
{
65-
return rndbytes(buf, size);
68+
rand_bytes(buf, size);
69+
return true;
6670
}
6771

6872
rand_type::result_type rand()
@@ -71,13 +75,6 @@ class MTRand : public WeakRandomAPI
7175
}
7276

7377
private:
74-
bool rndbytes(unsigned char *buf, size_t size)
75-
{
76-
while (size--)
77-
*buf++ = rbs.get_byte(rng);
78-
return true;
79-
}
80-
8178
static rand_type::result_type gen_seed(RandomAPI &seed)
8279
{
8380
return seed.rand_get<rand_type::result_type>();

0 commit comments

Comments
 (0)