Skip to main content

optee_utee/object/
object_define.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use bitflags::bitflags;
19use optee_utee_sys as raw;
20
21/// Indicate the possible start offset when moving a data position in the data
22/// stream associated with a [PersistentObject](crate::PersistentObject).
23pub enum Whence {
24    /// The data position is set to offset bytes from the beginning of the data stream.
25    DataSeekSet,
26    /// The data position is set to its current position plus offset.
27    DataSeekCur,
28    /// The data position is set to the size of the object data plus offset.
29    DataSeekEnd,
30}
31
32impl From<Whence> for raw::TEE_Whence {
33    fn from(val: Whence) -> Self {
34        match val {
35            Whence::DataSeekSet => raw::TEE_Whence::TEE_DATA_SEEK_SET,
36            Whence::DataSeekCur => raw::TEE_Whence::TEE_DATA_SEEK_CUR,
37            Whence::DataSeekEnd => raw::TEE_Whence::TEE_DATA_SEEK_END,
38        }
39    }
40}
41
42#[repr(u32)]
43pub enum ObjectStorageConstants {
44    Private = 0x00000001,
45    PrivateRee = 0x80000000,
46    PrivateRpmb = 0x80000100,
47    IllegalValue = 0x7FFFFFFF,
48}
49
50bitflags! {
51    /// A set of flags that controls the access rights and sharing permissions
52    /// with which the object handle is opened.
53    pub struct DataFlag: u32 {
54        /// The object is opened with the read access right. This allows the
55        /// Trusted Application to call the function `TEE_ReadObjectData`.
56        const ACCESS_READ = 0x00000001;
57        /// The object is opened with the write access right. This allows the
58        /// Trusted Application to call the functions `TEE_WriteObjectData` and
59        /// `TEE_TruncateObjectData`.
60        const ACCESS_WRITE = 0x00000002;
61        /// The object is opened with the write-meta access right. This allows
62        /// the Trusted Application to call the functions
63        /// `TEE_CloseAndDeletePersistentObject1` and
64        /// `TEE_RenamePersistentObject`.
65        const ACCESS_WRITE_META = 0x00000004;
66        /// The caller allows another handle on the object to be created with
67        /// read access.
68        const SHARE_READ = 0x00000010;
69        /// The caller allows another handle on the object to be created with
70        /// write access.
71        const SHARE_WRITE = 0x00000020;
72        /// * If this flag is present and the object exists, then the object is
73        ///   deleted and re-created as an atomic operation: that is, the TA
74        ///   sees either the old object or the new one.
75        /// * If the flag is absent and the object exists, then the function
76        ///   SHALL return `TEE_ERROR_ACCESS_CONFLICT`.
77        const OVERWRITE = 0x00000400;
78    }
79}
80
81bitflags! {
82    /// A set of flags that defines usages of data in TEE secure storage.
83    pub struct UsageFlag: u32 {
84        /// The object [Attribute](Attribute) can be extracted.
85        const EXTRACTABLE = 0x00000001;
86        /// The object can be used for encryption.
87        const ENCRYPT = 0x00000002;
88        /// The object can be used for decryption.
89        const DECRYPT = 0x00000004;
90        /// The object can be used for mac operation.
91        const MAC = 0x00000008;
92        /// The object can be used for signature.
93        const SIGN = 0x00000010;
94        /// The object can be used for verification of a signature.
95        const VERIFY = 0x00000020;
96        /// The object can be used for deriving a key.
97        const DERIVE = 0x00000040;
98    }
99}
100
101/// Miscellaneous constants.
102#[repr(u32)]
103pub enum MiscellaneousConstants {
104    /// Maximum offset of a data object.
105    TeeDataMaxPosition = 0xFFFFFFFF,
106    /// Maximum length of an object id.
107    TeeObjectIdMaxLen = 64,
108}
109
110bitflags! {
111    /// A set of flags that defines Handle features.
112    pub struct HandleFlag: u32{
113        /// Set for a [PersistentObject](crate::PersistentObject).
114        const PERSISTENT = 0x00010000;
115        /// 1) For a [PersistentObject](crate::PersistentObject), always set.
116        /// 2) For a [TransientObject](crate::TransientObject), initially
117        ///    cleared, then set when the object becomes initialized.
118        const INITIALIZED = 0x00020000;
119        /// Following two flags are for crypto operation handles:
120        /// 1) Set if the required operation key has been set.
121        /// 2) Always set for digest operations.
122        const KEY_SET = 0x00040000;
123        /// Set if the algorithm expects two keys to be set, using
124        /// `TEE_SetOperationKey2`.
125        /// This happens only if algorithm is set to
126        /// [AesXts](crate::AlgorithmId::AesXts)
127        /// or `TEE_ALG_SM2_KEP`(not supported now).
128        const EXPECT_TWO_KEYS = 0x00080000;
129    }
130}