DemesneGH commented on code in PR #209:
URL: 
https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/209#discussion_r2204905434


##########
optee-utee/src/object/persistent_object.rs:
##########
@@ -0,0 +1,643 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use core::ptr;
+
+use optee_utee_sys as raw;
+
+use super::{DataFlag, GenericObject, ObjectHandle, ObjectStorageConstants, 
Whence};
+use crate::{Error, Result};
+
+/// An object identified by an Object Identifier and including a Data Stream.
+///
+/// Contrast [TransientObject](crate::TransientObject).
+#[derive(Debug)]
+pub struct PersistentObject(ObjectHandle);
+
+impl PersistentObject {
+    /// Open an existing persistent object.
+    ///
+    /// # Parameters
+    ///
+    /// 1) `storage_id`: The storage to use which is defined in
+    ///    [ObjectStorageConstants](crate::ObjectStorageConstants).
+    /// 2) `object_id`: The object identifier. Note that this buffer cannot
+    ///    reside in shared memory.
+    /// 3) `flags`: The [DataFlag](crate::DataFlag) which determine the 
settings
+    ///    under which the object is opened.
+    ///
+    /// # Example
+    ///
+    /// ``` rust,no_run
+    /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag};
+    /// # fn main() -> optee_utee::Result<()> {
+    /// let obj_id = [1u8;1];
+    /// match PersistentObject::open(
+    ///         ObjectStorageConstants::Private,
+    ///         &obj_id,
+    ///         DataFlag::ACCESS_READ) {
+    ///     Ok(object) =>
+    ///     {
+    ///         // ...
+    ///         Ok(())
+    ///     }
+    ///     Err(e) => Err(e),
+    /// }
+    /// # }
+    /// ```
+    ///
+    /// # Errors
+    ///
+    /// 1) `ItemNotFound`: If the storage denoted by storage_id does not exist
+    ///    or if the object identifier cannot be found in the storage.
+    /// 2) `Access_Conflict`: If an access right conflict was detected while
+    ///    opening the object.
+    /// 3) `OutOfMemory`: If there is not enough memory to complete the
+    ///    operation.
+    /// 4) `CorruptObject`: If the object is corrupt. The object handle SHALL
+    ///    behave based on the `gpd.ta.doesNotCloseHandleOnCorruptObject`
+    ///    property.
+    /// 5) `StorageNotAvailable`: If the object is stored in a storage area
+    ///    which is currently inaccessible.
+    ///
+    /// # Panics
+    ///
+    /// 1) If object_id.len() >
+    ///    
[MiscellaneousConstants::TeeObjectIdMaxLen](crate::MiscellaneousConstants::TeeObjectIdMaxLen)
+    /// 2) If the Implementation detects any other error associated with this
+    ///    function which is not explicitly associated with a defined return
+    ///    code for this function.
+    pub fn open(
+        storage_id: ObjectStorageConstants,
+        object_id: &[u8],
+        flags: DataFlag,
+    ) -> Result<Self> {
+        let mut handle: raw::TEE_ObjectHandle = core::ptr::null_mut();
+        let handle_mut = &mut handle;
+        match unsafe {
+            raw::TEE_OpenPersistentObject(
+                storage_id as u32,
+                object_id.as_ptr() as _,
+                object_id.len(),
+                flags.bits(),
+                handle_mut,
+            )
+        } {
+            raw::TEE_SUCCESS => Ok(Self(ObjectHandle::from_raw(handle)?)),
+            code => Err(Error::from_raw_error(code)),
+        }
+    }
+
+    /// Create an object with initial attributes and an initial data stream
+    /// content.
+    ///
+    /// # Parameters
+    ///
+    /// 1) `storage_id`: The storage to use which is defined in
+    ///    [ObjectStorageConstants](crate::ObjectStorageConstants).
+    /// 2) `object_id`: The object identifier. Note that this buffer cannot
+    ///    reside in shared memory.
+    /// 3) `flags`: The [DataFlag](crate::DataFlag) which determine the 
settings
+    ///    under which the object is opened.
+    /// 4) `attributes`: A handle on a
+    ///    [PersistentObject](crate::PersistentObject) or an initialized
+    ///    [TransientObject](crate::TransientObject) from which to take the
+    ///    [PersistentObject](crate::PersistentObject) attributes.
+    ///    Can be NONE if the [PersistentObject](crate::PersistentObject)
+    ///    contains no attribute. For example,if it is a pure data object.
+    ///
+    /// # Example
+    ///
+    /// ``` rust,no_run
+    /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag};
+    /// # fn main() -> optee_utee::Result<()> {
+    /// let obj_id = [1u8;1];
+    /// let mut init_data: [u8; 0] = [0; 0];
+    /// match PersistentObject::create(
+    ///         ObjectStorageConstants::Private,
+    ///         &obj_id,
+    ///         DataFlag::ACCESS_READ | DataFlag::ACCESS_WRITE,
+    ///         None,
+    ///         &mut init_data) {
+    ///     Ok(object) =>
+    ///     {
+    ///         // ...
+    ///         Ok(())
+    ///     }
+    ///     Err(e) => Err(e),
+    /// }
+    /// # }
+    /// ```
+    ///
+    /// # Errors
+    ///
+    /// 1) `ItemNotFound`: If the storage denoted by storage_id does not exist.
+    /// 2) `Access_Conflict`: If an access right conflict was detected while
+    ///    opening the object.
+    /// 3) `OutOfMemory`: If there is not enough memory to complete the
+    ///    operation.
+    /// 4) `StorageNoSpace`: If insufficient space is available to create the
+    ///    persistent object.
+    /// 5) `CorruptObject`: If the storage is corrupt.
+    /// 6) `StorageNotAvailable`: If the object is stored in a storage area
+    ///    which is currently inaccessible.
+    ///
+    /// # Panics
+    ///
+    /// 1) If object_id.len() >
+    ///    
[MiscellaneousConstants::TeeObjectIdMaxLen](crate::MiscellaneousConstants::TeeObjectIdMaxLen).
+    /// 2) If attributes is not NONE and is not a valid handle on an 
initialized
+    ///    object containing the type and attributes of the object to create.
+    /// 3) If the Implementation detects any other error associated with this
+    ///    function which is not explicitly associated with a defined return
+    ///    code for this function.
+    pub fn create(
+        storage_id: ObjectStorageConstants,
+        object_id: &[u8],
+        flags: DataFlag,
+        attributes: Option<ObjectHandle>,
+        initial_data: &[u8],
+    ) -> Result<Self> {
+        let mut handle: raw::TEE_ObjectHandle = core::ptr::null_mut();
+        let handle_mut = &mut handle;
+        let attributes = match attributes {
+            Some(a) => a.handle(),
+            None => ptr::null_mut(),

Review Comment:
   Seems there're multiple source of `null_mut()`: `core::ptr::null_mut()`, 
`ptr::null_mut()`(use core::ptr) and `std::ptr::null_mut()`. Could we unify 
this?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org
For additional commands, e-mail: dev-h...@teaclave.apache.org

Reply via email to