mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-09-17 23:48:03 +00:00
Merge changes I3cf10baa,I0062e20b
* changes: kata-storage-interface: add back From trait to streamline return processing Revert "StorageManager: streamline kata_storage_* routines" GitOrigin-RevId: 051c4f2b1529e448f70acc4d4e2779f4d9c50e70
This commit is contained in:
@@ -4,6 +4,6 @@ version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
cstr_core = { version = "0.2.3", default-features = false }
|
||||
cstr_core = "0.2.3"
|
||||
kata-security-interface = { path = "../../SecurityCoordinator/kata-security-interface" }
|
||||
postcard = { version = "0.7", features = ["alloc"], default-features = false }
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
|
||||
use core::str;
|
||||
use cstr_core;
|
||||
use cstr_core::CString;
|
||||
use kata_security_interface::SecurityRequestError;
|
||||
use postcard;
|
||||
|
||||
@@ -100,6 +100,12 @@ impl From<Result<(), StorageError>> for StorageManagerError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cstr_core::NulError> for StorageManagerError {
|
||||
fn from(_err: cstr_core::NulError) -> StorageManagerError {
|
||||
StorageManagerError::SmeKeyInvalid
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StorageManagerError> for Result<(), StorageManagerError> {
|
||||
fn from(err: StorageManagerError) -> Result<(), StorageManagerError> {
|
||||
if err == StorageManagerError::SmeSuccess {
|
||||
@@ -117,7 +123,8 @@ pub fn kata_storage_delete(key: &str) -> Result<(), StorageManagerError> {
|
||||
extern "C" {
|
||||
pub fn storage_delete(c_key: *const cstr_core::c_char) -> StorageManagerError;
|
||||
}
|
||||
unsafe { storage_delete(key.as_ptr()) }.into()
|
||||
let cstr = CString::new(key)?;
|
||||
unsafe { storage_delete(cstr.as_ptr()) }.into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -129,8 +136,9 @@ pub fn kata_storage_read(key: &str) -> Result<KeyValueData, StorageManagerError>
|
||||
c_raw_value: *mut KeyValueData,
|
||||
) -> StorageManagerError;
|
||||
}
|
||||
let cstr = CString::new(key)?;
|
||||
let value = &mut [0u8; KEY_VALUE_DATA_SIZE];
|
||||
match unsafe { storage_read(key.as_ptr(), value as *mut _) } {
|
||||
match unsafe { storage_read(cstr.as_ptr(), value as *mut _) } {
|
||||
StorageManagerError::SmeSuccess => Ok(*value),
|
||||
status => Err(status),
|
||||
}
|
||||
@@ -146,5 +154,6 @@ pub fn kata_storage_write(key: &str, value: &[u8]) -> Result<(), StorageManagerE
|
||||
c_raw_value: *const u8,
|
||||
) -> StorageManagerError;
|
||||
}
|
||||
unsafe { storage_write(key.as_ptr(), value.len(), value.as_ptr()) }.into()
|
||||
let cstr = CString::new(key)?;
|
||||
unsafe { storage_write(cstr.as_ptr(), value.len(), value.as_ptr()) }.into()
|
||||
}
|
||||
|
Reference in New Issue
Block a user