diff --git a/autobahn/_version.py b/autobahn/_version.py index 965c97f24..c8e3a5015 100644 --- a/autobahn/_version.py +++ b/autobahn/_version.py @@ -24,6 +24,6 @@ # ############################################################################### -__version__ = '24.4.1' +__version__ = '24.4.2' __build__ = '00000000-0000000' diff --git a/autobahn/util.py b/autobahn/util.py index bfad2ed26..a66b26f28 100644 --- a/autobahn/util.py +++ b/autobahn/util.py @@ -278,13 +278,13 @@ def __next__(self): # -# 8 byte mask with 53 LSBs set (WAMP requires IDs from [0, 2**53] +# 8 byte mask with 53 LSBs set (WAMP requires IDs from [1, 2**53] _WAMP_ID_MASK = struct.unpack(">Q", b"\x00\x1f\xff\xff\xff\xff\xff\xff")[0] def rid(): """ - Generate a new random integer ID from range **[0, 2**53]**. + Generate a new random integer ID from range **[1, 2**53]**. The generated ID is uniformly distributed over the whole range, doesn't have a period (no pseudo-random generator is used) and cryptographically strong. @@ -298,13 +298,13 @@ def rid(): :returns: A random integer ID. :rtype: int """ - return struct.unpack("@Q", os.urandom(8))[0] & _WAMP_ID_MASK + return struct.unpack(">Q", os.urandom(8))[0] & _WAMP_ID_MASK or 2 ** 53 # noinspection PyShadowingBuiltins def id(): """ - Generate a new random integer ID from range **[0, 2**53]**. + Generate a new random integer ID from range **[1, 2**53]**. The generated ID is based on a pseudo-random number generator (Mersenne Twister, which has a period of 2**19937-1). It is NOT cryptographically strong, and @@ -319,7 +319,7 @@ def id(): :returns: A random integer ID. :rtype: int """ - return random.randint(0, 9007199254740992) + return random.randint(1, 9007199254740992) def newid(length=16): diff --git a/docs/changelog.rst b/docs/changelog.rst index 35681f6d7..a543df433 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,11 @@ Changelog ========= +24.4.2 +------ + +- fix: Ensure ID generator in range [1, 2 ** 53] (#1637) + 24.4.1 ------