DemesneGH commented on code in PR #209: URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/209#discussion_r2204806831
########## 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, + ) Review Comment: Consider removing line90 and line176 for simplicity? -- 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