diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index bb6e4bbf..4b2cc944 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -452,7 +452,7 @@ struct UpdateFolderData { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct UpdateEmergencyAccessData { - id: String, + id: EmergencyAccessId, key_encrypted: String, } @@ -508,9 +508,9 @@ fn validate_keydata( // Check that we're correctly rotating all the user's emergency access keys let existing_emergency_access_ids = - existing_emergency_access.iter().map(|ea| ea.uuid.as_str()).collect::>(); + existing_emergency_access.iter().map(|ea| &ea.uuid).collect::>(); let provided_emergency_access_ids = - data.emergency_access_keys.iter().map(|ea| ea.id.as_str()).collect::>(); + data.emergency_access_keys.iter().map(|ea| &ea.id).collect::>(); if !provided_emergency_access_ids.is_superset(&existing_emergency_access_ids) { err!("All existing emergency access keys must be included in the rotation") } diff --git a/src/db/models/emergency_access.rs b/src/db/models/emergency_access.rs index 429092ea..3480d921 100644 --- a/src/db/models/emergency_access.rs +++ b/src/db/models/emergency_access.rs @@ -1,4 +1,5 @@ use chrono::{NaiveDateTime, Utc}; +use derive_more::{AsRef, Deref, Display, From}; use serde_json::Value; use crate::{api::EmptyResult, db::DbConn, error::MapResult}; @@ -11,7 +12,7 @@ db_object! { #[diesel(treat_none_as_null = true)] #[diesel(primary_key(uuid))] pub struct EmergencyAccess { - pub uuid: String, + pub uuid: EmergencyAccessId, pub grantor_uuid: UserId, pub grantee_uuid: Option, pub email: Option, @@ -33,7 +34,7 @@ impl EmergencyAccess { let now = Utc::now().naive_utc(); Self { - uuid: crate::util::get_uuid(), + uuid: EmergencyAccessId(crate::util::get_uuid()), grantor_uuid, grantee_uuid: None, email: Some(email), @@ -349,3 +350,8 @@ impl EmergencyAccess { } // endregion + +#[derive( + Clone, Debug, AsRef, Deref, DieselNewType, Display, From, FromForm, Hash, PartialEq, Eq, Serialize, Deserialize, +)] +pub struct EmergencyAccessId(String); diff --git a/src/db/models/mod.rs b/src/db/models/mod.rs index d503354c..a78c4a9a 100644 --- a/src/db/models/mod.rs +++ b/src/db/models/mod.rs @@ -21,7 +21,7 @@ pub use self::auth_request::{AuthRequest, AuthRequestId}; pub use self::cipher::{Cipher, CipherId, RepromptType}; pub use self::collection::{Collection, CollectionCipher, CollectionId, CollectionUser}; pub use self::device::{Device, DeviceId, DeviceType}; -pub use self::emergency_access::{EmergencyAccess, EmergencyAccessStatus, EmergencyAccessType}; +pub use self::emergency_access::{EmergencyAccess, EmergencyAccessId, EmergencyAccessStatus, EmergencyAccessType}; pub use self::event::{Event, EventType}; pub use self::favorite::Favorite; pub use self::folder::{Folder, FolderCipher, FolderId};