matrix-sdk-python 0.18.0a1__cp314-cp314-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1876 @@
1
+ # This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ # Trust me, you don't want to mess with it!
3
+
4
+ # Common helper code.
5
+ #
6
+ # Ideally this would live in a separate .py file where it can be unittested etc
7
+ # in isolation, and perhaps even published as a re-useable package.
8
+ #
9
+ # However, it's important that the details of how this helper code works (e.g. the
10
+ # way that different builtin types are passed across the FFI) exactly match what's
11
+ # expected by the rust code on the other side of the interface. In practice right
12
+ # now that means coming from the exact some version of `uniffi` that was used to
13
+ # compile the rust component. The easiest way to ensure this is to bundle the Python
14
+ # helpers directly inline like we're doing here.
15
+
16
+ from __future__ import annotations
17
+ import os
18
+ import sys
19
+ import ctypes
20
+ from dataclasses import dataclass
21
+ import enum
22
+ import struct
23
+ import contextlib
24
+ import datetime
25
+ import threading
26
+ import itertools
27
+ import traceback
28
+ import typing
29
+ import platform
30
+
31
+
32
+ # Used for default argument values
33
+ _DEFAULT = object() # type: typing.Any
34
+
35
+
36
+ class _UniffiRustBuffer(ctypes.Structure):
37
+ _fields_ = [
38
+ ("capacity", ctypes.c_uint64),
39
+ ("len", ctypes.c_uint64),
40
+ ("data", ctypes.POINTER(ctypes.c_char)),
41
+ ]
42
+
43
+ @staticmethod
44
+ def default():
45
+ return _UniffiRustBuffer(0, 0, None)
46
+
47
+ @staticmethod
48
+ def alloc(size):
49
+ return _uniffi_rust_call(_UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_alloc, size)
50
+
51
+ @staticmethod
52
+ def reserve(rbuf, additional):
53
+ return _uniffi_rust_call(_UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_reserve, rbuf, additional)
54
+
55
+ def free(self):
56
+ return _uniffi_rust_call(_UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_free, self)
57
+
58
+ def __str__(self):
59
+ return "_UniffiRustBuffer(capacity={}, len={}, data={})".format(
60
+ self.capacity,
61
+ self.len,
62
+ self.data[0:self.len]
63
+ )
64
+
65
+ @contextlib.contextmanager
66
+ def alloc_with_builder(*args):
67
+ """Context-manger to allocate a buffer using a _UniffiRustBufferBuilder.
68
+
69
+ The allocated buffer will be automatically freed if an error occurs, ensuring that
70
+ we don't accidentally leak it.
71
+ """
72
+ builder = _UniffiRustBufferBuilder()
73
+ try:
74
+ yield builder
75
+ except:
76
+ builder.discard()
77
+ raise
78
+
79
+ @contextlib.contextmanager
80
+ def consume_with_stream(self):
81
+ """Context-manager to consume a buffer using a _UniffiRustBufferStream.
82
+
83
+ The _UniffiRustBuffer will be freed once the context-manager exits, ensuring that we don't
84
+ leak it even if an error occurs.
85
+ """
86
+ try:
87
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
88
+ yield s
89
+ if s.remaining() != 0:
90
+ raise RuntimeError(f"junk data left in buffer at end of consume_with_stream {s.remaining()}")
91
+ finally:
92
+ self.free()
93
+
94
+ @contextlib.contextmanager
95
+ def read_with_stream(self):
96
+ """Context-manager to read a buffer using a _UniffiRustBufferStream.
97
+
98
+ This is like consume_with_stream, but doesn't free the buffer afterwards.
99
+ It should only be used with borrowed `_UniffiRustBuffer` data.
100
+ """
101
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
102
+ yield s
103
+ if s.remaining() != 0:
104
+ raise RuntimeError(f"junk data left in buffer at end of read_with_stream {s.remaining()}")
105
+
106
+ class _UniffiForeignBytes(ctypes.Structure):
107
+ _fields_ = [
108
+ ("len", ctypes.c_int32),
109
+ ("data", ctypes.POINTER(ctypes.c_char)),
110
+ ]
111
+
112
+ def __str__(self):
113
+ return "_UniffiForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len])
114
+
115
+
116
+ class _UniffiRustBufferStream:
117
+ """
118
+ Helper for structured reading of bytes from a _UniffiRustBuffer
119
+ """
120
+
121
+ def __init__(self, data, len):
122
+ self.data = data
123
+ self.len = len
124
+ self.offset = 0
125
+
126
+ @classmethod
127
+ def from_rust_buffer(cls, buf):
128
+ return cls(buf.data, buf.len)
129
+
130
+ def remaining(self):
131
+ return self.len - self.offset
132
+
133
+ def _unpack_from(self, size, format):
134
+ if self.offset + size > self.len:
135
+ raise InternalError("read past end of rust buffer")
136
+ value = struct.unpack(format, self.data[self.offset:self.offset+size])[0]
137
+ self.offset += size
138
+ return value
139
+
140
+ def read(self, size):
141
+ if self.offset + size > self.len:
142
+ raise InternalError("read past end of rust buffer")
143
+ data = self.data[self.offset:self.offset+size]
144
+ self.offset += size
145
+ return data
146
+
147
+ def read_i8(self):
148
+ return self._unpack_from(1, ">b")
149
+
150
+ def read_u8(self):
151
+ return self._unpack_from(1, ">B")
152
+
153
+ def read_i16(self):
154
+ return self._unpack_from(2, ">h")
155
+
156
+ def read_u16(self):
157
+ return self._unpack_from(2, ">H")
158
+
159
+ def read_i32(self):
160
+ return self._unpack_from(4, ">i")
161
+
162
+ def read_u32(self):
163
+ return self._unpack_from(4, ">I")
164
+
165
+ def read_i64(self):
166
+ return self._unpack_from(8, ">q")
167
+
168
+ def read_u64(self):
169
+ return self._unpack_from(8, ">Q")
170
+
171
+ def read_float(self):
172
+ v = self._unpack_from(4, ">f")
173
+ return v
174
+
175
+ def read_double(self):
176
+ return self._unpack_from(8, ">d")
177
+
178
+ class _UniffiRustBufferBuilder:
179
+ """
180
+ Helper for structured writing of bytes into a _UniffiRustBuffer.
181
+ """
182
+
183
+ def __init__(self):
184
+ self.rbuf = _UniffiRustBuffer.alloc(16)
185
+ self.rbuf.len = 0
186
+
187
+ def finalize(self):
188
+ rbuf = self.rbuf
189
+ self.rbuf = None
190
+ return rbuf
191
+
192
+ def discard(self):
193
+ if self.rbuf is not None:
194
+ rbuf = self.finalize()
195
+ rbuf.free()
196
+
197
+ @contextlib.contextmanager
198
+ def _reserve(self, num_bytes):
199
+ if self.rbuf.len + num_bytes > self.rbuf.capacity:
200
+ self.rbuf = _UniffiRustBuffer.reserve(self.rbuf, num_bytes)
201
+ yield None
202
+ self.rbuf.len += num_bytes
203
+
204
+ def _pack_into(self, size, format, value):
205
+ with self._reserve(size):
206
+ # XXX TODO: I feel like I should be able to use `struct.pack_into` here but can't figure it out.
207
+ for i, byte in enumerate(struct.pack(format, value)):
208
+ self.rbuf.data[self.rbuf.len + i] = byte
209
+
210
+ def write(self, value):
211
+ with self._reserve(len(value)):
212
+ for i, byte in enumerate(value):
213
+ self.rbuf.data[self.rbuf.len + i] = byte
214
+
215
+ def write_i8(self, v):
216
+ self._pack_into(1, ">b", v)
217
+
218
+ def write_u8(self, v):
219
+ self._pack_into(1, ">B", v)
220
+
221
+ def write_i16(self, v):
222
+ self._pack_into(2, ">h", v)
223
+
224
+ def write_u16(self, v):
225
+ self._pack_into(2, ">H", v)
226
+
227
+ def write_i32(self, v):
228
+ self._pack_into(4, ">i", v)
229
+
230
+ def write_u32(self, v):
231
+ self._pack_into(4, ">I", v)
232
+
233
+ def write_i64(self, v):
234
+ self._pack_into(8, ">q", v)
235
+
236
+ def write_u64(self, v):
237
+ self._pack_into(8, ">Q", v)
238
+
239
+ def write_float(self, v):
240
+ self._pack_into(4, ">f", v)
241
+
242
+ def write_double(self, v):
243
+ self._pack_into(8, ">d", v)
244
+
245
+ def write_c_size_t(self, v):
246
+ self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v)
247
+ # A handful of classes and functions to support the generated data structures.
248
+ # This would be a good candidate for isolating in its own ffi-support lib.
249
+
250
+ class InternalError(Exception):
251
+ pass
252
+
253
+ class _UniffiRustCallStatus(ctypes.Structure):
254
+ """
255
+ Error runtime.
256
+ """
257
+ _fields_ = [
258
+ ("code", ctypes.c_int8),
259
+ ("error_buf", _UniffiRustBuffer),
260
+ ]
261
+
262
+ # These match the values from the uniffi::rustcalls module
263
+ CALL_SUCCESS = 0
264
+ CALL_ERROR = 1
265
+ CALL_UNEXPECTED_ERROR = 2
266
+
267
+ @staticmethod
268
+ def default():
269
+ return _UniffiRustCallStatus(code=_UniffiRustCallStatus.CALL_SUCCESS, error_buf=_UniffiRustBuffer.default())
270
+
271
+ def __str__(self):
272
+ if self.code == _UniffiRustCallStatus.CALL_SUCCESS:
273
+ return "_UniffiRustCallStatus(CALL_SUCCESS)"
274
+ elif self.code == _UniffiRustCallStatus.CALL_ERROR:
275
+ return "_UniffiRustCallStatus(CALL_ERROR)"
276
+ elif self.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
277
+ return "_UniffiRustCallStatus(CALL_UNEXPECTED_ERROR)"
278
+ else:
279
+ return "_UniffiRustCallStatus(<invalid code>)"
280
+
281
+ def _uniffi_rust_call(fn, *args):
282
+ # Call a rust function
283
+ return _uniffi_rust_call_with_error(None, fn, *args)
284
+
285
+ def _uniffi_rust_call_with_error(error_ffi_converter, fn, *args):
286
+ # Call a rust function and handle any errors
287
+ #
288
+ # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code.
289
+ # error_ffi_converter must be set to the _UniffiConverter for the error class that corresponds to the result.
290
+ call_status = _UniffiRustCallStatus.default()
291
+
292
+ args_with_error = args + (ctypes.byref(call_status),)
293
+ result = fn(*args_with_error)
294
+ _uniffi_check_call_status(error_ffi_converter, call_status)
295
+ return result
296
+
297
+ def _uniffi_check_call_status(error_ffi_converter, call_status):
298
+ if call_status.code == _UniffiRustCallStatus.CALL_SUCCESS:
299
+ pass
300
+ elif call_status.code == _UniffiRustCallStatus.CALL_ERROR:
301
+ if error_ffi_converter is None:
302
+ call_status.error_buf.free()
303
+ raise InternalError("_uniffi_rust_call_with_error: CALL_ERROR, but error_ffi_converter is None")
304
+ else:
305
+ raise error_ffi_converter.lift(call_status.error_buf)
306
+ elif call_status.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
307
+ # When the rust code sees a panic, it tries to construct a _UniffiRustBuffer
308
+ # with the message. But if that code panics, then it just sends back
309
+ # an empty buffer.
310
+ if call_status.error_buf.len > 0:
311
+ msg = _UniffiFfiConverterString.lift(call_status.error_buf)
312
+ else:
313
+ msg = "Unknown rust panic"
314
+ raise InternalError(msg)
315
+ else:
316
+ raise InternalError("Invalid _UniffiRustCallStatus code: {}".format(
317
+ call_status.code))
318
+
319
+ def _uniffi_trait_interface_call(call_status, make_call, write_return_value):
320
+ try:
321
+ return write_return_value(make_call())
322
+ except Exception as e:
323
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
324
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
325
+
326
+ def _uniffi_trait_interface_call_with_error(call_status, make_call, write_return_value, error_type, lower_error):
327
+ try:
328
+ try:
329
+ return write_return_value(make_call())
330
+ except error_type as e:
331
+ call_status.code = _UniffiRustCallStatus.CALL_ERROR
332
+ call_status.error_buf = lower_error(e)
333
+ except Exception as e:
334
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
335
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
336
+ # Initial value and increment amount for handles.
337
+ # These ensure that Python-generated handles always have the lowest bit set
338
+ _UNIFFI_HANDLEMAP_INITIAL = 1
339
+ _UNIFFI_HANDLEMAP_DELTA = 2
340
+
341
+ class _UniffiHandleMap:
342
+ """
343
+ A map where inserting, getting and removing data is synchronized with a lock.
344
+ """
345
+
346
+ def __init__(self):
347
+ # type Handle = int
348
+ self._map = {} # type: Dict[Handle, Any]
349
+ self._lock = threading.Lock()
350
+ self._counter = _UNIFFI_HANDLEMAP_INITIAL
351
+
352
+ def insert(self, obj):
353
+ with self._lock:
354
+ return self._insert(obj)
355
+
356
+ """Low-level insert, this assumes `self._lock` is held."""
357
+ def _insert(self, obj):
358
+ handle = self._counter
359
+ self._counter += _UNIFFI_HANDLEMAP_DELTA
360
+ self._map[handle] = obj
361
+ return handle
362
+
363
+ def get(self, handle):
364
+ try:
365
+ with self._lock:
366
+ return self._map[handle]
367
+ except KeyError:
368
+ raise InternalError(f"_UniffiHandleMap.get: Invalid handle {handle}")
369
+
370
+ def clone(self, handle):
371
+ try:
372
+ with self._lock:
373
+ obj = self._map[handle]
374
+ return self._insert(obj)
375
+ except KeyError:
376
+ raise InternalError(f"_UniffiHandleMap.clone: Invalid handle {handle}")
377
+
378
+ def remove(self, handle):
379
+ try:
380
+ with self._lock:
381
+ return self._map.pop(handle)
382
+ except KeyError:
383
+ raise InternalError(f"_UniffiHandleMap.remove: Invalid handle: {handle}")
384
+
385
+ def __len__(self):
386
+ return len(self._map)
387
+ # Types conforming to `_UniffiConverterPrimitive` pass themselves directly over the FFI.
388
+ class _UniffiConverterPrimitive:
389
+ @classmethod
390
+ def lift(cls, value):
391
+ return value
392
+
393
+ @classmethod
394
+ def lower(cls, value):
395
+ return value
396
+
397
+ class _UniffiConverterPrimitiveInt(_UniffiConverterPrimitive):
398
+ @classmethod
399
+ def check_lower(cls, value):
400
+ try:
401
+ value = value.__index__()
402
+ except Exception:
403
+ raise TypeError("'{}' object cannot be interpreted as an integer".format(type(value).__name__))
404
+ if not isinstance(value, int):
405
+ raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__))
406
+ if not cls.VALUE_MIN <= value < cls.VALUE_MAX:
407
+ raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX))
408
+
409
+ class _UniffiConverterPrimitiveFloat(_UniffiConverterPrimitive):
410
+ @classmethod
411
+ def check_lower(cls, value):
412
+ try:
413
+ value = value.__float__()
414
+ except Exception:
415
+ raise TypeError("must be real number, not {}".format(type(value).__name__))
416
+ if not isinstance(value, float):
417
+ raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__))
418
+
419
+ # Helper class for wrapper types that will always go through a _UniffiRustBuffer.
420
+ # Classes should inherit from this and implement the `read` and `write` static methods.
421
+ class _UniffiConverterRustBuffer:
422
+ @classmethod
423
+ def lift(cls, rbuf):
424
+ with rbuf.consume_with_stream() as stream:
425
+ return cls.read(stream)
426
+
427
+ @classmethod
428
+ def lower(cls, value):
429
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
430
+ cls.write(value, builder)
431
+ return builder.finalize()
432
+
433
+ # Contains loading, initialization code, and the FFI Function declarations.
434
+ # Define some ctypes FFI types that we use in the library
435
+
436
+ """
437
+ Function pointer for a Rust task, which a callback function that takes a opaque pointer
438
+ """
439
+ _UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8)
440
+
441
+ def _uniffi_future_callback_t(return_type):
442
+ """
443
+ Factory function to create callback function types for async functions
444
+ """
445
+ return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus)
446
+
447
+ def _uniffi_load_indirect():
448
+ """
449
+ This is how we find and load the dynamic library provided by the component.
450
+ For now we just look it up by name.
451
+ """
452
+ if sys.platform == "darwin":
453
+ libname = "lib{}.dylib"
454
+ elif sys.platform.startswith("win"):
455
+ # As of python3.8, ctypes does not seem to search $PATH when loading DLLs.
456
+ # We could use `os.add_dll_directory` to configure the search path, but
457
+ # it doesn't feel right to mess with application-wide settings. Let's
458
+ # assume that the `.dll` is next to the `.py` file and load by full path.
459
+ libname = os.path.join(
460
+ os.path.dirname(__file__),
461
+ "{}.dll",
462
+ )
463
+ else:
464
+ # Anything else must be an ELF platform - Linux, *BSD, Solaris/illumos
465
+ libname = "lib{}.so"
466
+
467
+ libname = libname.format("matrix_sdk_ffi")
468
+ path = os.path.join(os.path.dirname(__file__), libname)
469
+ lib = ctypes.cdll.LoadLibrary(path)
470
+ return lib
471
+
472
+ def _uniffi_check_contract_api_version(lib):
473
+ # Get the bindings contract version from our ComponentInterface
474
+ bindings_contract_version = 30
475
+ # Get the scaffolding contract version by calling the into the dylib
476
+ scaffolding_contract_version = lib.ffi_matrix_sdk_crypto_uniffi_contract_version()
477
+ if bindings_contract_version != scaffolding_contract_version:
478
+ raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
479
+
480
+ def _uniffi_check_api_checksums(lib):
481
+ pass
482
+
483
+ # A ctypes library to expose the extern-C FFI definitions.
484
+ # This is an implementation detail which will be called internally by the public API.
485
+
486
+ _UniffiLib = _uniffi_load_indirect()
487
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_alloc.argtypes = (
488
+ ctypes.c_uint64,
489
+ ctypes.POINTER(_UniffiRustCallStatus),
490
+ )
491
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_alloc.restype = _UniffiRustBuffer
492
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_from_bytes.argtypes = (
493
+ _UniffiForeignBytes,
494
+ ctypes.POINTER(_UniffiRustCallStatus),
495
+ )
496
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_from_bytes.restype = _UniffiRustBuffer
497
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_free.argtypes = (
498
+ _UniffiRustBuffer,
499
+ ctypes.POINTER(_UniffiRustCallStatus),
500
+ )
501
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_free.restype = None
502
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_reserve.argtypes = (
503
+ _UniffiRustBuffer,
504
+ ctypes.c_uint64,
505
+ ctypes.POINTER(_UniffiRustCallStatus),
506
+ )
507
+ _UniffiLib.ffi_matrix_sdk_crypto_rustbuffer_reserve.restype = _UniffiRustBuffer
508
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int8,
509
+ )
510
+ _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,
511
+ )
512
+ class _UniffiForeignFutureDroppedCallbackStruct(ctypes.Structure):
513
+ _fields_ = [
514
+ ("handle", ctypes.c_uint64),
515
+ ("free", _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK),
516
+ ]
517
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u8.argtypes = (
518
+ ctypes.c_uint64,
519
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
520
+ ctypes.c_uint64,
521
+ )
522
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u8.restype = None
523
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u8.argtypes = (
524
+ ctypes.c_uint64,
525
+ )
526
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u8.restype = None
527
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u8.argtypes = (
528
+ ctypes.c_uint64,
529
+ ctypes.POINTER(_UniffiRustCallStatus),
530
+ )
531
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u8.restype = ctypes.c_uint8
532
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u8.argtypes = (
533
+ ctypes.c_uint64,
534
+ )
535
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u8.restype = None
536
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i8.argtypes = (
537
+ ctypes.c_uint64,
538
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
539
+ ctypes.c_uint64,
540
+ )
541
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i8.restype = None
542
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i8.argtypes = (
543
+ ctypes.c_uint64,
544
+ )
545
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i8.restype = None
546
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i8.argtypes = (
547
+ ctypes.c_uint64,
548
+ ctypes.POINTER(_UniffiRustCallStatus),
549
+ )
550
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i8.restype = ctypes.c_int8
551
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i8.argtypes = (
552
+ ctypes.c_uint64,
553
+ )
554
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i8.restype = None
555
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u16.argtypes = (
556
+ ctypes.c_uint64,
557
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
558
+ ctypes.c_uint64,
559
+ )
560
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u16.restype = None
561
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u16.argtypes = (
562
+ ctypes.c_uint64,
563
+ )
564
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u16.restype = None
565
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u16.argtypes = (
566
+ ctypes.c_uint64,
567
+ ctypes.POINTER(_UniffiRustCallStatus),
568
+ )
569
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u16.restype = ctypes.c_uint16
570
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u16.argtypes = (
571
+ ctypes.c_uint64,
572
+ )
573
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u16.restype = None
574
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i16.argtypes = (
575
+ ctypes.c_uint64,
576
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
577
+ ctypes.c_uint64,
578
+ )
579
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i16.restype = None
580
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i16.argtypes = (
581
+ ctypes.c_uint64,
582
+ )
583
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i16.restype = None
584
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i16.argtypes = (
585
+ ctypes.c_uint64,
586
+ ctypes.POINTER(_UniffiRustCallStatus),
587
+ )
588
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i16.restype = ctypes.c_int16
589
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i16.argtypes = (
590
+ ctypes.c_uint64,
591
+ )
592
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i16.restype = None
593
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u32.argtypes = (
594
+ ctypes.c_uint64,
595
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
596
+ ctypes.c_uint64,
597
+ )
598
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u32.restype = None
599
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u32.argtypes = (
600
+ ctypes.c_uint64,
601
+ )
602
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u32.restype = None
603
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u32.argtypes = (
604
+ ctypes.c_uint64,
605
+ ctypes.POINTER(_UniffiRustCallStatus),
606
+ )
607
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u32.restype = ctypes.c_uint32
608
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u32.argtypes = (
609
+ ctypes.c_uint64,
610
+ )
611
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u32.restype = None
612
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i32.argtypes = (
613
+ ctypes.c_uint64,
614
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
615
+ ctypes.c_uint64,
616
+ )
617
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i32.restype = None
618
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i32.argtypes = (
619
+ ctypes.c_uint64,
620
+ )
621
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i32.restype = None
622
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i32.argtypes = (
623
+ ctypes.c_uint64,
624
+ ctypes.POINTER(_UniffiRustCallStatus),
625
+ )
626
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i32.restype = ctypes.c_int32
627
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i32.argtypes = (
628
+ ctypes.c_uint64,
629
+ )
630
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i32.restype = None
631
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u64.argtypes = (
632
+ ctypes.c_uint64,
633
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
634
+ ctypes.c_uint64,
635
+ )
636
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_u64.restype = None
637
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u64.argtypes = (
638
+ ctypes.c_uint64,
639
+ )
640
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_u64.restype = None
641
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u64.argtypes = (
642
+ ctypes.c_uint64,
643
+ ctypes.POINTER(_UniffiRustCallStatus),
644
+ )
645
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_u64.restype = ctypes.c_uint64
646
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u64.argtypes = (
647
+ ctypes.c_uint64,
648
+ )
649
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_u64.restype = None
650
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i64.argtypes = (
651
+ ctypes.c_uint64,
652
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
653
+ ctypes.c_uint64,
654
+ )
655
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_i64.restype = None
656
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i64.argtypes = (
657
+ ctypes.c_uint64,
658
+ )
659
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_i64.restype = None
660
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i64.argtypes = (
661
+ ctypes.c_uint64,
662
+ ctypes.POINTER(_UniffiRustCallStatus),
663
+ )
664
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_i64.restype = ctypes.c_int64
665
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i64.argtypes = (
666
+ ctypes.c_uint64,
667
+ )
668
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_i64.restype = None
669
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_f32.argtypes = (
670
+ ctypes.c_uint64,
671
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
672
+ ctypes.c_uint64,
673
+ )
674
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_f32.restype = None
675
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_f32.argtypes = (
676
+ ctypes.c_uint64,
677
+ )
678
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_f32.restype = None
679
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_f32.argtypes = (
680
+ ctypes.c_uint64,
681
+ ctypes.POINTER(_UniffiRustCallStatus),
682
+ )
683
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_f32.restype = ctypes.c_float
684
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_f32.argtypes = (
685
+ ctypes.c_uint64,
686
+ )
687
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_f32.restype = None
688
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_f64.argtypes = (
689
+ ctypes.c_uint64,
690
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
691
+ ctypes.c_uint64,
692
+ )
693
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_f64.restype = None
694
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_f64.argtypes = (
695
+ ctypes.c_uint64,
696
+ )
697
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_f64.restype = None
698
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_f64.argtypes = (
699
+ ctypes.c_uint64,
700
+ ctypes.POINTER(_UniffiRustCallStatus),
701
+ )
702
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_f64.restype = ctypes.c_double
703
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_f64.argtypes = (
704
+ ctypes.c_uint64,
705
+ )
706
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_f64.restype = None
707
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_rust_buffer.argtypes = (
708
+ ctypes.c_uint64,
709
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
710
+ ctypes.c_uint64,
711
+ )
712
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_rust_buffer.restype = None
713
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_rust_buffer.argtypes = (
714
+ ctypes.c_uint64,
715
+ )
716
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_rust_buffer.restype = None
717
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_rust_buffer.argtypes = (
718
+ ctypes.c_uint64,
719
+ ctypes.POINTER(_UniffiRustCallStatus),
720
+ )
721
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_rust_buffer.restype = _UniffiRustBuffer
722
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_rust_buffer.argtypes = (
723
+ ctypes.c_uint64,
724
+ )
725
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_rust_buffer.restype = None
726
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_void.argtypes = (
727
+ ctypes.c_uint64,
728
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
729
+ ctypes.c_uint64,
730
+ )
731
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_poll_void.restype = None
732
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_void.argtypes = (
733
+ ctypes.c_uint64,
734
+ )
735
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_cancel_void.restype = None
736
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_void.argtypes = (
737
+ ctypes.c_uint64,
738
+ ctypes.POINTER(_UniffiRustCallStatus),
739
+ )
740
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_complete_void.restype = None
741
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_void.argtypes = (
742
+ ctypes.c_uint64,
743
+ )
744
+ _UniffiLib.ffi_matrix_sdk_crypto_rust_future_free_void.restype = None
745
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_backupsecrets.argtypes = (
746
+ ctypes.c_uint64,
747
+ ctypes.POINTER(_UniffiRustCallStatus),
748
+ )
749
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_backupsecrets.restype = ctypes.c_uint64
750
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_free_backupsecrets.argtypes = (
751
+ ctypes.c_uint64,
752
+ ctypes.POINTER(_UniffiRustCallStatus),
753
+ )
754
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_free_backupsecrets.restype = None
755
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_crosssigningsecrets.argtypes = (
756
+ ctypes.c_uint64,
757
+ ctypes.POINTER(_UniffiRustCallStatus),
758
+ )
759
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_crosssigningsecrets.restype = ctypes.c_uint64
760
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_free_crosssigningsecrets.argtypes = (
761
+ ctypes.c_uint64,
762
+ ctypes.POINTER(_UniffiRustCallStatus),
763
+ )
764
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_free_crosssigningsecrets.restype = None
765
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_secretsbundle.argtypes = (
766
+ ctypes.c_uint64,
767
+ ctypes.POINTER(_UniffiRustCallStatus),
768
+ )
769
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_secretsbundle.restype = ctypes.c_uint64
770
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_free_secretsbundle.argtypes = (
771
+ ctypes.c_uint64,
772
+ ctypes.POINTER(_UniffiRustCallStatus),
773
+ )
774
+ _UniffiLib.uniffi_matrix_sdk_crypto_fn_free_secretsbundle.restype = None
775
+ _UniffiLib.ffi_matrix_sdk_crypto_uniffi_contract_version.argtypes = (
776
+ )
777
+ _UniffiLib.ffi_matrix_sdk_crypto_uniffi_contract_version.restype = ctypes.c_uint32
778
+
779
+ _uniffi_check_contract_api_version(_UniffiLib)
780
+ # _uniffi_check_api_checksums(_UniffiLib)
781
+
782
+
783
+
784
+ # Public interface members begin here.
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+ class TrustRequirement(enum.Enum):
793
+ """
794
+ The trust level in the sender's device that is required to decrypt an
795
+ event.
796
+ """
797
+
798
+ UNTRUSTED = 0
799
+ """
800
+ Decrypt events from everyone regardless of trust.
801
+
802
+ Not recommended, per the guidance of [MSC4153].
803
+
804
+ [MSC4153]: https://github.com/matrix-org/matrix-doc/pull/4153
805
+ """
806
+
807
+ CROSS_SIGNED_OR_LEGACY = 1
808
+ """
809
+ Only decrypt events from cross-signed devices or legacy sessions (Megolm
810
+ sessions created before we started collecting trust information).
811
+ """
812
+
813
+ CROSS_SIGNED = 2
814
+ """
815
+ Only decrypt events from cross-signed devices.
816
+ """
817
+
818
+
819
+
820
+ class _UniffiFfiConverterTypeTrustRequirement(_UniffiConverterRustBuffer):
821
+ @staticmethod
822
+ def read(buf):
823
+ variant = buf.read_i32()
824
+ if variant == 1:
825
+ return TrustRequirement.UNTRUSTED
826
+ if variant == 2:
827
+ return TrustRequirement.CROSS_SIGNED_OR_LEGACY
828
+ if variant == 3:
829
+ return TrustRequirement.CROSS_SIGNED
830
+ raise InternalError("Raw enum value doesn't match any cases")
831
+
832
+ @staticmethod
833
+ def check_lower(value):
834
+ if value == TrustRequirement.UNTRUSTED:
835
+ return
836
+ if value == TrustRequirement.CROSS_SIGNED_OR_LEGACY:
837
+ return
838
+ if value == TrustRequirement.CROSS_SIGNED:
839
+ return
840
+ raise ValueError(value)
841
+
842
+ @staticmethod
843
+ def write(value, buf):
844
+ if value == TrustRequirement.UNTRUSTED:
845
+ buf.write_i32(1)
846
+ if value == TrustRequirement.CROSS_SIGNED_OR_LEGACY:
847
+ buf.write_i32(2)
848
+ if value == TrustRequirement.CROSS_SIGNED:
849
+ buf.write_i32(3)
850
+
851
+
852
+
853
+ @dataclass
854
+ class DecryptionSettings:
855
+ """
856
+ Settings for decrypting messages
857
+ """
858
+ def __init__(self, *, sender_device_trust_requirement:TrustRequirement):
859
+ self.sender_device_trust_requirement = sender_device_trust_requirement
860
+
861
+
862
+
863
+
864
+ def __str__(self):
865
+ return "DecryptionSettings(sender_device_trust_requirement={})".format(self.sender_device_trust_requirement)
866
+ def __eq__(self, other):
867
+ if self.sender_device_trust_requirement != other.sender_device_trust_requirement:
868
+ return False
869
+ return True
870
+
871
+ class _UniffiFfiConverterTypeDecryptionSettings(_UniffiConverterRustBuffer):
872
+ @staticmethod
873
+ def read(buf):
874
+ return DecryptionSettings(
875
+ sender_device_trust_requirement=_UniffiFfiConverterTypeTrustRequirement.read(buf),
876
+ )
877
+
878
+ @staticmethod
879
+ def check_lower(value):
880
+ _UniffiFfiConverterTypeTrustRequirement.check_lower(value.sender_device_trust_requirement)
881
+
882
+ @staticmethod
883
+ def write(value, buf):
884
+ _UniffiFfiConverterTypeTrustRequirement.write(value.sender_device_trust_requirement, buf)
885
+
886
+
887
+
888
+
889
+
890
+
891
+ class CollectStrategy(enum.Enum):
892
+ """
893
+ Strategy to collect the devices that should receive room keys for the
894
+ current discussion.
895
+ """
896
+
897
+ ALL_DEVICES = 0
898
+ """
899
+ Share with all (unblacklisted) devices.
900
+
901
+ Not recommended, per the guidance of [MSC4153].
902
+
903
+ (Used by Element X and Element Web in the legacy, non-"exclude insecure
904
+ devices" mode.)
905
+
906
+ [MSC4153]: https://github.com/matrix-org/matrix-doc/pull/4153
907
+ """
908
+
909
+ ERROR_ON_VERIFIED_USER_PROBLEM = 1
910
+ """
911
+ Share with all devices, except errors for *verified* users cause sharing
912
+ to fail with an error.
913
+
914
+ In this strategy, if a verified user has an unsigned device,
915
+ key sharing will fail with a
916
+ [`SessionRecipientCollectionError::VerifiedUserHasUnsignedDevice`].
917
+ If a verified user has replaced their identity, key
918
+ sharing will fail with a
919
+ [`SessionRecipientCollectionError::VerifiedUserChangedIdentity`].
920
+
921
+ Otherwise, keys are shared with unsigned devices as normal.
922
+
923
+ Once the problematic devices are blacklisted or whitelisted the
924
+ caller can retry to share a second time.
925
+
926
+ Not recommended, per the guidance of [MSC4153].
927
+
928
+ [MSC4153]: https://github.com/matrix-org/matrix-doc/pull/4153
929
+ """
930
+
931
+ IDENTITY_BASED_STRATEGY = 2
932
+ """
933
+ Share based on identity. Only distribute to devices signed by their
934
+ owner. If a user has no published identity he will not receive
935
+ any room keys.
936
+
937
+ This is the recommended strategy: it is compliant with the guidance of
938
+ [MSC4153].
939
+
940
+ (Used by Element Web and Element X in the "exclude insecure devices"
941
+ mode.)
942
+
943
+ [MSC4153]: https://github.com/matrix-org/matrix-doc/pull/4153
944
+ """
945
+
946
+ ONLY_TRUSTED_DEVICES = 3
947
+ """
948
+ Only share keys with devices that we "trust". A device is trusted if any
949
+ of the following is true:
950
+ - It was manually marked as trusted.
951
+ - It was marked as verified via interactive verification.
952
+ - It is signed by its owner identity, and this identity has been
953
+ trusted via interactive verification.
954
+ - It is the current own device of the user.
955
+
956
+ This strategy is compliant with [MSC4153], but is probably too strict
957
+ for normal use.
958
+
959
+ (Used by Element Web when "only send messages to verified users" is
960
+ enabled.)
961
+
962
+ [MSC4153]: https://github.com/matrix-org/matrix-doc/pull/4153
963
+ """
964
+
965
+
966
+
967
+ class _UniffiFfiConverterTypeCollectStrategy(_UniffiConverterRustBuffer):
968
+ @staticmethod
969
+ def read(buf):
970
+ variant = buf.read_i32()
971
+ if variant == 1:
972
+ return CollectStrategy.ALL_DEVICES
973
+ if variant == 2:
974
+ return CollectStrategy.ERROR_ON_VERIFIED_USER_PROBLEM
975
+ if variant == 3:
976
+ return CollectStrategy.IDENTITY_BASED_STRATEGY
977
+ if variant == 4:
978
+ return CollectStrategy.ONLY_TRUSTED_DEVICES
979
+ raise InternalError("Raw enum value doesn't match any cases")
980
+
981
+ @staticmethod
982
+ def check_lower(value):
983
+ if value == CollectStrategy.ALL_DEVICES:
984
+ return
985
+ if value == CollectStrategy.ERROR_ON_VERIFIED_USER_PROBLEM:
986
+ return
987
+ if value == CollectStrategy.IDENTITY_BASED_STRATEGY:
988
+ return
989
+ if value == CollectStrategy.ONLY_TRUSTED_DEVICES:
990
+ return
991
+ raise ValueError(value)
992
+
993
+ @staticmethod
994
+ def write(value, buf):
995
+ if value == CollectStrategy.ALL_DEVICES:
996
+ buf.write_i32(1)
997
+ if value == CollectStrategy.ERROR_ON_VERIFIED_USER_PROBLEM:
998
+ buf.write_i32(2)
999
+ if value == CollectStrategy.IDENTITY_BASED_STRATEGY:
1000
+ buf.write_i32(3)
1001
+ if value == CollectStrategy.ONLY_TRUSTED_DEVICES:
1002
+ buf.write_i32(4)
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+ class IdentityState(enum.Enum):
1012
+ """
1013
+ The state of an identity - verified, pinned etc.
1014
+ """
1015
+
1016
+ VERIFIED = 0
1017
+ """
1018
+ The user is verified with us
1019
+ """
1020
+
1021
+ PINNED = 1
1022
+ """
1023
+ Either this is the first identity we have seen for this user, or the
1024
+ user has acknowledged a change of identity explicitly e.g. by
1025
+ clicking OK on a notification.
1026
+ """
1027
+
1028
+ PIN_VIOLATION = 2
1029
+ """
1030
+ The user's identity has changed since it was pinned. The user should be
1031
+ notified about this and given the opportunity to acknowledge the
1032
+ change, which will make the new identity pinned.
1033
+ When the user acknowledges the change, the app should call
1034
+ [`crate::OtherUserIdentity::pin_current_master_key`].
1035
+ """
1036
+
1037
+ VERIFICATION_VIOLATION = 3
1038
+ """
1039
+ The user's identity has changed, and before that it was verified. This
1040
+ is a serious problem. The user can either verify again to make this
1041
+ identity verified, or withdraw verification
1042
+ [`UserIdentity::withdraw_verification`] to make it pinned.
1043
+ """
1044
+
1045
+
1046
+
1047
+ class _UniffiFfiConverterTypeIdentityState(_UniffiConverterRustBuffer):
1048
+ @staticmethod
1049
+ def read(buf):
1050
+ variant = buf.read_i32()
1051
+ if variant == 1:
1052
+ return IdentityState.VERIFIED
1053
+ if variant == 2:
1054
+ return IdentityState.PINNED
1055
+ if variant == 3:
1056
+ return IdentityState.PIN_VIOLATION
1057
+ if variant == 4:
1058
+ return IdentityState.VERIFICATION_VIOLATION
1059
+ raise InternalError("Raw enum value doesn't match any cases")
1060
+
1061
+ @staticmethod
1062
+ def check_lower(value):
1063
+ if value == IdentityState.VERIFIED:
1064
+ return
1065
+ if value == IdentityState.PINNED:
1066
+ return
1067
+ if value == IdentityState.PIN_VIOLATION:
1068
+ return
1069
+ if value == IdentityState.VERIFICATION_VIOLATION:
1070
+ return
1071
+ raise ValueError(value)
1072
+
1073
+ @staticmethod
1074
+ def write(value, buf):
1075
+ if value == IdentityState.VERIFIED:
1076
+ buf.write_i32(1)
1077
+ if value == IdentityState.PINNED:
1078
+ buf.write_i32(2)
1079
+ if value == IdentityState.PIN_VIOLATION:
1080
+ buf.write_i32(3)
1081
+ if value == IdentityState.VERIFICATION_VIOLATION:
1082
+ buf.write_i32(4)
1083
+
1084
+
1085
+
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+ class LocalTrust(enum.Enum):
1092
+ """
1093
+ The local trust state of a device.
1094
+ """
1095
+
1096
+ VERIFIED = 0
1097
+ """
1098
+ The device has been verified and is trusted.
1099
+ """
1100
+
1101
+ BLACK_LISTED = 1
1102
+ """
1103
+ The device been blacklisted from communicating.
1104
+ """
1105
+
1106
+ IGNORED = 2
1107
+ """
1108
+ The trust state of the device is being ignored.
1109
+ """
1110
+
1111
+ UNSET = 3
1112
+ """
1113
+ The trust state is unset.
1114
+ """
1115
+
1116
+
1117
+
1118
+ class _UniffiFfiConverterTypeLocalTrust(_UniffiConverterRustBuffer):
1119
+ @staticmethod
1120
+ def read(buf):
1121
+ variant = buf.read_i32()
1122
+ if variant == 1:
1123
+ return LocalTrust.VERIFIED
1124
+ if variant == 2:
1125
+ return LocalTrust.BLACK_LISTED
1126
+ if variant == 3:
1127
+ return LocalTrust.IGNORED
1128
+ if variant == 4:
1129
+ return LocalTrust.UNSET
1130
+ raise InternalError("Raw enum value doesn't match any cases")
1131
+
1132
+ @staticmethod
1133
+ def check_lower(value):
1134
+ if value == LocalTrust.VERIFIED:
1135
+ return
1136
+ if value == LocalTrust.BLACK_LISTED:
1137
+ return
1138
+ if value == LocalTrust.IGNORED:
1139
+ return
1140
+ if value == LocalTrust.UNSET:
1141
+ return
1142
+ raise ValueError(value)
1143
+
1144
+ @staticmethod
1145
+ def write(value, buf):
1146
+ if value == LocalTrust.VERIFIED:
1147
+ buf.write_i32(1)
1148
+ if value == LocalTrust.BLACK_LISTED:
1149
+ buf.write_i32(2)
1150
+ if value == LocalTrust.IGNORED:
1151
+ buf.write_i32(3)
1152
+ if value == LocalTrust.UNSET:
1153
+ buf.write_i32(4)
1154
+
1155
+
1156
+
1157
+
1158
+
1159
+ # LoginQrCodeDecodeError
1160
+ # We want to define each variant as a nested class that's also a subclass,
1161
+ # which is tricky in Python. To accomplish this we're going to create each
1162
+ # class separately, then manually add the child classes to the base class's
1163
+ # __dict__. All of this happens in dummy class to avoid polluting the module
1164
+ # namespace.
1165
+ class LoginQrCodeDecodeError(Exception):
1166
+ """
1167
+ Error type for the decoding of the [`QrCodeData`].
1168
+ """
1169
+ pass
1170
+
1171
+ _UniffiTempLoginQrCodeDecodeError = LoginQrCodeDecodeError
1172
+
1173
+ class LoginQrCodeDecodeError: # type: ignore
1174
+ """
1175
+ Error type for the decoding of the [`QrCodeData`].
1176
+ """
1177
+
1178
+ class NotEnoughData(_UniffiTempLoginQrCodeDecodeError):
1179
+ """
1180
+ The QR code data is no long enough, it's missing some fields.
1181
+ """
1182
+ def __repr__(self):
1183
+ return "LoginQrCodeDecodeError.NotEnoughData({})".format(repr(str(self)))
1184
+ _UniffiTempLoginQrCodeDecodeError.NotEnoughData = NotEnoughData # type: ignore
1185
+ class NotUtf8(_UniffiTempLoginQrCodeDecodeError):
1186
+ """
1187
+ One of the URLs in the QR code data is not a valid UTF-8 encoded string.
1188
+ """
1189
+ def __repr__(self):
1190
+ return "LoginQrCodeDecodeError.NotUtf8({})".format(repr(str(self)))
1191
+ _UniffiTempLoginQrCodeDecodeError.NotUtf8 = NotUtf8 # type: ignore
1192
+ class UrlParse(_UniffiTempLoginQrCodeDecodeError):
1193
+ """
1194
+ One of the URLs in the QR code data could not be parsed.
1195
+ """
1196
+ def __repr__(self):
1197
+ return "LoginQrCodeDecodeError.UrlParse({})".format(repr(str(self)))
1198
+ _UniffiTempLoginQrCodeDecodeError.UrlParse = UrlParse # type: ignore
1199
+ class InvalidIntent(_UniffiTempLoginQrCodeDecodeError):
1200
+ """
1201
+ The QR code data contains an invalid intent, we expect the login
1202
+ intent or the reciprocate intent.
1203
+ """
1204
+ def __repr__(self):
1205
+ return "LoginQrCodeDecodeError.InvalidIntent({})".format(repr(str(self)))
1206
+ _UniffiTempLoginQrCodeDecodeError.InvalidIntent = InvalidIntent # type: ignore
1207
+ class InvalidType(_UniffiTempLoginQrCodeDecodeError):
1208
+ """
1209
+ The QR code data contains an unsupported type.
1210
+ """
1211
+ def __repr__(self):
1212
+ return "LoginQrCodeDecodeError.InvalidType({})".format(repr(str(self)))
1213
+ _UniffiTempLoginQrCodeDecodeError.InvalidType = InvalidType # type: ignore
1214
+ class Base64(_UniffiTempLoginQrCodeDecodeError):
1215
+ """
1216
+ The base64 encoded variant of the QR code data is not a valid base64
1217
+ string.
1218
+ """
1219
+ def __repr__(self):
1220
+ return "LoginQrCodeDecodeError.Base64({})".format(repr(str(self)))
1221
+ _UniffiTempLoginQrCodeDecodeError.Base64 = Base64 # type: ignore
1222
+ class InvalidPrefix(_UniffiTempLoginQrCodeDecodeError):
1223
+ """
1224
+ The QR code data doesn't contain the expected `MATRIX` prefix.
1225
+ """
1226
+ def __repr__(self):
1227
+ return "LoginQrCodeDecodeError.InvalidPrefix({})".format(repr(str(self)))
1228
+ _UniffiTempLoginQrCodeDecodeError.InvalidPrefix = InvalidPrefix # type: ignore
1229
+
1230
+ LoginQrCodeDecodeError = _UniffiTempLoginQrCodeDecodeError # type: ignore
1231
+ del _UniffiTempLoginQrCodeDecodeError
1232
+
1233
+
1234
+ class _UniffiFfiConverterTypeLoginQrCodeDecodeError(_UniffiConverterRustBuffer):
1235
+ @staticmethod
1236
+ def read(buf):
1237
+ variant = buf.read_i32()
1238
+ if variant == 1:
1239
+ return LoginQrCodeDecodeError.NotEnoughData(
1240
+ _UniffiFfiConverterString.read(buf),
1241
+ )
1242
+ if variant == 2:
1243
+ return LoginQrCodeDecodeError.NotUtf8(
1244
+ _UniffiFfiConverterString.read(buf),
1245
+ )
1246
+ if variant == 3:
1247
+ return LoginQrCodeDecodeError.UrlParse(
1248
+ _UniffiFfiConverterString.read(buf),
1249
+ )
1250
+ if variant == 4:
1251
+ return LoginQrCodeDecodeError.InvalidIntent(
1252
+ _UniffiFfiConverterString.read(buf),
1253
+ )
1254
+ if variant == 5:
1255
+ return LoginQrCodeDecodeError.InvalidType(
1256
+ _UniffiFfiConverterString.read(buf),
1257
+ )
1258
+ if variant == 6:
1259
+ return LoginQrCodeDecodeError.Base64(
1260
+ _UniffiFfiConverterString.read(buf),
1261
+ )
1262
+ if variant == 7:
1263
+ return LoginQrCodeDecodeError.InvalidPrefix(
1264
+ _UniffiFfiConverterString.read(buf),
1265
+ )
1266
+ raise InternalError("Raw enum value doesn't match any cases")
1267
+
1268
+ @staticmethod
1269
+ def check_lower(value):
1270
+ if isinstance(value, LoginQrCodeDecodeError.NotEnoughData):
1271
+ return
1272
+ if isinstance(value, LoginQrCodeDecodeError.NotUtf8):
1273
+ return
1274
+ if isinstance(value, LoginQrCodeDecodeError.UrlParse):
1275
+ return
1276
+ if isinstance(value, LoginQrCodeDecodeError.InvalidIntent):
1277
+ return
1278
+ if isinstance(value, LoginQrCodeDecodeError.InvalidType):
1279
+ return
1280
+ if isinstance(value, LoginQrCodeDecodeError.Base64):
1281
+ return
1282
+ if isinstance(value, LoginQrCodeDecodeError.InvalidPrefix):
1283
+ return
1284
+
1285
+ @staticmethod
1286
+ def write(value, buf):
1287
+ if isinstance(value, LoginQrCodeDecodeError.NotEnoughData):
1288
+ buf.write_i32(1)
1289
+ if isinstance(value, LoginQrCodeDecodeError.NotUtf8):
1290
+ buf.write_i32(2)
1291
+ if isinstance(value, LoginQrCodeDecodeError.UrlParse):
1292
+ buf.write_i32(3)
1293
+ if isinstance(value, LoginQrCodeDecodeError.InvalidIntent):
1294
+ buf.write_i32(4)
1295
+ if isinstance(value, LoginQrCodeDecodeError.InvalidType):
1296
+ buf.write_i32(5)
1297
+ if isinstance(value, LoginQrCodeDecodeError.Base64):
1298
+ buf.write_i32(6)
1299
+ if isinstance(value, LoginQrCodeDecodeError.InvalidPrefix):
1300
+ buf.write_i32(7)
1301
+
1302
+
1303
+
1304
+
1305
+
1306
+
1307
+ class QrCodeIntent(enum.Enum):
1308
+ """
1309
+ The intent of the device that generated/displayed the QR code.
1310
+
1311
+ The QR code login mechanism supports both, the new device, as well as the
1312
+ existing device to display the QR code.
1313
+
1314
+ The different intents have an explicit one-byte identifier which gets added
1315
+ to the QR code data.
1316
+ """
1317
+
1318
+ LOGIN = 0
1319
+ """
1320
+ Enum variant for the case where the new device is displaying the QR
1321
+ code.
1322
+ """
1323
+
1324
+ RECIPROCATE = 1
1325
+ """
1326
+ Enum variant for the case where the existing device is displaying the QR
1327
+ code.
1328
+ """
1329
+
1330
+
1331
+
1332
+ class _UniffiFfiConverterTypeQrCodeIntent(_UniffiConverterRustBuffer):
1333
+ @staticmethod
1334
+ def read(buf):
1335
+ variant = buf.read_i32()
1336
+ if variant == 1:
1337
+ return QrCodeIntent.LOGIN
1338
+ if variant == 2:
1339
+ return QrCodeIntent.RECIPROCATE
1340
+ raise InternalError("Raw enum value doesn't match any cases")
1341
+
1342
+ @staticmethod
1343
+ def check_lower(value):
1344
+ if value == QrCodeIntent.LOGIN:
1345
+ return
1346
+ if value == QrCodeIntent.RECIPROCATE:
1347
+ return
1348
+ raise ValueError(value)
1349
+
1350
+ @staticmethod
1351
+ def write(value, buf):
1352
+ if value == QrCodeIntent.LOGIN:
1353
+ buf.write_i32(1)
1354
+ if value == QrCodeIntent.RECIPROCATE:
1355
+ buf.write_i32(2)
1356
+
1357
+
1358
+
1359
+
1360
+
1361
+
1362
+
1363
+
1364
+ class SignatureState(enum.Enum):
1365
+ """
1366
+ The result of a signature check.
1367
+ """
1368
+
1369
+ MISSING = 0
1370
+ """
1371
+ The signature is missing.
1372
+ """
1373
+
1374
+ INVALID = 1
1375
+ """
1376
+ The signature is invalid.
1377
+ """
1378
+
1379
+ VALID_BUT_NOT_TRUSTED = 2
1380
+ """
1381
+ The signature is valid but the device or user identity that created the
1382
+ signature is not trusted.
1383
+ """
1384
+
1385
+ VALID_AND_TRUSTED = 3
1386
+ """
1387
+ The signature is valid and the device or user identity that created the
1388
+ signature is trusted.
1389
+ """
1390
+
1391
+
1392
+
1393
+ class _UniffiFfiConverterTypeSignatureState(_UniffiConverterRustBuffer):
1394
+ @staticmethod
1395
+ def read(buf):
1396
+ variant = buf.read_i32()
1397
+ if variant == 1:
1398
+ return SignatureState.MISSING
1399
+ if variant == 2:
1400
+ return SignatureState.INVALID
1401
+ if variant == 3:
1402
+ return SignatureState.VALID_BUT_NOT_TRUSTED
1403
+ if variant == 4:
1404
+ return SignatureState.VALID_AND_TRUSTED
1405
+ raise InternalError("Raw enum value doesn't match any cases")
1406
+
1407
+ @staticmethod
1408
+ def check_lower(value):
1409
+ if value == SignatureState.MISSING:
1410
+ return
1411
+ if value == SignatureState.INVALID:
1412
+ return
1413
+ if value == SignatureState.VALID_BUT_NOT_TRUSTED:
1414
+ return
1415
+ if value == SignatureState.VALID_AND_TRUSTED:
1416
+ return
1417
+ raise ValueError(value)
1418
+
1419
+ @staticmethod
1420
+ def write(value, buf):
1421
+ if value == SignatureState.MISSING:
1422
+ buf.write_i32(1)
1423
+ if value == SignatureState.INVALID:
1424
+ buf.write_i32(2)
1425
+ if value == SignatureState.VALID_BUT_NOT_TRUSTED:
1426
+ buf.write_i32(3)
1427
+ if value == SignatureState.VALID_AND_TRUSTED:
1428
+ buf.write_i32(4)
1429
+
1430
+
1431
+
1432
+
1433
+
1434
+
1435
+
1436
+
1437
+ class UtdCause(enum.Enum):
1438
+ """
1439
+ Our best guess at the reason why an event can't be decrypted.
1440
+ """
1441
+
1442
+ UNKNOWN = 0
1443
+ """
1444
+ We don't have an explanation for why this UTD happened - it is probably
1445
+ a bug, or a network split between the two homeservers.
1446
+
1447
+ For example:
1448
+
1449
+ - the keys for this event are missing, but a key storage backup exists
1450
+ and is working, so we should be able to find the keys in the backup.
1451
+
1452
+ - the keys for this event are missing, and a key storage backup exists
1453
+ on the server, but that backup is not working on this client even
1454
+ though this device is verified.
1455
+ """
1456
+
1457
+ SENT_BEFORE_WE_JOINED = 1
1458
+ """
1459
+ We are missing the keys for this event, and the event was sent when we
1460
+ were not a member of the room (or invited).
1461
+ """
1462
+
1463
+ VERIFICATION_VIOLATION = 2
1464
+ """
1465
+ The message was sent by a user identity we have not verified, but the
1466
+ user was previously verified.
1467
+ """
1468
+
1469
+ UNSIGNED_DEVICE = 3
1470
+ """
1471
+ The [`crate::TrustRequirement`] requires that the sending device be
1472
+ signed by its owner, and it was not.
1473
+ """
1474
+
1475
+ UNKNOWN_DEVICE = 4
1476
+ """
1477
+ The [`crate::TrustRequirement`] requires that the sending device be
1478
+ signed by its owner, and we were unable to securely find the device.
1479
+
1480
+ This could be because the device has since been deleted, because we
1481
+ haven't yet downloaded it from the server, or because the session
1482
+ data was obtained from an insecure source (imported from a file,
1483
+ obtained from a legacy (asymmetric) backup, unsafe key forward, etc.)
1484
+ """
1485
+
1486
+ HISTORICAL_MESSAGE_AND_BACKUP_IS_DISABLED = 5
1487
+ """
1488
+ We are missing the keys for this event, but it is a "device-historical"
1489
+ message and there is no key storage backup on the server, presumably
1490
+ because the user has turned it off.
1491
+
1492
+ Device-historical means that the message was sent before the current
1493
+ device existed (but the current user was probably a member of the room
1494
+ at the time the message was sent). Not to
1495
+ be confused with pre-join or pre-invite messages (see
1496
+ [`UtdCause::SentBeforeWeJoined`] for that).
1497
+
1498
+ Expected message to user: "History is not available on this device".
1499
+ """
1500
+
1501
+ WITHHELD_FOR_UNVERIFIED_OR_INSECURE_DEVICE = 6
1502
+ """
1503
+ The keys for this event are intentionally withheld.
1504
+
1505
+ The sender has refused to share the key because our device does not meet
1506
+ the sender's security requirements.
1507
+ """
1508
+
1509
+ WITHHELD_BY_SENDER = 7
1510
+ """
1511
+ The keys for this event are missing, likely because the sender was
1512
+ unable to share them (e.g., failure to establish an Olm 1:1
1513
+ channel). Alternatively, the sender may have deliberately excluded
1514
+ this device by cherry-picking and blocking it, in which case, no action
1515
+ can be taken on our side.
1516
+ """
1517
+
1518
+ HISTORICAL_MESSAGE_AND_DEVICE_IS_UNVERIFIED = 8
1519
+ """
1520
+ We are missing the keys for this event, but it is a "device-historical"
1521
+ message, and even though a key storage backup does exist, we can't use
1522
+ it because our device is unverified.
1523
+
1524
+ Device-historical means that the message was sent before the current
1525
+ device existed (but the current user was probably a member of the room
1526
+ at the time the message was sent). Not to
1527
+ be confused with pre-join or pre-invite messages (see
1528
+ [`UtdCause::SentBeforeWeJoined`] for that).
1529
+
1530
+ Expected message to user: "You need to verify this device".
1531
+ """
1532
+
1533
+
1534
+
1535
+ class _UniffiFfiConverterTypeUtdCause(_UniffiConverterRustBuffer):
1536
+ @staticmethod
1537
+ def read(buf):
1538
+ variant = buf.read_i32()
1539
+ if variant == 1:
1540
+ return UtdCause.UNKNOWN
1541
+ if variant == 2:
1542
+ return UtdCause.SENT_BEFORE_WE_JOINED
1543
+ if variant == 3:
1544
+ return UtdCause.VERIFICATION_VIOLATION
1545
+ if variant == 4:
1546
+ return UtdCause.UNSIGNED_DEVICE
1547
+ if variant == 5:
1548
+ return UtdCause.UNKNOWN_DEVICE
1549
+ if variant == 6:
1550
+ return UtdCause.HISTORICAL_MESSAGE_AND_BACKUP_IS_DISABLED
1551
+ if variant == 7:
1552
+ return UtdCause.WITHHELD_FOR_UNVERIFIED_OR_INSECURE_DEVICE
1553
+ if variant == 8:
1554
+ return UtdCause.WITHHELD_BY_SENDER
1555
+ if variant == 9:
1556
+ return UtdCause.HISTORICAL_MESSAGE_AND_DEVICE_IS_UNVERIFIED
1557
+ raise InternalError("Raw enum value doesn't match any cases")
1558
+
1559
+ @staticmethod
1560
+ def check_lower(value):
1561
+ if value == UtdCause.UNKNOWN:
1562
+ return
1563
+ if value == UtdCause.SENT_BEFORE_WE_JOINED:
1564
+ return
1565
+ if value == UtdCause.VERIFICATION_VIOLATION:
1566
+ return
1567
+ if value == UtdCause.UNSIGNED_DEVICE:
1568
+ return
1569
+ if value == UtdCause.UNKNOWN_DEVICE:
1570
+ return
1571
+ if value == UtdCause.HISTORICAL_MESSAGE_AND_BACKUP_IS_DISABLED:
1572
+ return
1573
+ if value == UtdCause.WITHHELD_FOR_UNVERIFIED_OR_INSECURE_DEVICE:
1574
+ return
1575
+ if value == UtdCause.WITHHELD_BY_SENDER:
1576
+ return
1577
+ if value == UtdCause.HISTORICAL_MESSAGE_AND_DEVICE_IS_UNVERIFIED:
1578
+ return
1579
+ raise ValueError(value)
1580
+
1581
+ @staticmethod
1582
+ def write(value, buf):
1583
+ if value == UtdCause.UNKNOWN:
1584
+ buf.write_i32(1)
1585
+ if value == UtdCause.SENT_BEFORE_WE_JOINED:
1586
+ buf.write_i32(2)
1587
+ if value == UtdCause.VERIFICATION_VIOLATION:
1588
+ buf.write_i32(3)
1589
+ if value == UtdCause.UNSIGNED_DEVICE:
1590
+ buf.write_i32(4)
1591
+ if value == UtdCause.UNKNOWN_DEVICE:
1592
+ buf.write_i32(5)
1593
+ if value == UtdCause.HISTORICAL_MESSAGE_AND_BACKUP_IS_DISABLED:
1594
+ buf.write_i32(6)
1595
+ if value == UtdCause.WITHHELD_FOR_UNVERIFIED_OR_INSECURE_DEVICE:
1596
+ buf.write_i32(7)
1597
+ if value == UtdCause.WITHHELD_BY_SENDER:
1598
+ buf.write_i32(8)
1599
+ if value == UtdCause.HISTORICAL_MESSAGE_AND_DEVICE_IS_UNVERIFIED:
1600
+ buf.write_i32(9)
1601
+
1602
+
1603
+
1604
+
1605
+ class BackupSecretsProtocol(typing.Protocol):
1606
+ """
1607
+ Enum for the algorithm-specific secrets for the room key backup.
1608
+ """
1609
+
1610
+ pass
1611
+
1612
+ class BackupSecrets(BackupSecretsProtocol):
1613
+ """
1614
+ Enum for the algorithm-specific secrets for the room key backup.
1615
+ """
1616
+
1617
+ _handle: ctypes.c_uint64
1618
+
1619
+ def __init__(self, *args, **kwargs):
1620
+ raise ValueError("This class has no default constructor")
1621
+
1622
+ def __del__(self):
1623
+ # In case of partial initialization of instances.
1624
+ handle = getattr(self, "_handle", None)
1625
+ if handle is not None:
1626
+ _uniffi_rust_call(_UniffiLib.uniffi_matrix_sdk_crypto_fn_free_backupsecrets, handle)
1627
+
1628
+ def _uniffi_clone_handle(self):
1629
+ return _uniffi_rust_call(_UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_backupsecrets, self._handle)
1630
+
1631
+ # Used by alternative constructors or any methods which return this type.
1632
+ @classmethod
1633
+ def _uniffi_make_instance(cls, handle):
1634
+ # Lightly yucky way to bypass the usual __init__ logic
1635
+ # and just create a new instance with the required handle.
1636
+ inst = cls.__new__(cls)
1637
+ inst._handle = handle
1638
+ return inst
1639
+
1640
+
1641
+
1642
+
1643
+
1644
+ class _UniffiFfiConverterTypeBackupSecrets:
1645
+ @staticmethod
1646
+ def lift(value: int) -> BackupSecrets:
1647
+ return BackupSecrets._uniffi_make_instance(value)
1648
+
1649
+ @staticmethod
1650
+ def check_lower(value: BackupSecrets):
1651
+ if not isinstance(value, BackupSecrets):
1652
+ raise TypeError("Expected BackupSecrets instance, {} found".format(type(value).__name__))
1653
+
1654
+ @staticmethod
1655
+ def lower(value: BackupSecrets) -> ctypes.c_uint64:
1656
+ return value._uniffi_clone_handle()
1657
+
1658
+ @classmethod
1659
+ def read(cls, buf: _UniffiRustBuffer) -> BackupSecrets:
1660
+ ptr = buf.read_u64()
1661
+ if ptr == 0:
1662
+ raise InternalError("Raw handle value was null")
1663
+ return cls.lift(ptr)
1664
+
1665
+ @classmethod
1666
+ def write(cls, value: BackupSecrets, buf: _UniffiRustBuffer):
1667
+ buf.write_u64(cls.lower(value))
1668
+
1669
+
1670
+ class CrossSigningSecretsProtocol(typing.Protocol):
1671
+ """
1672
+ Data for the secrets bundle containing the cross-signing keys.
1673
+ """
1674
+
1675
+ pass
1676
+
1677
+ class CrossSigningSecrets(CrossSigningSecretsProtocol):
1678
+ """
1679
+ Data for the secrets bundle containing the cross-signing keys.
1680
+ """
1681
+
1682
+ _handle: ctypes.c_uint64
1683
+
1684
+ def __init__(self, *args, **kwargs):
1685
+ raise ValueError("This class has no default constructor")
1686
+
1687
+ def __del__(self):
1688
+ # In case of partial initialization of instances.
1689
+ handle = getattr(self, "_handle", None)
1690
+ if handle is not None:
1691
+ _uniffi_rust_call(_UniffiLib.uniffi_matrix_sdk_crypto_fn_free_crosssigningsecrets, handle)
1692
+
1693
+ def _uniffi_clone_handle(self):
1694
+ return _uniffi_rust_call(_UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_crosssigningsecrets, self._handle)
1695
+
1696
+ # Used by alternative constructors or any methods which return this type.
1697
+ @classmethod
1698
+ def _uniffi_make_instance(cls, handle):
1699
+ # Lightly yucky way to bypass the usual __init__ logic
1700
+ # and just create a new instance with the required handle.
1701
+ inst = cls.__new__(cls)
1702
+ inst._handle = handle
1703
+ return inst
1704
+
1705
+
1706
+
1707
+
1708
+
1709
+ class _UniffiFfiConverterTypeCrossSigningSecrets:
1710
+ @staticmethod
1711
+ def lift(value: int) -> CrossSigningSecrets:
1712
+ return CrossSigningSecrets._uniffi_make_instance(value)
1713
+
1714
+ @staticmethod
1715
+ def check_lower(value: CrossSigningSecrets):
1716
+ if not isinstance(value, CrossSigningSecrets):
1717
+ raise TypeError("Expected CrossSigningSecrets instance, {} found".format(type(value).__name__))
1718
+
1719
+ @staticmethod
1720
+ def lower(value: CrossSigningSecrets) -> ctypes.c_uint64:
1721
+ return value._uniffi_clone_handle()
1722
+
1723
+ @classmethod
1724
+ def read(cls, buf: _UniffiRustBuffer) -> CrossSigningSecrets:
1725
+ ptr = buf.read_u64()
1726
+ if ptr == 0:
1727
+ raise InternalError("Raw handle value was null")
1728
+ return cls.lift(ptr)
1729
+
1730
+ @classmethod
1731
+ def write(cls, value: CrossSigningSecrets, buf: _UniffiRustBuffer):
1732
+ buf.write_u64(cls.lower(value))
1733
+
1734
+
1735
+ class SecretsBundleProtocol(typing.Protocol):
1736
+ """
1737
+ Struct containing the bundle of secrets to fully activate a new device for
1738
+ end-to-end encryption.
1739
+ """
1740
+
1741
+ pass
1742
+
1743
+ class SecretsBundle(SecretsBundleProtocol):
1744
+ """
1745
+ Struct containing the bundle of secrets to fully activate a new device for
1746
+ end-to-end encryption.
1747
+ """
1748
+
1749
+ _handle: ctypes.c_uint64
1750
+
1751
+ def __init__(self, *args, **kwargs):
1752
+ raise ValueError("This class has no default constructor")
1753
+
1754
+ def __del__(self):
1755
+ # In case of partial initialization of instances.
1756
+ handle = getattr(self, "_handle", None)
1757
+ if handle is not None:
1758
+ _uniffi_rust_call(_UniffiLib.uniffi_matrix_sdk_crypto_fn_free_secretsbundle, handle)
1759
+
1760
+ def _uniffi_clone_handle(self):
1761
+ return _uniffi_rust_call(_UniffiLib.uniffi_matrix_sdk_crypto_fn_clone_secretsbundle, self._handle)
1762
+
1763
+ # Used by alternative constructors or any methods which return this type.
1764
+ @classmethod
1765
+ def _uniffi_make_instance(cls, handle):
1766
+ # Lightly yucky way to bypass the usual __init__ logic
1767
+ # and just create a new instance with the required handle.
1768
+ inst = cls.__new__(cls)
1769
+ inst._handle = handle
1770
+ return inst
1771
+
1772
+
1773
+
1774
+
1775
+
1776
+ class _UniffiFfiConverterTypeSecretsBundle:
1777
+ @staticmethod
1778
+ def lift(value: int) -> SecretsBundle:
1779
+ return SecretsBundle._uniffi_make_instance(value)
1780
+
1781
+ @staticmethod
1782
+ def check_lower(value: SecretsBundle):
1783
+ if not isinstance(value, SecretsBundle):
1784
+ raise TypeError("Expected SecretsBundle instance, {} found".format(type(value).__name__))
1785
+
1786
+ @staticmethod
1787
+ def lower(value: SecretsBundle) -> ctypes.c_uint64:
1788
+ return value._uniffi_clone_handle()
1789
+
1790
+ @classmethod
1791
+ def read(cls, buf: _UniffiRustBuffer) -> SecretsBundle:
1792
+ ptr = buf.read_u64()
1793
+ if ptr == 0:
1794
+ raise InternalError("Raw handle value was null")
1795
+ return cls.lift(ptr)
1796
+
1797
+ @classmethod
1798
+ def write(cls, value: SecretsBundle, buf: _UniffiRustBuffer):
1799
+ buf.write_u64(cls.lower(value))
1800
+
1801
+ class _UniffiFfiConverterUInt8(_UniffiConverterPrimitiveInt):
1802
+ CLASS_NAME = "u8"
1803
+ VALUE_MIN = 0
1804
+ VALUE_MAX = 2**8
1805
+
1806
+ @staticmethod
1807
+ def read(buf):
1808
+ return buf.read_u8()
1809
+
1810
+ @staticmethod
1811
+ def write(value, buf):
1812
+ buf.write_u8(value)
1813
+
1814
+ class _UniffiFfiConverterUInt64(_UniffiConverterPrimitiveInt):
1815
+ CLASS_NAME = "u64"
1816
+ VALUE_MIN = 0
1817
+ VALUE_MAX = 2**64
1818
+
1819
+ @staticmethod
1820
+ def read(buf):
1821
+ return buf.read_u64()
1822
+
1823
+ @staticmethod
1824
+ def write(value, buf):
1825
+ buf.write_u64(value)
1826
+
1827
+ class _UniffiFfiConverterString:
1828
+ @staticmethod
1829
+ def check_lower(value):
1830
+ if not isinstance(value, str):
1831
+ raise TypeError("argument must be str, not {}".format(type(value).__name__))
1832
+ return value
1833
+
1834
+ @staticmethod
1835
+ def read(buf):
1836
+ size = buf.read_i32()
1837
+ if size < 0:
1838
+ raise InternalError("Unexpected negative string length")
1839
+ utf8_bytes = buf.read(size)
1840
+ return utf8_bytes.decode("utf-8")
1841
+
1842
+ @staticmethod
1843
+ def write(value, buf):
1844
+ utf8_bytes = value.encode("utf-8")
1845
+ buf.write_i32(len(utf8_bytes))
1846
+ buf.write(utf8_bytes)
1847
+
1848
+ @staticmethod
1849
+ def lift(buf):
1850
+ with buf.consume_with_stream() as stream:
1851
+ return stream.read(stream.remaining()).decode("utf-8")
1852
+
1853
+ @staticmethod
1854
+ def lower(value):
1855
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
1856
+ builder.write(value.encode("utf-8"))
1857
+ return builder.finalize()
1858
+
1859
+ __all__ = [
1860
+ "InternalError",
1861
+ "TrustRequirement",
1862
+ "CollectStrategy",
1863
+ "IdentityState",
1864
+ "LocalTrust",
1865
+ "LoginQrCodeDecodeError",
1866
+ "QrCodeIntent",
1867
+ "SignatureState",
1868
+ "UtdCause",
1869
+ "DecryptionSettings",
1870
+ "BackupSecrets",
1871
+ "BackupSecretsProtocol",
1872
+ "CrossSigningSecrets",
1873
+ "CrossSigningSecretsProtocol",
1874
+ "SecretsBundle",
1875
+ "SecretsBundleProtocol",
1876
+ ]