optee_utee/object/
object_info.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 optee_utee_sys as raw;
19
20/// Represent the characteristics of an object.
21/// This info can be returned by [GenericObject](crate::GenericObject) function
22/// [info](crate::GenericObject::info)
23pub struct ObjectInfo {
24    pub(crate) raw: raw::TEE_ObjectInfo,
25}
26
27// Since raw struct is not implemented Copy attribute yet, every item in raw
28// struct needs a function to extract.
29impl ObjectInfo {
30    /// Return an [ObjectInfo](crate::ObjectInfo) struct based on the raw
31    /// structure `TEE_ObjectInfo`.
32    /// The raw structure contains following fields:
33    ///
34    /// 1) `objectType`: The parameter represents one of the
35    ///    [TransientObjectType](crate::TransientObjectType).
36    /// 2) `objectSize`: The current size in bits of the object as determined
37    ///    by its attributes.
38    ///    This will always be less than or equal to maxObjectSize. Set to 0 for
39    ///    uninitialized and data only objects.
40    /// 3) `maxObjectSize`: The maximum objectSize which this object can
41    ///    represent.
42    ///     * For a [PersistentObject](crate::PersistentObject), set to
43    ///       `objectSize`.
44    ///     * For a [TransientObject](crate::TransientObject), set to the
45    ///       parameter `maxObjectSize` passed to
46    ///       [allocate](crate::TransientObject::allocate).
47    /// 4) `objectUsage`: A bit vector of UsageFlag.
48    /// 5) `dataSize`:
49    ///     * For a [PersistentObject](crate::PersistentObject), set to the
50    ///       current size of the data associated with the object.
51    ///     * For a [TransientObject](crate::TransientObject), always set to 0.
52    /// 6) `dataPosition`:
53    ///     * For a [PersistentObject](crate::PersistentObject), set to the
54    ///       current position in the data for this handle.
55    ///       Data positions for different handles on the same object may
56    ///       differ.
57    ///     * For a [TransientObject](crate::TransientObject), set to 0.
58    /// 7) `handleFlags`: A bit vector containing one or more
59    ///    [HandleFlag](crate::HandleFlag) or [DataFlag](crate::DataFlag).
60    pub fn from_raw(raw: raw::TEE_ObjectInfo) -> Self {
61        Self { raw }
62    }
63
64    /// Return the `dataSize` field of the raw structure `TEE_ObjectInfo`.
65    pub fn data_size(&self) -> usize {
66        self.raw.dataSize
67    }
68
69    /// Return the `objectSize` field of the raw structure `TEE_ObjectInfo`.
70    pub fn object_size(&self) -> usize {
71        self.raw.objectSize as usize
72    }
73
74    /// Return the `objectType` field of the raw structure `TEE_ObjectInfo`.
75    pub fn object_type(&self) -> u32 {
76        self.raw.objectType
77    }
78}