X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Frand.py;h=4bc073a1ceb63f727d6022e5586d85d577084dbf;hb=5eb6b4548beeacbd191b9c49a9b6cb7acf339837;hp=5d51eedd77fb30fc0ea3a31e2aa322a57b35e622;hpb=1ff9b1899959673512927b6afa317855908b7073;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/rand.py b/ctypescrypto/rand.py index 5d51eed..4bc073a 100644 --- a/ctypescrypto/rand.py +++ b/ctypescrypto/rand.py @@ -6,6 +6,8 @@ from ctypes import create_string_buffer, c_char_p, c_int, c_double from ctypescrypto import libcrypto from ctypescrypto.exception import LibCryptoError +__all__ = ['RandError','bytes','pseudo_bytes','seed','status'] + class RandError(LibCryptoError): pass @@ -17,11 +19,11 @@ def bytes( num, check_result=False): """ if num <= 0 : - raise ValueError, "'num' should be > 0" + raise ValueError("'num' should be > 0") buffer = create_string_buffer(num) result = libcrypto.RAND_bytes(buffer, num) if check_result and result == 0: - raise RandError, "Random Number Generator not seeded sufficiently" + raise RandError("Random Number Generator not seeded sufficiently") return buffer.raw[:num] def pseudo_bytes(num): @@ -34,7 +36,7 @@ def pseudo_bytes(num): not for key generation etc. """ if num <= 0 : - raise ValueError, "'num' should be > 0" + raise ValueError("'num' should be > 0") buffer = create_string_buffer(num) libcrypto.RAND_pseudo_bytes(buffer, num) return buffer.raw[:num] @@ -45,8 +47,8 @@ def seed(data, entropy=None): If entropy is not None, it should be floating point(double) value estimating amount of entropy in the data (in bytes). """ - if type(data) != type(""): - raise TypeError, "A string is expected" + if not isinstance(data,str): + raise TypeError("A string is expected") ptr = c_char_p(data) size = len(data) if entropy is None: