1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
from abc import ABC, abstractmethod
from typing import FrozenSet, NamedTuple, Optional, Tuple
__all__ = [
"Content",
"EncryptedKeyMaterial",
"KeyExchange",
"Message",
"PlainKeyMaterial"
]
class Content(ABC):
"""
The encrypted content of an OMEMO-encrypted message. Contains for example the ciphertext, but can contain
other backend-specific data that is shared between all recipients.
"""
@property
@abstractmethod
def empty(self) -> bool:
"""
Returns:
Whether this instance corresponds to an empty OMEMO message purely used for protocol stability
reasons.
"""
class PlainKeyMaterial(ABC):
"""
Key material which be used to decrypt the content. Defails are backend-specific.
"""
class EncryptedKeyMaterial(ABC):
"""
Encrypted key material. When decrypted, the key material can in turn be used to decrypt the content. One
collection of key material is included in an OMEMO-encrypted message per recipient. Defails are
backend-specific.
"""
@property
@abstractmethod
def bare_jid(self) -> str:
pass
@property
@abstractmethod
def device_id(self) -> int:
pass
class KeyExchange(ABC):
"""
Key exchange information, generated by the active part of the session building process, then transferred
to and consumed by the passive part of the session building process. Details are backend-specific.
"""
@property
@abstractmethod
def identity_key(self) -> bytes:
pass
@abstractmethod
def builds_same_session(self, other: "KeyExchange") -> bool:
"""
Args:
other: The other key exchange instance to compare to this instance.
Returns:
Whether the key exchange information stored in this instance and the key exchange information
stored in the other instance would build the same session.
"""
class Message(NamedTuple):
# pylint: disable=invalid-name
"""
Simple structure representing an OMEMO-encrypted message.
"""
namespace: str
bare_jid: str
device_id: int
content: Content
keys: FrozenSet[Tuple[EncryptedKeyMaterial, Optional[KeyExchange]]]
|