aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorHubert Chathi <hubertc@matrix.org>2020-09-24 18:56:19 +0000
committerHubert Chathi <hubertc@matrix.org>2020-09-24 18:56:19 +0000
commit0e6ec3062dbb7c7d571313921b6b5ee6c48bf9b3 (patch)
tree77ef25d4c416ce0ea89acb36baeabcb0595be27a /python
parentec5ff1e032868d5bce9dd36b0e549928dc7ebe36 (diff)
remove other_key checks from Python binding since it's done in C now
Diffstat (limited to 'python')
-rw-r--r--python/olm/sas.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/python/olm/sas.py b/python/olm/sas.py
index bea1dd0..cf2a443 100644
--- a/python/olm/sas.py
+++ b/python/olm/sas.py
@@ -42,16 +42,6 @@ from ._compat import URANDOM, to_bytearray, to_bytes
from ._finalize import track_for_finalization
-def other_pubkey_set(func):
- """Ensure that the other pubkey is added to the Sas object."""
- @wraps(func)
- def wrapper(self, *args, **kwargs):
- if not self.other_key_set:
- raise OlmSasError("The other public key isn't set.")
- return func(self, *args, **kwargs)
- return wrapper
-
-
def _clear_sas(sas):
# type: (ffi.cdata) -> None
lib.olm_clear_sas(sas)
@@ -73,16 +63,11 @@ class Sas(object):
key is necesary to generate bytes for the authentication string
as well as to calculate the MAC.
- Attributes:
- other_key_set (bool): A boolean flag that tracks if we set the
- other users public key for this SAS object.
-
Raises OlmSasError on failure.
"""
self._buf = ffi.new("char[]", lib.olm_sas_size())
self._sas = lib.olm_sas(self._buf)
- self.other_key_set = False
track_for_finalization(self, self._sas, _clear_sas)
random_length = lib.olm_create_sas_random_length(self._sas)
@@ -132,6 +117,13 @@ class Sas(object):
return bytes_to_native_str(ffi.unpack(pubkey_buffer, pubkey_length))
+ @property
+ def other_key_set(self):
+ # type: () -> bool
+ """Check if the other user's pubkey has been set.
+ """
+ return lib.olm_sas_is_their_key_set(self._sas) == 1
+
def set_their_pubkey(self, key):
# type: (str) -> None
"""Set the public key of the other user.
@@ -155,9 +147,7 @@ class Sas(object):
len(byte_key)
)
)
- self.other_key_set = True
- @other_pubkey_set
def generate_bytes(self, extra_info, length):
# type: (str, int) -> bytes
"""Generate bytes to use for the short authentication string.
@@ -189,7 +179,6 @@ class Sas(object):
return ffi.unpack(out_buffer, length)
- @other_pubkey_set
def calculate_mac(self, message, extra_info):
# type: (str, str) -> str
"""Generate a message authentication code based on the shared secret.
@@ -221,7 +210,6 @@ class Sas(object):
)
return bytes_to_native_str(ffi.unpack(mac_buffer, mac_length))
- @other_pubkey_set
def calculate_mac_long_kdf(self, message, extra_info):
# type: (str, str) -> str
"""Generate a message authentication code based on the shared secret.