avb: move error module to libavb
The libavb Rust wrappers are moving to //external/avb to make them more
widely available and keep them closer to the C source.
To keep CLs manageable, this is being done in smaller chunks. This first
CL just moves the error module over.
A few minor changes were necessary to split out some pvmfw-specific
error conditions from the generic libavb errors (e.g. requirements on
the shape of the vbmeta image).
Bug: b/290110273
Test: atest results unchanged from pre-patch
Change-Id: Iacef297bfb72e560890971e9e158c55f46cf0583
diff --git a/pvmfw/avb/src/utils.rs b/pvmfw/avb/src/utils.rs
index a24d61f..f4f15e1 100644
--- a/pvmfw/avb/src/utils.rs
+++ b/pvmfw/avb/src/utils.rs
@@ -14,11 +14,10 @@
//! Common utility functions.
-use crate::error::AvbIOError;
use core::ptr::NonNull;
use core::result;
-pub(crate) type Result<T> = result::Result<T, AvbIOError>;
+pub(crate) type Result<T> = result::Result<T, avb::IoError>;
pub(crate) fn write<T>(ptr: *mut T, value: T) -> Result<()> {
let ptr = to_nonnull(ptr)?;
@@ -36,21 +35,21 @@
}
pub(crate) fn to_nonnull<T>(ptr: *mut T) -> Result<NonNull<T>> {
- NonNull::new(ptr).ok_or(AvbIOError::NoSuchValue)
+ NonNull::new(ptr).ok_or(avb::IoError::NoSuchValue)
}
pub(crate) fn is_not_null<T>(ptr: *const T) -> Result<()> {
if ptr.is_null() {
- Err(AvbIOError::NoSuchValue)
+ Err(avb::IoError::NoSuchValue)
} else {
Ok(())
}
}
pub(crate) fn to_usize<T: TryInto<usize>>(num: T) -> Result<usize> {
- num.try_into().map_err(|_| AvbIOError::InvalidValueSize)
+ num.try_into().map_err(|_| avb::IoError::InvalidValueSize)
}
pub(crate) fn usize_checked_add(x: usize, y: usize) -> Result<usize> {
- x.checked_add(y).ok_or(AvbIOError::InvalidValueSize)
+ x.checked_add(y).ok_or(avb::IoError::InvalidValueSize)
}