From 942b004af9dd1823a8bb8358719f070320a04444 Mon Sep 17 00:00:00 2001 From: RinZ27 <222222878+RinZ27@users.noreply.github.com> Date: Sat, 21 Mar 2026 19:46:11 +0700 Subject: [PATCH] Fix NameError in PQDH when handling invalid algorithms --- asyncssh/crypto/pq.py | 2 +- tests/test_kex.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/asyncssh/crypto/pq.py b/asyncssh/crypto/pq.py index bf24503..142f6fa 100644 --- a/asyncssh/crypto/pq.py +++ b/asyncssh/crypto/pq.py @@ -59,7 +59,7 @@ def __init__(self, alg_name: bytes): self.ciphertext_bytes, self.secret_bytes, \ oqs_name = _pq_algs[alg_name] except KeyError: # pragma: no cover, other algs not registered - raise ValueError(f'Unknown PQ algorithm {oqs_name}') from None + raise ValueError(f'Unknown PQ algorithm {alg_name.decode()}') from None if not hasattr(_oqs, 'OQS_' + oqs_name + '_keypair'): # pragma: no cover oqs_name += '_ipd' diff --git a/tests/test_kex.py b/tests/test_kex.py index 01d8a19..273489b 100644 --- a/tests/test_kex.py +++ b/tests/test_kex.py @@ -650,3 +650,9 @@ async def test_rsa_errors(self): client_conn.close() server_conn.close() + + def test_invalid_pq_alg(self): + """Test providing an invalid PQ algorithm""" + + with self.assertRaisesRegex(ValueError, 'Unknown PQ algorithm invalid'): + PQDH(b'invalid')