mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 12:14:38 +02:00
Merge pull request #728 from embray/patch-1
Fixes a serious bug in Random.byte
This commit is contained in:
@@ -46,23 +46,23 @@ class Random(object):
|
|||||||
"""
|
"""
|
||||||
Generate and return a random byte.
|
Generate and return a random byte.
|
||||||
"""
|
"""
|
||||||
result = t2b("\0")
|
result = _ffi.new('byte[1]')
|
||||||
|
|
||||||
ret = _lib.wc_RNG_GenerateByte(self.native_object, result)
|
ret = _lib.wc_RNG_GenerateByte(self.native_object, result)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
raise WolfCryptError("RNG generate byte error (%d)" % ret)
|
raise WolfCryptError("RNG generate byte error (%d)" % ret)
|
||||||
|
|
||||||
return result
|
return _ffi.buffer(result, 1)[:]
|
||||||
|
|
||||||
|
|
||||||
def bytes(self, length):
|
def bytes(self, length):
|
||||||
"""
|
"""
|
||||||
Generate and return a random sequence of length bytes.
|
Generate and return a random sequence of length bytes.
|
||||||
"""
|
"""
|
||||||
result = t2b("\0" * length)
|
result = _ffi.new('byte[%d]' % length)
|
||||||
|
|
||||||
ret = _lib.wc_RNG_GenerateBlock(self.native_object, result, length)
|
ret = _lib.wc_RNG_GenerateBlock(self.native_object, result, length)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
raise WolfCryptError("RNG generate block error (%d)" % ret)
|
raise WolfCryptError("RNG generate block error (%d)" % ret)
|
||||||
|
|
||||||
return result
|
return _ffi.buffer(result, length)[:]
|
||||||
|
Reference in New Issue
Block a user