crypto: Use DeviceId instead of str everywhere.

master
Damir Jelić 2020-07-21 10:48:15 +02:00
parent b22324b305
commit fe33430e9b
3 changed files with 8 additions and 8 deletions

View File

@ -164,7 +164,7 @@ impl OlmMachine {
/// * `device_id` - The unique id of the device that owns this machine. /// * `device_id` - The unique id of the device that owns this machine.
pub async fn new_with_default_store<P: AsRef<Path>>( pub async fn new_with_default_store<P: AsRef<Path>>(
user_id: &UserId, user_id: &UserId,
device_id: &str, device_id: &DeviceId,
path: P, path: P,
passphrase: &str, passphrase: &str,
) -> StoreResult<Self> { ) -> StoreResult<Self> {

View File

@ -140,7 +140,7 @@ pub struct UserDevices {
impl UserDevices { impl UserDevices {
/// Get the specific device with the given device id. /// Get the specific device with the given device id.
pub fn get(&self, device_id: &str) -> Option<Device> { pub fn get(&self, device_id: &DeviceId) -> Option<Device> {
self.entries.get(device_id).cloned() self.entries.get(device_id).cloned()
} }
@ -180,7 +180,7 @@ impl DeviceStore {
} }
/// Get the device with the given device_id and belonging to the given user. /// Get the device with the given device_id and belonging to the given user.
pub fn get(&self, user_id: &UserId, device_id: &str) -> Option<Device> { pub fn get(&self, user_id: &UserId, device_id: &DeviceId) -> Option<Device> {
self.entries self.entries
.get(user_id) .get(user_id)
.and_then(|m| m.get(device_id).map(|d| d.value().clone())) .and_then(|m| m.get(device_id).map(|d| d.value().clone()))
@ -189,7 +189,7 @@ impl DeviceStore {
/// Remove the device with the given device_id and belonging to the given user. /// Remove the device with the given device_id and belonging to the given user.
/// ///
/// Returns the device if it was removed, None if it wasn't in the store. /// Returns the device if it was removed, None if it wasn't in the store.
pub fn remove(&self, user_id: &UserId, device_id: &str) -> Option<Device> { pub fn remove(&self, user_id: &UserId, device_id: &DeviceId) -> Option<Device> {
self.entries self.entries
.get(user_id) .get(user_id)
.and_then(|m| m.remove(device_id)) .and_then(|m| m.remove(device_id))

View File

@ -66,7 +66,7 @@ impl SqliteStore {
/// * `path` - The path where the database file should reside in. /// * `path` - The path where the database file should reside in.
pub async fn open<P: AsRef<Path>>( pub async fn open<P: AsRef<Path>>(
user_id: &UserId, user_id: &UserId,
device_id: &str, device_id: &DeviceId,
path: P, path: P,
) -> Result<SqliteStore> { ) -> Result<SqliteStore> {
SqliteStore::open_helper(user_id, device_id, path, None).await SqliteStore::open_helper(user_id, device_id, path, None).await
@ -88,7 +88,7 @@ impl SqliteStore {
/// the encryption keys. /// the encryption keys.
pub async fn open_with_passphrase<P: AsRef<Path>>( pub async fn open_with_passphrase<P: AsRef<Path>>(
user_id: &UserId, user_id: &UserId,
device_id: &str, device_id: &DeviceId,
path: P, path: P,
passphrase: &str, passphrase: &str,
) -> Result<SqliteStore> { ) -> Result<SqliteStore> {
@ -109,7 +109,7 @@ impl SqliteStore {
async fn open_helper<P: AsRef<Path>>( async fn open_helper<P: AsRef<Path>>(
user_id: &UserId, user_id: &UserId,
device_id: &str, device_id: &DeviceId,
path: P, path: P,
passphrase: Option<Zeroizing<String>>, passphrase: Option<Zeroizing<String>>,
) -> Result<SqliteStore> { ) -> Result<SqliteStore> {
@ -804,7 +804,7 @@ mod test {
use super::{Account, CryptoStore, InboundGroupSession, RoomId, Session, SqliteStore, TryFrom}; use super::{Account, CryptoStore, InboundGroupSession, RoomId, Session, SqliteStore, TryFrom};
static USER_ID: &str = "@example:localhost"; static USER_ID: &str = "@example:localhost";
static DEVICE_ID: &str = "DEVICEID"; static DEVICE_ID: &DeviceId = "DEVICEID";
async fn get_store(passphrase: Option<&str>) -> (SqliteStore, tempfile::TempDir) { async fn get_store(passphrase: Option<&str>) -> (SqliteStore, tempfile::TempDir) {
let tmpdir = tempdir().unwrap(); let tmpdir = tempdir().unwrap();