Browse Source

util.randrange: use stdlib 'secrets' module instead of 'python-ecdsa'

patch-4
SomberNight 4 years ago
parent
commit
120da2783b
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 8
      electrum/util.py

8
electrum/util.py

@ -44,15 +44,15 @@ import ssl
import ipaddress import ipaddress
from ipaddress import IPv4Address, IPv6Address from ipaddress import IPv4Address, IPv6Address
import random import random
import attr import secrets
import attr
import aiohttp import aiohttp
from aiohttp_socks import ProxyConnector, ProxyType from aiohttp_socks import ProxyConnector, ProxyType
import aiorpcx import aiorpcx
from aiorpcx import TaskGroup from aiorpcx import TaskGroup
import certifi import certifi
import dns.resolver import dns.resolver
import ecdsa
from .i18n import _ from .i18n import _
from .logging import get_logger, Logger from .logging import get_logger, Logger
@ -1306,7 +1306,9 @@ def resolve_dns_srv(host: str):
def randrange(bound: int) -> int: def randrange(bound: int) -> int:
"""Return a random integer k such that 1 <= k < bound, uniformly """Return a random integer k such that 1 <= k < bound, uniformly
distributed across that range.""" distributed across that range."""
return ecdsa.util.randrange(bound) # secrets.randbelow(bound) returns a random int: 0 <= r < bound,
# hence transformations:
return secrets.randbelow(bound - 1) + 1
class CallbackManager: class CallbackManager:

Loading…
Cancel
Save