-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Description
Environment
- Python version: 3.9.22
- netutils version: 1.15.1
Expected Behavior
encrypt_cisco_type7(unencrypted_password: str, salt: t.Optional[int] = None) shall make use of the salt when their value is 0.
Observed Behavior
encrypt_cisco_type7(unencrypted_password: str, salt: t.Optional[int] = None) drops the salt when their value is 0, and randomizes a new salt between 0 and 15.
Steps to Reproduce
>>> encrypt_cisco_type7("cisco", 0)
'121A0C041104'
>>> encrypt_cisco_type7("cisco", 0)
'13061E010803'
>>> encrypt_cisco_type7("cisco", 0)
'05080F1C2243'
>>> encrypt_cisco_type7("cisco", 0)
'1511021F0725'
>>> encrypt_cisco_type7("cisco", 0)
'00071A150754'
There is a 1 on 16 chance that the salt ends up being 0.
Root cause
In netutils.password.encrypt_cisco_type7(...), the code tests for a falsy salt value and not strictly for a None value.
if not salt:
salt = random.randint(0, 15) # noqa: S311Should be:
if salt is None:
salt = random.randint(0, 15) # noqa: S311Metadata
Metadata
Assignees
Labels
No labels