Skip to content

Commit 9d5f88a

Browse files
committed
Simplify with keyword-only arguments
1 parent 9ea1e3a commit 9d5f88a

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

lib/Crypto/Protocol/HPKE.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import IntEnum
33

44
from types import ModuleType
5-
from typing import Optional, TypedDict, NotRequired, Unpack
5+
from typing import Optional
66

77
from .KDF import _HKDF_extract, _HKDF_expand
88
from .DH import key_agreement, import_x25519_public_key, import_x448_public_key
@@ -363,16 +363,12 @@ def unseal(self, ciphertext: bytes, auth_data: Optional[bytes] = None):
363363
return pt
364364

365365

366-
class RequestParams(TypedDict):
367-
enc: NotRequired[bytes]
368-
sender_key: NotRequired[EccKey]
369-
psk: NotRequired[tuple[bytes, bytes]]
370-
info: NotRequired[bytes]
371-
372-
373-
def new(receiver_key: EccKey,
366+
def new(*, receiver_key: EccKey,
374367
aead_id: AEAD,
375-
**kwargs: Unpack[RequestParams]):
368+
enc: Optional[bytes] = None,
369+
sender_key: Optional[EccKey] = None,
370+
psk: Optional[tuple[bytes, bytes]] = None,
371+
info: bytes = b''):
376372
"""Create an HPKE context which can be used
377373
by the sender to seal (encrypt) a message
378374
or by the receiver to unseal (decrypt) it.
@@ -440,14 +436,6 @@ def new(receiver_key: EccKey,
440436
.. _HPKE: https://datatracker.ietf.org/doc/rfc9180/
441437
"""
442438

443-
sender_key = kwargs.pop('sender_key', None)
444-
psk = kwargs.pop('psk', None)
445-
info = kwargs.pop('info', b'')
446-
enc = kwargs.pop('enc', None)
447-
448-
if kwargs:
449-
raise ValueError(f"Unknown parameters: {list(kwargs.keys())}")
450-
451439
if aead_id not in AEAD:
452440
raise ValueError(f"Unknown AEAD cipher ID {aead_id:#x}")
453441

lib/Crypto/SelfTest/Protocol/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_tests(config={}):
3333
from Crypto.SelfTest.Protocol import test_SecretSharing
3434
tests += test_SecretSharing.get_tests(config=config)
3535

36-
if sys.version_info >= (3, 11):
36+
if sys.version_info >= (3, 9):
3737
from Crypto.SelfTest.Protocol import test_HPKE
3838
tests += test_HPKE.get_tests(config=config)
3939

0 commit comments

Comments
 (0)