annotate sat/core/core_types.py @ 3911:8289ac1b34f4

plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo: - support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace - maintains one identity across both versions of OMEMO - migrates data from the old plugin - includes more features for protocol stability - uses SCE for modern OMEMO - fully type-checked, linted and format-checked - added type hints to various pieces of backend code used by the plugin - added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy) - core (xmpp): enabled `send` trigger and made it an asyncPoint fix 375
author Syndace <me@syndace.dev>
date Tue, 23 Aug 2022 21:06:24 +0200
parents 722a38e78fd1
children 5a42c7842556
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
2
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia types
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
5
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
10
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
15
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
18
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
19 from collections import namedtuple
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
20 from typing import Dict
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
21 from typing_extensions import TypedDict
3679
b02fb5fcaa30 core (core_types): add `jid` to `SatXMPPEntity`
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
22 from twisted.words.protocols.jabber import jid as t_jid
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
23 from twisted.words.xish import domish
3679
b02fb5fcaa30 core (core_types): add `jid` to `SatXMPPEntity`
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
24
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
25
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
26 class SatXMPPEntity:
3679
b02fb5fcaa30 core (core_types): add `jid` to `SatXMPPEntity`
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
27
b02fb5fcaa30 core (core_types): add `jid` to `SatXMPPEntity`
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
28 jid: t_jid.JID
3812
722a38e78fd1 core (types): add `is_component` to `SatXMPPEntity`
Goffi <goffi@goffi.org>
parents: 3679
diff changeset
29 is_component: bool
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
30
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
31
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
32 EncryptionPlugin = namedtuple("EncryptionPlugin", ("instance",
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
33 "name",
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
34 "namespace",
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
35 "priority",
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
36 "directed"))
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
37
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
38
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
39 class EncryptionSession(TypedDict):
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
40 plugin: EncryptionPlugin
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
41
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
42
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
43 # Incomplete types built through observation rather than code inspection.
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
44 MessageDataExtra = TypedDict(
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
45 "MessageDataExtra",
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
46 { "encrypted": bool, "origin_id": str },
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
47 total=False
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
48 )
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
49
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
50
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
51 MessageData = TypedDict("MessageData", {
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
52 "from": t_jid.JID,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
53 "to": t_jid.JID,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
54 "uid": str,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
55 "message": Dict[str, str],
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
56 "subject": Dict[str, str],
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
57 "type": str,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
58 "timestamp": float,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
59 "extra": MessageDataExtra,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
60 "ENCRYPTION": EncryptionSession,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
61 "xml": domish.Element
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3812
diff changeset
62 }, total=False)