2022-02-15 19:11:53 +09:00
|
|
|
from anonstream.utils.chat import create_message, NonceReuse
|
2022-02-13 13:00:10 +09:00
|
|
|
|
2022-02-15 19:11:53 +09:00
|
|
|
class Malformed(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def parse_websocket_data(message_ids, secret, receipt):
|
2022-02-13 13:00:10 +09:00
|
|
|
if not isinstance(receipt, dict):
|
2022-02-15 19:11:53 +09:00
|
|
|
raise Malformed('not a json object')
|
2022-02-13 13:00:10 +09:00
|
|
|
|
2022-02-15 19:11:53 +09:00
|
|
|
comment = receipt.get('comment')
|
|
|
|
if not isinstance(comment, str):
|
|
|
|
raise Malformed('malformed comment')
|
2022-02-13 13:00:10 +09:00
|
|
|
|
|
|
|
nonce = receipt.get('nonce')
|
|
|
|
if not isinstance(nonce, str):
|
2022-02-15 19:11:53 +09:00
|
|
|
raise Malformed('malformed nonce')
|
2022-02-13 13:00:10 +09:00
|
|
|
|
2022-02-15 19:11:53 +09:00
|
|
|
try:
|
|
|
|
message = create_message(message_ids, secret, nonce, comment)
|
|
|
|
except NonceReuse:
|
|
|
|
raise Malformed('nonce already used')
|
2022-02-13 13:00:10 +09:00
|
|
|
|
2022-02-15 19:11:53 +09:00
|
|
|
return message
|