Skip to content

Commit 77b4e2f

Browse files
committed
adds gaurd clause for the hmac verification implementation
1 parent f25ec12 commit 77b4e2f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

apimatic_core/security/hmac_signature_verifier.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, key: str, signature_header: str):
2525
raise ValueError("HMAC verification requires a non-empty key.")
2626
if not signature_header:
2727
raise ValueError("signature_header must be a non-empty string.")
28+
2829
self._key = key
2930
self._signature_header = signature_header.lower()
3031

@@ -40,8 +41,14 @@ def verify(self, headers: Mapping[str, str], payload: str) -> bool:
4041
bool: True if the computed HMAC matches the provided signature.
4142
4243
Raises:
44+
TypeError: If input types are invalid.
4345
ValueError: If the signature header is missing.
4446
"""
47+
if headers is None or not hasattr(headers, "items"):
48+
raise TypeError("headers must be a Mapping[str, str]")
49+
if payload is None or not isinstance(payload, str):
50+
raise TypeError("payload must be a str containing raw JSON")
51+
4552
normalized = {k.lower(): v for k, v in headers.items()}
4653
provided = normalized.get(self._signature_header)
4754
if not provided:

0 commit comments

Comments
 (0)