diff --git a/changes/741.fixed b/changes/741.fixed new file mode 100644 index 00000000..1c5c7f76 --- /dev/null +++ b/changes/741.fixed @@ -0,0 +1 @@ +Fixed the logic error where `salt=0` was ignored in `encrypt_cisco_type7` \ No newline at end of file diff --git a/netutils/password.py b/netutils/password.py index 21b6a55c..b01f1464 100644 --- a/netutils/password.py +++ b/netutils/password.py @@ -292,7 +292,7 @@ def encrypt_cisco_type7(unencrypted_password: str, salt: t.Optional[int] = None) if len(unencrypted_password) > ENCRYPT_TYPE7_LENGTH: raise ValueError("Password must not exceed 25 characters.") - if not salt: + if salt is None: salt = random.randint(0, 15) # noqa: S311 # Start building the encrypted password - pre-pend the 2 decimal digit offset. encrypted_password = format(salt, "02d") diff --git a/tests/unit/test_password.py b/tests/unit/test_password.py index 9db1895f..bd373fab 100644 --- a/tests/unit/test_password.py +++ b/tests/unit/test_password.py @@ -86,6 +86,10 @@ "sent": {"unencrypted_password": "cisco", "salt": 10}, "received": "104D000A0618", }, + { + "sent": {"unencrypted_password": "cisco", "salt": 0}, + "received": "00071A150754", + }, ] ENCRYPT_CISCO_TYPE9 = [