diff --git a/task_module.py b/task_module.py new file mode 100644 index 0000000..0000001 --- /dev/null +++ b/task_module.py @@ -0,0 +1,20 @@ +from graphene import Scalar +from base64 import b64encode, b64decode + +class SecureToken(Scalar): + @staticmethod + def serialize(value): + if not isinstance(value, (str, bytes)): + raise TypeError("SecureToken expects string or bytes") + value = value if isinstance(value, bytes) else value.encode("utf-8") + encoded = b64encode(value).decode("utf-8") + return f"tok_{encoded}" + + @staticmethod + def parse_value(value): + if not isinstance(value, str): + raise TypeError("SecureToken expects string") + if not value.startswith("tok_"): + raise ValueError("Invalid prefix") + encoded = value[4:] + return b64decode(encoded) \ No newline at end of file