Skip to content

Commit

Permalink
Checker Lib: Check types of arguments in public API
Browse files Browse the repository at this point in the history
  • Loading branch information
rudis committed Sep 3, 2023
1 parent 8dfe043 commit ce8fe75
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ctf_gameserver/checkerlib/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def get_flag(tick: int) -> str:
current run. The returned flag can be used for both placement and checks.
"""

if not isinstance(tick, int):
raise TypeError('tick must be of type int')

# Return dummy flag when launched locally
if _launched_without_runner():
try:
Expand All @@ -140,6 +143,9 @@ def set_flagid(data: str) -> None:
Stores the Flag ID for the current team and tick.
"""

if not isinstance(data, str):
raise TypeError('data must be of type str')

if not _launched_without_runner():
_send_ctrl_message({'action': 'FLAGID', 'param': data})
# Wait for acknowledgement
Expand All @@ -154,6 +160,9 @@ def store_state(key: str, data: Any) -> None:
service and team with the given key as an additional identifier.
"""

if not isinstance(key, str):
raise TypeError('key must be of type str')

serialized_data = base64.b64encode(pickle.dumps(data)).decode('ascii')

if not _launched_without_runner():
Expand All @@ -178,6 +187,9 @@ def load_state(key: str) -> Any:
current service and team), None is returned.
"""

if not isinstance(key, str):
raise TypeError('key must be of type str')

if not _launched_without_runner():
_send_ctrl_message({'action': 'LOAD', 'param': key})
result = _recv_ctrl_message()
Expand Down

0 comments on commit ce8fe75

Please sign in to comment.