Skip to content

Commit 8a68519

Browse files
author
Vinit Kumar
authored
fix: use SystemRandom as a secure way for generating Random Integers (#156)
* fix: use SystemRandom as a secure way for generating Random Integers * fix: move all module level imports to the top * fix: isort issues
1 parent 96f3b09 commit 8a68519

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

json2xml/dicttoxml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
import numbers
1717
import os
1818
from collections.abc import Callable, Sequence
19-
from random import randint
19+
from random import SystemRandom
2020
from typing import Any, Dict, Union
2121

2222
from defusedxml.minidom import parseString
2323

24+
safe_random = SystemRandom()
2425
DEBUGMODE = os.getenv("DEBUGMODE", False) # pragma: no cover
2526
LOG = logging.getLogger("dicttoxml") # pragma: no cover
2627

2728

2829
def make_id(element: str, start: int = 100000, end: int = 999999) -> str:
2930
"""Returns a random integer"""
30-
return f"{element}_{randint(start, end)}"
31+
return f"{element}_{safe_random.randint(start, end)}"
3132

3233

3334
def get_unique_id(element: str) -> str:

0 commit comments

Comments
 (0)