lb_rs/model/
meta.rs

1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4use super::access_info::{EncryptedFolderAccessKey, UserAccessInfo};
5use super::file_metadata::{DocumentHmac, FileType, Owner};
6use super::secret_filename::SecretFileName;
7
8#[derive(Serialize, Deserialize, Clone, Debug)]
9pub enum Meta {
10    V1 {
11        id: Uuid,
12        file_type: FileType,
13        parent: Uuid,
14        name: SecretFileName,
15        owner: Owner,
16        is_deleted: bool,
17        doc_size: Option<usize>,
18        doc_hmac: Option<DocumentHmac>,
19        user_access_keys: Vec<UserAccessInfo>,
20        folder_access_key: EncryptedFolderAccessKey,
21    },
22}
23
24impl Meta {
25    pub fn doc_size(&self) -> &Option<usize> {
26        match self {
27            Meta::V1 { doc_size, .. } => doc_size,
28        }
29    }
30}
31
32// This is impl'd to avoid comparing encrypted values
33impl PartialEq for Meta {
34    fn eq(&self, other: &Self) -> bool {
35        match (self, other) {
36            (
37                Meta::V1 {
38                    id,
39                    file_type,
40                    parent,
41                    name,
42                    owner,
43                    is_deleted,
44                    doc_hmac,
45                    user_access_keys,
46                    // todo: verify that ignoring this is intentional
47                    folder_access_key: _,
48                    doc_size,
49                },
50                Meta::V1 {
51                    id: other_id,
52                    file_type: other_file_type,
53                    parent: other_parent,
54                    name: other_name,
55                    owner: other_owner,
56                    is_deleted: other_is_deleted,
57                    doc_hmac: other_doc_hmac,
58                    user_access_keys: other_user_access_keys,
59                    // todo: verify that ignoring this is intentional
60                    folder_access_key: _other_folder_access_key,
61                    doc_size: other_doc_size,
62                },
63            ) => {
64                id == other_id
65                    && file_type == other_file_type
66                    && parent == other_parent
67                    && name == other_name
68                    && owner == other_owner
69                    && is_deleted == other_is_deleted
70                    && doc_hmac == other_doc_hmac
71                    && user_access_keys == other_user_access_keys
72                    && doc_size == other_doc_size
73            }
74        }
75    }
76}