feat: Port SignatureListItem to Rust

This commit is contained in:
Skye Elliot
2026-05-05 13:24:34 +01:00
parent 3e6bf10640
commit eb39d4e202
5 changed files with 116 additions and 17 deletions
+83
View File
@@ -0,0 +1,83 @@
/*
* This file is licensed under the Affero General Public License (AGPL) version 3.
*
* Copyright (C) 2026 Element Creations Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* See the GNU Affero General Public License for more details:
* <https://www.gnu.org/licenses/agpl-3.0.html>.
*
* Originally licensed under the Apache License, Version 2.0:
* <http://www.apache.org/licenses/LICENSE-2.0>.
*
* [This file includes modifications made by Element Creations Ltd]
*/
use pyo3::{
pyclass, pymethods,
types::{PyAnyMethods, PyModule, PyModuleMethods},
Bound, Py, PyAny, PyResult, Python,
};
pub fn register_module(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
let child_module = PyModule::new(py, "e2e_keys")?;
child_module.add_class::<SignatureListItem>()?;
m.add_submodule(&child_module)?;
py.import("sys")?
.getattr("modules")?
.set_item("synapse.synapse_rust.e2e_keys", child_module)?;
Ok(())
}
/// A pending cross-signing signature.
#[derive(Debug)]
#[pyclass(frozen)]
pub struct SignatureListItem {
/// Full key ID of the signing key, e.g. `"ed25519:ABCDEF"`.
#[pyo3(get)]
pub signing_key_id: String,
/// User whose key was signed.
#[pyo3(get)]
pub target_user_id: String,
/// Device ID (or master-key ID) that the signature targets.
#[pyo3(get)]
pub target_device_id: String,
/// Raw signature value.
#[pyo3(get)]
pub signature: Py<PyAny>,
}
#[pymethods]
impl SignatureListItem {
#[new]
fn py_new(
signing_key_id: String,
target_user_id: String,
target_device_id: String,
signature: Py<PyAny>,
) -> Self {
Self {
signing_key_id,
target_user_id,
target_device_id,
signature,
}
}
fn __repr__(&self) -> String {
format!(
"SignatureListItem(signing_key_id={:?}, target_user_id={:?}, target_device_id={:?})",
self.signing_key_id, self.target_user_id, self.target_device_id,
)
}
}
+2
View File
@@ -7,6 +7,7 @@ use pyo3_log::ResetHandle;
pub mod acl;
pub mod canonical_json;
pub mod duration;
pub mod e2e_keys;
pub mod errors;
pub mod events;
pub mod http;
@@ -64,6 +65,7 @@ fn synapse_rust(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
acl::register_module(py, m)?;
push::register_module(py, m)?;
e2e_keys::register_module(py, m)?;
events::register_module(py, m)?;
http_client::register_module(py, m)?;
rendezvous::register_module(py, m)?;