Raise an exception when the payload is not of the form we expect
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
94e3a62d8a
commit
957b555d93
1 changed files with 10 additions and 0 deletions
|
@ -170,6 +170,10 @@ class UndecidedException(XEP0384):
|
||||||
self.ik = ik
|
self.ik = ik
|
||||||
|
|
||||||
|
|
||||||
|
class ErroneousPayload(XEP0384):
|
||||||
|
"""To be raised when the payload is not of the form we expect"""
|
||||||
|
|
||||||
|
|
||||||
class XEP_0384(BasePlugin):
|
class XEP_0384(BasePlugin):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -512,6 +516,8 @@ class XEP_0384(BasePlugin):
|
||||||
allow_untrusted: bool = False,
|
allow_untrusted: bool = False,
|
||||||
) -> Optional[str]:
|
) -> Optional[str]:
|
||||||
header = encrypted['header']
|
header = encrypted['header']
|
||||||
|
if encrypted['payload']['value'] is None:
|
||||||
|
raise ErroneousPayload('The payload element was empty')
|
||||||
payload = b64dec(encrypted['payload']['value'])
|
payload = b64dec(encrypted['payload']['value'])
|
||||||
|
|
||||||
jid = sender.bare
|
jid = sender.bare
|
||||||
|
@ -524,7 +530,11 @@ class XEP_0384(BasePlugin):
|
||||||
|
|
||||||
key = Key(key)
|
key = Key(key)
|
||||||
isPrekeyMessage = key['prekey'] in TRUE_VALUES
|
isPrekeyMessage = key['prekey'] in TRUE_VALUES
|
||||||
|
if key['value'] is None:
|
||||||
|
raise ErroneousPayload('The key element was empty')
|
||||||
message = b64dec(key['value'])
|
message = b64dec(key['value'])
|
||||||
|
if header['iv']['value'] is None:
|
||||||
|
raise ErroneousPayload('The iv element was empty')
|
||||||
iv = b64dec(header['iv']['value'])
|
iv = b64dec(header['iv']['value'])
|
||||||
|
|
||||||
# XXX: 'cipher' is part of KeyTransportMessages and is used when no payload
|
# XXX: 'cipher' is part of KeyTransportMessages and is used when no payload
|
||||||
|
|
Loading…
Reference in a new issue