sentc_crypto_common/
file.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3
4use serde::{Deserialize, Serialize};
5
6use crate::crypto::SignHead;
7use crate::{FileId, FileSessionId, GeneralIdFormat, PartId, UserId};
8
9/**
10# Who has access to this file
11
12When group or user, then the belongs_to must be Some(id)
13
14The api checks if the user got access to this:
15- for user -> check if belongs_to is the same as the user id
16- for group -> check if the user is in this group
17*/
18#[derive(Serialize, Deserialize)]
19pub enum BelongsToType
20{
21	Group,
22	User,
23	None,
24}
25
26#[derive(Serialize, Deserialize)]
27pub struct FilePartListItem
28{
29	pub part_id: PartId,
30	pub sequence: i32,
31	pub extern_storage: bool,
32}
33
34#[derive(Serialize, Deserialize)]
35pub struct FileData
36{
37	pub file_id: FileId,
38	pub master_key_id: String,
39	pub owner: UserId,
40	pub belongs_to: Option<GeneralIdFormat>, //can be a group or a user. if belongs to type is none then this is Option::None
41	pub belongs_to_type: BelongsToType,
42	pub encrypted_key: String,
43	pub encrypted_key_alg: String,
44	pub encrypted_file_name: Option<String>,
45	pub part_list: Vec<FilePartListItem>,
46}
47
48//__________________________________________________________________________________________________
49
50#[derive(Serialize, Deserialize)]
51pub struct FileRegisterInput
52{
53	pub encrypted_key: String,
54	pub encrypted_key_alg: String,
55	pub master_key_id: String, //can be group key or user private / public key pair id
56	pub belongs_to_id: Option<GeneralIdFormat>,
57	pub belongs_to_type: BelongsToType,
58	pub encrypted_file_name: Option<String>,
59}
60
61#[derive(Serialize, Deserialize)]
62pub struct FileRegisterOutput
63{
64	pub file_id: FileId,
65	pub session_id: FileSessionId,
66}
67
68#[derive(Serialize, Deserialize)]
69pub struct FileNameUpdate
70{
71	pub encrypted_file_name: Option<String>,
72}
73
74#[derive(Serialize, Deserialize)]
75pub struct FilePartRegisterOutput
76{
77	pub part_id: PartId,
78}
79
80//__________________________________________________________________________________________________
81
82#[derive(Serialize, Deserialize)]
83pub struct FileHead
84{
85	pub key: String,
86	pub sign: Option<SignHead>,
87	pub sym_key_alg: String,
88}