pub trait UserKeysQueries: Database {
Show 16 methods
// Provided methods
async fn upsert_device_keys(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
key: &DeviceKeys,
) -> Result<i64, DatabaseError> { ... }
async fn import_cross_signing_key(
&mut self,
user_id: &UserId,
key_type: DbKeyType,
key: &CrossSigningKey,
) -> Result<bool, DatabaseError> { ... }
async fn resolve_user_key(
&mut self,
user_id: &UserId,
key_id: &CrossSigningOrDeviceSigningKeyId,
) -> Result<Option<UserKeyRef>, DatabaseError> { ... }
async fn resolve_device_user_key(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
) -> Result<Option<UserKeyRef>, DatabaseError> { ... }
async fn resolve_cross_signing_user_key(
&mut self,
user_id: &UserId,
key_id: &str,
) -> Result<Option<UserKeyRef>, DatabaseError> { ... }
async fn import_device_keys(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
key: &DeviceKeys,
) -> Result<bool, DatabaseError> { ... }
async fn fetch_device_keys_for_users(
&mut self,
device_keys: &BTreeMap<OwnedUserId, Vec<OwnedDeviceId>>,
) -> Result<BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, DeviceKeysRow>>, DatabaseError> { ... }
async fn fetch_single_cross_signing_key_for_user(
&mut self,
user_id: &UserId,
key_type: DbKeyType,
) -> Result<Option<CrossSigningKey>, DatabaseError> { ... }
async fn fetch_allowed_cross_signing_keys(
&mut self,
requester: Option<&UserId>,
user_ids: &[OwnedUserId],
) -> Result<HashMap<OwnedUserId, HashMap<DbKeyType, CrossSigningKeyRow>>, DatabaseError> { ... }
async fn fetch_cross_signing_keys_ids_for_user(
&mut self,
user_id: &UserId,
) -> Result<Vec<String>, DatabaseError> { ... }
async fn upsert_cross_signing_key(
&mut self,
user_id: &UserId,
key_type: DbKeyType,
key: &CrossSigningKey,
) -> Result<i64, DatabaseError> { ... }
async fn fetch_user_keys(
&mut self,
requested_keys: &[(OwnedUserId, Vec<DbKeyType>)],
) -> Result<BTreeMap<OwnedUserId, Vec<UserKeyRow>>, DatabaseError> { ... }
async fn fetch_sync_user_keys_changes(
&mut self,
user_id: &UserId,
from_event_stream_id: StreamId,
from_keys_stream_id: StreamId,
) -> Result<Vec<ChangedUserKeys>, DatabaseError> { ... }
async fn fetch_sync_user_keys_left(
&mut self,
user_id: &UserId,
from_event_stream_id: StreamId,
) -> Result<Vec<OwnedUserId>, DatabaseError> { ... }
async fn fetch_otk_counts(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
) -> Result<BTreeMap<OneTimeKeyAlgorithm, UInt>, DatabaseError> { ... }
async fn fetch_current_user_keys_stream_id(
&mut self,
) -> Result<StreamId, DatabaseError> { ... }
}Expand description
Queries related to the user_keys table.
Provided Methods§
Sourceasync fn upsert_device_keys(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
key: &DeviceKeys,
) -> Result<i64, DatabaseError>
async fn upsert_device_keys( &mut self, user_id: &UserId, device_id: &DeviceId, key: &DeviceKeys, ) -> Result<i64, DatabaseError>
Inserts device keys for a given user and device, and returns its NID.
§Conflict resolution
If the given device_id is already present in the table, its row gets
updated with the new key_object value if and only if the new
one is different.
Sourceasync fn import_cross_signing_key(
&mut self,
user_id: &UserId,
key_type: DbKeyType,
key: &CrossSigningKey,
) -> Result<bool, DatabaseError>
async fn import_cross_signing_key( &mut self, user_id: &UserId, key_type: DbKeyType, key: &CrossSigningKey, ) -> Result<bool, DatabaseError>
Imports a cross-signing key for a given user idempotently.
Returns true if a new cross-signing key was inserted, false if one already exists
Sourceasync fn resolve_user_key(
&mut self,
user_id: &UserId,
key_id: &CrossSigningOrDeviceSigningKeyId,
) -> Result<Option<UserKeyRef>, DatabaseError>
async fn resolve_user_key( &mut self, user_id: &UserId, key_id: &CrossSigningOrDeviceSigningKeyId, ) -> Result<Option<UserKeyRef>, DatabaseError>
Resolves a user_keys row by user id and key id, returning a
UserKeyRef if found, or None if no matching row exists.
The key_id is matched against both the stored key_id column (device
keys, stored as "ed25519:<device_id>") and against keys embedded in
key_object->'keys' (cross-signing keys, where the key id is a field
name inside the JSON object). This dual match handles both device keys
and cross-signing keys with a single query.
Returns None when:
- The user does not exist in the
userstable (e.g. a remote user whose keys were never imported). - No
user_keysrow matches the givenkey_id.
Sourceasync fn resolve_device_user_key(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
) -> Result<Option<UserKeyRef>, DatabaseError>
async fn resolve_device_user_key( &mut self, user_id: &UserId, device_id: &DeviceId, ) -> Result<Option<UserKeyRef>, DatabaseError>
Resolves a device user_keys row by user id and bare device id
(the key_type = 'device' row whose device has this device_id).
Cross-signing signatures name their signed target by bare device id,
which does not match the stored key_id (ed25519:<device_id>) nor a
key_object->'keys' field, so Self::resolve_user_key cannot find
it. This is the device branch of the ADR’s signed-key resolution.
Returns None if the user, device, or its device-keys row is absent.
Sourceasync fn resolve_cross_signing_user_key(
&mut self,
user_id: &UserId,
key_id: &str,
) -> Result<Option<UserKeyRef>, DatabaseError>
async fn resolve_cross_signing_user_key( &mut self, user_id: &UserId, key_id: &str, ) -> Result<Option<UserKeyRef>, DatabaseError>
Resolves a cross-signing user_keys row (device_nid IS NULL) by
user id and the key id a cross-signing signature names its target by.
Synapse names a signed cross-signing-key target by its bare public
key (e.g. "<pubkey>"), while arminius stores that key id with its
algorithm prefix ("ed25519:<pubkey>"), both in the key_id column and
as the field name inside key_object->'keys'.
Self::resolve_user_key only matches the exact stored form, so a
bare target never resolves. This method matches the bare id (by
prefixing it) as well as the already prefixed form, scoped to
cross-signing rows so it can never collide with a device key. This is
the cross-signing-key branch of the ADR’s signed-key resolution (the
device branch is Self::resolve_device_user_key).
Returns None if the user has no matching cross-signing key.
Sourceasync fn import_device_keys(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
key: &DeviceKeys,
) -> Result<bool, DatabaseError>
async fn import_device_keys( &mut self, user_id: &UserId, device_id: &DeviceId, key: &DeviceKeys, ) -> Result<bool, DatabaseError>
Imports device keys for a given user and device idempotently.
Inserts into user_keys with key_type='device' and returns true if
a new row was inserted. If a row for the same (key_type, user_nid, device_nid) already exists, the insert is skipped and false is
returned, making this safe to replay and resume.
Sourceasync fn fetch_device_keys_for_users(
&mut self,
device_keys: &BTreeMap<OwnedUserId, Vec<OwnedDeviceId>>,
) -> Result<BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, DeviceKeysRow>>, DatabaseError>
async fn fetch_device_keys_for_users( &mut self, device_keys: &BTreeMap<OwnedUserId, Vec<OwnedDeviceId>>, ) -> Result<BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, DeviceKeysRow>>, DatabaseError>
Given a list of users, and an optional list of device IDs for each user, fetches all of their device keys.
NOTE: If the list of device IDs is empty for a user, fetches all of their keys (instead of only the ones of that list).
Sourceasync fn fetch_single_cross_signing_key_for_user(
&mut self,
user_id: &UserId,
key_type: DbKeyType,
) -> Result<Option<CrossSigningKey>, DatabaseError>
async fn fetch_single_cross_signing_key_for_user( &mut self, user_id: &UserId, key_type: DbKeyType, ) -> Result<Option<CrossSigningKey>, DatabaseError>
Fetches a single cross-signing key from the database.
Sourceasync fn fetch_allowed_cross_signing_keys(
&mut self,
requester: Option<&UserId>,
user_ids: &[OwnedUserId],
) -> Result<HashMap<OwnedUserId, HashMap<DbKeyType, CrossSigningKeyRow>>, DatabaseError>
async fn fetch_allowed_cross_signing_keys( &mut self, requester: Option<&UserId>, user_ids: &[OwnedUserId], ) -> Result<HashMap<OwnedUserId, HashMap<DbKeyType, CrossSigningKeyRow>>, DatabaseError>
Fetches all the cross-signing keys for the given list of user_ids.
This query can be performed by both by the client API (when a local user
requests local keys) and by the Federation Input API (when a foreign
homeserver requests local keys). Additionally, the only case this query
should return a User-Signing key is when it is that of a local user
requesting their own keys. This is what the requester parameter is
used for, and it should only be set in the local-keys-fetching scenario.
This returns a map from [OwnedUserId] to a map from DbKeyType to
[CrossSigningKey].
Sourceasync fn fetch_cross_signing_keys_ids_for_user(
&mut self,
user_id: &UserId,
) -> Result<Vec<String>, DatabaseError>
async fn fetch_cross_signing_keys_ids_for_user( &mut self, user_id: &UserId, ) -> Result<Vec<String>, DatabaseError>
Fetches all of a user’s cross-signing keys IDs.
Sourceasync fn upsert_cross_signing_key(
&mut self,
user_id: &UserId,
key_type: DbKeyType,
key: &CrossSigningKey,
) -> Result<i64, DatabaseError>
async fn upsert_cross_signing_key( &mut self, user_id: &UserId, key_type: DbKeyType, key: &CrossSigningKey, ) -> Result<i64, DatabaseError>
Inserts the given cross-signing keys.
§Conflict resolution
If a key already exists for the given key_type+user_id, its row gets
updated with the new key_id and key_object if and only if the new
key_object is different than the stored one. If they are the same,
nothing happens.
Sourceasync fn fetch_user_keys(
&mut self,
requested_keys: &[(OwnedUserId, Vec<DbKeyType>)],
) -> Result<BTreeMap<OwnedUserId, Vec<UserKeyRow>>, DatabaseError>
async fn fetch_user_keys( &mut self, requested_keys: &[(OwnedUserId, Vec<DbKeyType>)], ) -> Result<BTreeMap<OwnedUserId, Vec<UserKeyRow>>, DatabaseError>
Fetches all the user keys for the given users.
If the list of key types is empty, fetches all the types.
Sourceasync fn fetch_sync_user_keys_changes(
&mut self,
user_id: &UserId,
from_event_stream_id: StreamId,
from_keys_stream_id: StreamId,
) -> Result<Vec<ChangedUserKeys>, DatabaseError>
async fn fetch_sync_user_keys_changes( &mut self, user_id: &UserId, from_event_stream_id: StreamId, from_keys_stream_id: StreamId, ) -> Result<Vec<ChangedUserKeys>, DatabaseError>
Returns the list of users that either:
- Updated their device identity or cross-signing keys after the given
from_keys_stream_id - Joined a room shared with
user_idafter the givenfrom_event_stream_id
Or our own user name, if we changed our device keys
Sourceasync fn fetch_sync_user_keys_left(
&mut self,
user_id: &UserId,
from_event_stream_id: StreamId,
) -> Result<Vec<OwnedUserId>, DatabaseError>
async fn fetch_sync_user_keys_left( &mut self, user_id: &UserId, from_event_stream_id: StreamId, ) -> Result<Vec<OwnedUserId>, DatabaseError>
Returns the list of users that no longer share any encrypted rooms since
the given from_event_stream_id.
Sourceasync fn fetch_otk_counts(
&mut self,
user_id: &UserId,
device_id: &DeviceId,
) -> Result<BTreeMap<OneTimeKeyAlgorithm, UInt>, DatabaseError>
async fn fetch_otk_counts( &mut self, user_id: &UserId, device_id: &DeviceId, ) -> Result<BTreeMap<OneTimeKeyAlgorithm, UInt>, DatabaseError>
Fetches the count of non-used one-time keys for the given user.
Sourceasync fn fetch_current_user_keys_stream_id(
&mut self,
) -> Result<StreamId, DatabaseError>
async fn fetch_current_user_keys_stream_id( &mut self, ) -> Result<StreamId, DatabaseError>
Fetches the highest stream ID ever issued for the user_keys_streamids stream.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".