1dfe32fa1Soh_ci/*
2dfe32fa1Soh_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3dfe32fa1Soh_ci * Licensed under the Apache License, Version 2.0 (the "License");
4dfe32fa1Soh_ci * you may not use this file except in compliance with the License.
5dfe32fa1Soh_ci * You may obtain a copy of the License at
6dfe32fa1Soh_ci *
7dfe32fa1Soh_ci *     http://www.apache.org/licenses/LICENSE-2.0
8dfe32fa1Soh_ci *
9dfe32fa1Soh_ci * Unless required by applicable law or agreed to in writing, software
10dfe32fa1Soh_ci * distributed under the License is distributed on an "AS IS" BASIS,
11dfe32fa1Soh_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12dfe32fa1Soh_ci * See the License for the specific language governing permissions and
13dfe32fa1Soh_ci * limitations under the License.
14dfe32fa1Soh_ci */
15dfe32fa1Soh_ci
16dfe32fa1Soh_ci//! This module defines asset-related data structures.
17dfe32fa1Soh_ci
18dfe32fa1Soh_ciuse std::collections::HashMap;
19dfe32fa1Soh_ci
20dfe32fa1Soh_cimod extension;
21dfe32fa1Soh_ci#[macro_use]
22dfe32fa1Soh_cipub mod macros;
23dfe32fa1Soh_ci
24dfe32fa1Soh_ciimpl_enum_trait! {
25dfe32fa1Soh_ci    /// An enum type containing the data type definitions for Asset attribute value.
26dfe32fa1Soh_ci    #[derive(Eq, PartialEq)]
27dfe32fa1Soh_ci    pub enum DataType {
28dfe32fa1Soh_ci        /// The data type of Asset attribute value is bool.
29dfe32fa1Soh_ci        Bool = 1 << 28,
30dfe32fa1Soh_ci
31dfe32fa1Soh_ci        /// The data type of Asset attribute value is uint32.
32dfe32fa1Soh_ci        Number = 2 << 28,
33dfe32fa1Soh_ci
34dfe32fa1Soh_ci        /// The data type of Asset attribute value is byte array.
35dfe32fa1Soh_ci        Bytes = 3 << 28,
36dfe32fa1Soh_ci    }
37dfe32fa1Soh_ci}
38dfe32fa1Soh_ci
39dfe32fa1Soh_ciimpl_tag_trait! {
40dfe32fa1Soh_ci    /// An emum type that indicates the tag of the asset attribute.
41dfe32fa1Soh_ci    #[derive(Clone, Copy)]
42dfe32fa1Soh_ci    #[derive(Debug)]
43dfe32fa1Soh_ci    #[derive(Eq, Hash, PartialEq)]
44dfe32fa1Soh_ci    pub enum Tag {
45dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the sensitive user data such as passwords and tokens.
46dfe32fa1Soh_ci        Secret = DataType::Bytes as isize | 0x01,
47dfe32fa1Soh_ci
48dfe32fa1Soh_ci        /// A tag whose value is a byte array identifying an Asset.
49dfe32fa1Soh_ci        Alias = DataType::Bytes as isize | 0x02,
50dfe32fa1Soh_ci
51dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating when the Asset can be accessed.
52dfe32fa1Soh_ci        Accessibility = DataType::Number as isize | 0x03,
53dfe32fa1Soh_ci
54dfe32fa1Soh_ci        /// A tag whose value is a bool indicating whether a screen lock password is set for the device.
55dfe32fa1Soh_ci        RequirePasswordSet = DataType::Bool as isize | 0x04,
56dfe32fa1Soh_ci
57dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating
58dfe32fa1Soh_ci        /// the user authentication type for Asset access control.
59dfe32fa1Soh_ci        AuthType = DataType::Number as isize | 0x05,
60dfe32fa1Soh_ci
61dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating
62dfe32fa1Soh_ci        /// the validity period in seconds of user authentication.
63dfe32fa1Soh_ci        AuthValidityPeriod = DataType::Number as isize | 0x06,
64dfe32fa1Soh_ci
65dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the authentication challenge for anti-replay protection.
66dfe32fa1Soh_ci        AuthChallenge = DataType::Bytes as isize | 0x07,
67dfe32fa1Soh_ci
68dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the authentication token after a user is verified.
69dfe32fa1Soh_ci        AuthToken = DataType::Bytes as isize | 0x08,
70dfe32fa1Soh_ci
71dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating the type of Asset synchronization.
72dfe32fa1Soh_ci        SyncType = DataType::Number as isize | 0x10,
73dfe32fa1Soh_ci
74dfe32fa1Soh_ci        /// A tag whose value is a bool indicating whether Asset is stored persistently.
75dfe32fa1Soh_ci        IsPersistent = DataType::Bool as isize | 0x11,
76dfe32fa1Soh_ci
77dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the first user-defined Asset data label (not allow to update).
78dfe32fa1Soh_ci        DataLabelCritical1 = DataType::Bytes as isize | 0x20,
79dfe32fa1Soh_ci
80dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the second user-defined Asset data label (not allow to update).
81dfe32fa1Soh_ci        DataLabelCritical2 = DataType::Bytes as isize | 0x21,
82dfe32fa1Soh_ci
83dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the third user-defined Asset data label (not allow to update).
84dfe32fa1Soh_ci        DataLabelCritical3 = DataType::Bytes as isize | 0x22,
85dfe32fa1Soh_ci
86dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the fourth user-defined Asset data label (not allow to update).
87dfe32fa1Soh_ci        DataLabelCritical4 = DataType::Bytes as isize | 0x23,
88dfe32fa1Soh_ci
89dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the first user-defined Asset data label (allow to update).
90dfe32fa1Soh_ci        DataLabelNormal1 = DataType::Bytes as isize | 0x30,
91dfe32fa1Soh_ci
92dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the second user-defined Asset data label (allow to update).
93dfe32fa1Soh_ci        DataLabelNormal2 = DataType::Bytes as isize | 0x31,
94dfe32fa1Soh_ci
95dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the third user-defined Asset data label (allow to update).
96dfe32fa1Soh_ci        DataLabelNormal3 = DataType::Bytes as isize | 0x32,
97dfe32fa1Soh_ci
98dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the fourth user-defined Asset data label (allow to update).
99dfe32fa1Soh_ci        DataLabelNormal4 = DataType::Bytes as isize | 0x33,
100dfe32fa1Soh_ci
101dfe32fa1Soh_ci        /// A local tag whose value is a byte array indicating
102dfe32fa1Soh_ci        /// the first user-defined Asset data label (allow to update).
103dfe32fa1Soh_ci        /// The information of a local tag will not be synchronized.
104dfe32fa1Soh_ci        DataLabelNormalLocal1 = DataType::Bytes as isize | 0x34,
105dfe32fa1Soh_ci
106dfe32fa1Soh_ci        /// A local tag whose value is a byte array indicating
107dfe32fa1Soh_ci        /// the second user-defined Asset data label (allow to update).
108dfe32fa1Soh_ci        /// The information of a local tag will not be synchronized.
109dfe32fa1Soh_ci        DataLabelNormalLocal2 = DataType::Bytes as isize | 0x35,
110dfe32fa1Soh_ci
111dfe32fa1Soh_ci        /// A local tag whose value is a byte array indicating
112dfe32fa1Soh_ci        /// the third user-defined Asset data label (allow to update).
113dfe32fa1Soh_ci        /// The information of a local tag will not be synchronized.
114dfe32fa1Soh_ci        DataLabelNormalLocal3 = DataType::Bytes as isize | 0x36,
115dfe32fa1Soh_ci
116dfe32fa1Soh_ci        /// A local tag whose value is a byte array indicating
117dfe32fa1Soh_ci        /// the fourth user-defined Asset data label (allow to update).
118dfe32fa1Soh_ci        /// The information of a local tag will not be synchronized.
119dfe32fa1Soh_ci        DataLabelNormalLocal4 = DataType::Bytes as isize | 0x37,
120dfe32fa1Soh_ci
121dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating the return type of the queried Asset.
122dfe32fa1Soh_ci        ReturnType = DataType::Number as isize | 0x40,
123dfe32fa1Soh_ci
124dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating the maximum number of returned Assets in a query.
125dfe32fa1Soh_ci        ReturnLimit = DataType::Number as isize | 0x41,
126dfe32fa1Soh_ci
127dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating the offset of return data in batch query.
128dfe32fa1Soh_ci        ReturnOffset = DataType::Number as isize | 0x42,
129dfe32fa1Soh_ci
130dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating how the query results are sorted.
131dfe32fa1Soh_ci        ReturnOrderedBy = DataType::Number as isize | 0x43,
132dfe32fa1Soh_ci
133dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating the strategy for resolving Asset conflicts.
134dfe32fa1Soh_ci        ConflictResolution = DataType::Number as isize | 0x44,
135dfe32fa1Soh_ci
136dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the update time of an Asset.
137dfe32fa1Soh_ci        UpdateTime = DataType::Bytes as isize | 0x45,
138dfe32fa1Soh_ci
139dfe32fa1Soh_ci        /// A tag whose value is a byte array indicating the update time of an Asset.
140dfe32fa1Soh_ci        OperationType = DataType::Number as isize | 0x46,
141dfe32fa1Soh_ci
142dfe32fa1Soh_ci        /// A tag whose value is a bool indicating whether the attributes of an asset are required to be encrypted.
143dfe32fa1Soh_ci        RequireAttrEncrypted = DataType::Bool as isize | 0x47,
144dfe32fa1Soh_ci
145dfe32fa1Soh_ci        /// A tag whose value is a 32-bit unsigned integer indicating the specific user id.
146dfe32fa1Soh_ci        UserId = DataType::Number as isize | 0x100,
147dfe32fa1Soh_ci    }
148dfe32fa1Soh_ci}
149dfe32fa1Soh_ci
150dfe32fa1Soh_ci/// A type that indicates the secret or attribute value of an Asset tag.
151dfe32fa1Soh_ci#[derive(Clone)]
152dfe32fa1Soh_ci#[derive(Debug)]
153dfe32fa1Soh_ci#[derive(Eq, Hash, PartialEq)]
154dfe32fa1Soh_ci#[repr(C)]
155dfe32fa1Soh_cipub enum Value {
156dfe32fa1Soh_ci    /// Asset attribute value, whose data type is bool.
157dfe32fa1Soh_ci    Bool(bool),
158dfe32fa1Soh_ci
159dfe32fa1Soh_ci    /// Asset attribute value, whose data type is number.
160dfe32fa1Soh_ci    Number(u32),
161dfe32fa1Soh_ci
162dfe32fa1Soh_ci    /// Asset attribute value, whose data type is byte array.
163dfe32fa1Soh_ci    Bytes(Vec<u8>),
164dfe32fa1Soh_ci}
165dfe32fa1Soh_ci
166dfe32fa1Soh_ciimpl Drop for Value {
167dfe32fa1Soh_ci    fn drop(&mut self) {
168dfe32fa1Soh_ci        if let Value::Bytes(bytes) = self {
169dfe32fa1Soh_ci            bytes.fill(0);
170dfe32fa1Soh_ci        }
171dfe32fa1Soh_ci    }
172dfe32fa1Soh_ci}
173dfe32fa1Soh_ci
174dfe32fa1Soh_ci/// A Map type containing tag-value pairs that describe the attributes of an Asset.
175dfe32fa1Soh_cipub type AssetMap = HashMap<Tag, Value>;
176dfe32fa1Soh_ci
177dfe32fa1Soh_ciimpl_enum_trait! {
178dfe32fa1Soh_ci    /// An enum type containing the Asset error codes.
179dfe32fa1Soh_ci    #[derive(Clone, Copy)]
180dfe32fa1Soh_ci    #[derive(Debug)]
181dfe32fa1Soh_ci    #[derive(Eq, Hash, PartialEq)]
182dfe32fa1Soh_ci    pub enum ErrCode {
183dfe32fa1Soh_ci        /// The error code indicates that the caller doesn't have the permission.
184dfe32fa1Soh_ci        PermissionDenied = 201,
185dfe32fa1Soh_ci
186dfe32fa1Soh_ci        /// The error code indicates that the caller is not system application.
187dfe32fa1Soh_ci        NotSystemApplication = 202,
188dfe32fa1Soh_ci
189dfe32fa1Soh_ci        /// The error code indicates that the argument is invalid.
190dfe32fa1Soh_ci        InvalidArgument = 401,
191dfe32fa1Soh_ci
192dfe32fa1Soh_ci        /// The error code indicates that the ASSET service is unavailable.
193dfe32fa1Soh_ci        ServiceUnavailable = 24000001,
194dfe32fa1Soh_ci
195dfe32fa1Soh_ci        /// The error code indicates that the queried Asset can not be found.
196dfe32fa1Soh_ci        NotFound = 24000002,
197dfe32fa1Soh_ci
198dfe32fa1Soh_ci        /// The error code indicates that the Asset already exists.
199dfe32fa1Soh_ci        Duplicated = 24000003,
200dfe32fa1Soh_ci
201dfe32fa1Soh_ci        /// The error code indicates that the access to Asset is denied.
202dfe32fa1Soh_ci        AccessDenied = 24000004,
203dfe32fa1Soh_ci
204dfe32fa1Soh_ci        /// The error code indicates that the screen lock status mismatches.
205dfe32fa1Soh_ci        StatusMismatch = 24000005,
206dfe32fa1Soh_ci
207dfe32fa1Soh_ci        /// The error code indicates insufficient memory.
208dfe32fa1Soh_ci        OutOfMemory = 24000006,
209dfe32fa1Soh_ci
210dfe32fa1Soh_ci        /// The error code indicates that the Asset is corrupted.
211dfe32fa1Soh_ci        DataCorrupted = 24000007,
212dfe32fa1Soh_ci
213dfe32fa1Soh_ci        /// The error code indicates that the database operation is failed.
214dfe32fa1Soh_ci        DatabaseError = 24000008,
215dfe32fa1Soh_ci
216dfe32fa1Soh_ci        /// The error code indicates that the cryptography operation is failed.
217dfe32fa1Soh_ci        CryptoError = 24000009,
218dfe32fa1Soh_ci
219dfe32fa1Soh_ci        /// The error code indicates that the ipc communication is abnormal.
220dfe32fa1Soh_ci        IpcError = 24000010,
221dfe32fa1Soh_ci
222dfe32fa1Soh_ci        /// The error code indicates that the operation of calling Bundle Manager Service is failed.
223dfe32fa1Soh_ci        BmsError = 24000011,
224dfe32fa1Soh_ci
225dfe32fa1Soh_ci        /// The error code indicates that the operation of calling OS Account Service is failed.
226dfe32fa1Soh_ci        AccountError = 24000012,
227dfe32fa1Soh_ci
228dfe32fa1Soh_ci        /// The error code indicates that the operation of calling Access Token Service is failed.
229dfe32fa1Soh_ci        AccessTokenError = 24000013,
230dfe32fa1Soh_ci
231dfe32fa1Soh_ci        /// The error code indicates that the operation of file is failed.
232dfe32fa1Soh_ci        FileOperationError = 24000014,
233dfe32fa1Soh_ci
234dfe32fa1Soh_ci        /// The error code indicates that the operation of getting system time failed.
235dfe32fa1Soh_ci        GetSystemTimeError = 24000015,
236dfe32fa1Soh_ci
237dfe32fa1Soh_ci        /// The error code indicates that the cache exceeds the limit.
238dfe32fa1Soh_ci        LimitExceeded = 24000016,
239dfe32fa1Soh_ci
240dfe32fa1Soh_ci        /// The error code indicates that the capability is not supported.
241dfe32fa1Soh_ci        Unsupported = 24000017,
242dfe32fa1Soh_ci    }
243dfe32fa1Soh_ci}
244dfe32fa1Soh_ci
245dfe32fa1Soh_ci/// A struct containing the Asset result code and error message.
246dfe32fa1Soh_ci#[derive(Debug)]
247dfe32fa1Soh_cipub struct AssetError {
248dfe32fa1Soh_ci    /// Error code for error occurred.
249dfe32fa1Soh_ci    pub code: ErrCode,
250dfe32fa1Soh_ci
251dfe32fa1Soh_ci    /// Error message for error occurred.
252dfe32fa1Soh_ci    pub msg: String,
253dfe32fa1Soh_ci}
254dfe32fa1Soh_ci
255dfe32fa1Soh_ci/// Alias of the Asset result type.
256dfe32fa1Soh_cipub type Result<T> = std::result::Result<T, AssetError>;
257dfe32fa1Soh_ci
258dfe32fa1Soh_ciimpl_enum_trait! {
259dfe32fa1Soh_ci    /// An enum type indicates when the Asset is accessible.
260dfe32fa1Soh_ci    #[repr(C)]
261dfe32fa1Soh_ci    #[derive(Debug)]
262dfe32fa1Soh_ci    #[derive(Clone, Copy)]
263dfe32fa1Soh_ci    #[derive(PartialEq, Eq)]
264dfe32fa1Soh_ci    #[derive(Default)]
265dfe32fa1Soh_ci    pub enum Accessibility {
266dfe32fa1Soh_ci        /// The secret value in the Asset can only be accessed after the device power on.
267dfe32fa1Soh_ci        DevicePowerOn = 0,
268dfe32fa1Soh_ci
269dfe32fa1Soh_ci        /// The secret value in the Asset can only be accessed after the device is first unlocked.
270dfe32fa1Soh_ci        #[default]
271dfe32fa1Soh_ci        DeviceFirstUnlocked = 1,
272dfe32fa1Soh_ci
273dfe32fa1Soh_ci        /// The secret value in the Asset can only be accessed while the device is unlocked.
274dfe32fa1Soh_ci        DeviceUnlocked = 2,
275dfe32fa1Soh_ci    }
276dfe32fa1Soh_ci}
277dfe32fa1Soh_ci
278dfe32fa1Soh_ciimpl_enum_trait! {
279dfe32fa1Soh_ci    /// An enum type indicates the user authentication type for Asset access control.
280dfe32fa1Soh_ci    #[derive(Debug)]
281dfe32fa1Soh_ci    #[derive(Clone, Copy)]
282dfe32fa1Soh_ci    #[derive(PartialEq, Eq)]
283dfe32fa1Soh_ci    #[derive(Default)]
284dfe32fa1Soh_ci    pub enum AuthType {
285dfe32fa1Soh_ci        /// The access to an Asset doesn't require user authentication.
286dfe32fa1Soh_ci        #[default]
287dfe32fa1Soh_ci        None = 0x00,
288dfe32fa1Soh_ci
289dfe32fa1Soh_ci        /// The access to an Asset requires user authentication using either PIN/pattern/password or biometric traits.
290dfe32fa1Soh_ci        Any = 0xFF,
291dfe32fa1Soh_ci    }
292dfe32fa1Soh_ci}
293dfe32fa1Soh_ci
294dfe32fa1Soh_ciimpl_enum_trait! {
295dfe32fa1Soh_ci    /// An enum type indicates the type of Asset synchronization.
296dfe32fa1Soh_ci    #[derive(Debug)]
297dfe32fa1Soh_ci    #[derive(Clone, Copy)]
298dfe32fa1Soh_ci    #[derive(PartialEq, Eq)]
299dfe32fa1Soh_ci    #[derive(Default)]
300dfe32fa1Soh_ci    pub enum SyncType {
301dfe32fa1Soh_ci        /// An Asset with this attribute value is never allowed to be transferred out.
302dfe32fa1Soh_ci        #[default]
303dfe32fa1Soh_ci        Never = 0,
304dfe32fa1Soh_ci
305dfe32fa1Soh_ci        /// An Asset with this attribute value can only be restored to the device from which it was transferred out.
306dfe32fa1Soh_ci        ThisDevice = 1 << 0,
307dfe32fa1Soh_ci
308dfe32fa1Soh_ci        /// An Asset with this attribute value can only be transferred out to a trusted device (user authorized).
309dfe32fa1Soh_ci        TrustedDevice = 1 << 1,
310dfe32fa1Soh_ci
311dfe32fa1Soh_ci        /// An Asset with this attribute value can only be transferred out to a trusted device (user authorized).
312dfe32fa1Soh_ci        TrustedAccount = 1 << 2,
313dfe32fa1Soh_ci    }
314dfe32fa1Soh_ci}
315dfe32fa1Soh_ci
316dfe32fa1Soh_ciimpl_enum_trait! {
317dfe32fa1Soh_ci    /// An enum type indicates the strategy for conflict resolution when handling duplicated Asset alias.
318dfe32fa1Soh_ci    #[derive(Default)]
319dfe32fa1Soh_ci    pub enum ConflictResolution {
320dfe32fa1Soh_ci        /// Directly overwrite an Asset with duplicated alias when a conflict is detected.
321dfe32fa1Soh_ci        Overwrite = 0,
322dfe32fa1Soh_ci
323dfe32fa1Soh_ci        /// Throw an error so that the caller can take measures when a conflict is detected.
324dfe32fa1Soh_ci        #[default]
325dfe32fa1Soh_ci        ThrowError = 1,
326dfe32fa1Soh_ci    }
327dfe32fa1Soh_ci}
328dfe32fa1Soh_ci
329dfe32fa1Soh_ciimpl_enum_trait! {
330dfe32fa1Soh_ci    /// An enum type indicates the return type of the queried Asset.
331dfe32fa1Soh_ci    #[derive(Debug)]
332dfe32fa1Soh_ci    #[derive(Clone, Copy)]
333dfe32fa1Soh_ci    #[derive(PartialEq, Eq)]
334dfe32fa1Soh_ci    #[derive(Default)]
335dfe32fa1Soh_ci    pub enum LocalStatus {
336dfe32fa1Soh_ci        /// Specify that the return data should contain both secret value and attributes.
337dfe32fa1Soh_ci        #[default]
338dfe32fa1Soh_ci        Local = 0,
339dfe32fa1Soh_ci
340dfe32fa1Soh_ci        /// Specify that the return data contains only attributes.
341dfe32fa1Soh_ci        Cloud = 1 << 0,
342dfe32fa1Soh_ci    }
343dfe32fa1Soh_ci}
344dfe32fa1Soh_ci
345dfe32fa1Soh_ciimpl_enum_trait! {
346dfe32fa1Soh_ci    /// An enum type indicates the return type of the queried Asset.
347dfe32fa1Soh_ci    #[derive(Debug)]
348dfe32fa1Soh_ci    #[derive(Clone, Copy)]
349dfe32fa1Soh_ci    #[derive(PartialEq, Eq)]
350dfe32fa1Soh_ci    #[derive(Default)]
351dfe32fa1Soh_ci    pub enum SyncStatus {
352dfe32fa1Soh_ci        /// Specify that the return data should contain both secret value and attributes.
353dfe32fa1Soh_ci        #[default]
354dfe32fa1Soh_ci        NoNeedSync = 0,
355dfe32fa1Soh_ci
356dfe32fa1Soh_ci        /// Specify that the return data contains only attributes.
357dfe32fa1Soh_ci        SyncAdd = 1 << 0,
358dfe32fa1Soh_ci
359dfe32fa1Soh_ci        /// Specify that the return data contains only attributes.
360dfe32fa1Soh_ci        SyncDel = 1 << 1,
361dfe32fa1Soh_ci
362dfe32fa1Soh_ci        /// Specify that the return data contains only attributes.
363dfe32fa1Soh_ci        SyncUpdate = 1 << 2,
364dfe32fa1Soh_ci    }
365dfe32fa1Soh_ci}
366dfe32fa1Soh_ci
367dfe32fa1Soh_ciimpl_enum_trait! {
368dfe32fa1Soh_ci    /// An enum type indicates the return type of the queried Asset.
369dfe32fa1Soh_ci    #[derive(Default)]
370dfe32fa1Soh_ci    pub enum ReturnType {
371dfe32fa1Soh_ci        /// Specify that the return data should contain both secret value and attributes.
372dfe32fa1Soh_ci        All = 0,
373dfe32fa1Soh_ci
374dfe32fa1Soh_ci        /// Specify that the return data contains only attributes.
375dfe32fa1Soh_ci        #[default]
376dfe32fa1Soh_ci        Attributes = 1,
377dfe32fa1Soh_ci    }
378dfe32fa1Soh_ci}
379dfe32fa1Soh_ci
380dfe32fa1Soh_ciimpl_enum_trait! {
381dfe32fa1Soh_ci    /// An enum type indicates the return type of the queried Asset.
382dfe32fa1Soh_ci    #[derive(Default)]
383dfe32fa1Soh_ci    pub enum OperationType {
384dfe32fa1Soh_ci        /// Trigger Sync.
385dfe32fa1Soh_ci        #[default]
386dfe32fa1Soh_ci        NeedSync = 0,
387dfe32fa1Soh_ci
388dfe32fa1Soh_ci        /// Logout to clean cloud flag.
389dfe32fa1Soh_ci        NeedLogout = 1,
390dfe32fa1Soh_ci
391dfe32fa1Soh_ci        /// Delete cloud data.
392dfe32fa1Soh_ci        NeedDeleteCloudData = 2,
393dfe32fa1Soh_ci    }
394dfe32fa1Soh_ci}
395dfe32fa1Soh_ci
396dfe32fa1Soh_ci/// Expended abililty for HashMap.
397dfe32fa1Soh_cipub trait Extension<K> {
398dfe32fa1Soh_ci    /// Insert an attribute into the collection.
399dfe32fa1Soh_ci    fn insert_attr(&mut self, key: K, value: impl Conversion);
400dfe32fa1Soh_ci
401dfe32fa1Soh_ci    /// Get an attribute of bool type from the collection.
402dfe32fa1Soh_ci    fn get_bool_attr(&self, key: &K) -> Result<bool>;
403dfe32fa1Soh_ci
404dfe32fa1Soh_ci    /// Get an attribute of enum type from the collection.
405dfe32fa1Soh_ci    fn get_enum_attr<T: TryFrom<u32, Error = AssetError>>(&self, key: &K) -> Result<T>;
406dfe32fa1Soh_ci
407dfe32fa1Soh_ci    /// Get an attribute of number type from the collection.
408dfe32fa1Soh_ci    fn get_num_attr(&self, key: &K) -> Result<u32>;
409dfe32fa1Soh_ci
410dfe32fa1Soh_ci    /// Get an attribute of bytes type from the collection.
411dfe32fa1Soh_ci    fn get_bytes_attr(&self, key: &K) -> Result<&Vec<u8>>;
412dfe32fa1Soh_ci}
413dfe32fa1Soh_ci
414dfe32fa1Soh_ci/// Conversion between a specific type and the Asset Value type.
415dfe32fa1Soh_cipub trait Conversion {
416dfe32fa1Soh_ci    /// Get the data type of Asset Enum type.
417dfe32fa1Soh_ci    fn data_type(&self) -> DataType;
418dfe32fa1Soh_ci
419dfe32fa1Soh_ci    /// Convert the Asset Enum type to the Value variant.
420dfe32fa1Soh_ci    fn into_value(self) -> Value;
421dfe32fa1Soh_ci}
422