blob: af38c54ec555d1ff6e5a1987bef4c8fc9316317a [file] [log] [blame]
Alice Wang45d98fa2023-01-11 09:39:45 +00001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Alice Wang18655632023-01-18 09:11:34 +000015//! This module contains the error thrown by the payload verification API
16//! and other errors used in the library.
Alice Wang45d98fa2023-01-11 09:39:45 +000017
Alice Wang45d98fa2023-01-11 09:39:45 +000018use core::fmt;
19
David Pursella7c727b2023-08-14 16:24:40 -070020/// Wrapper around `avb::SlotVerifyError` to add custom pvmfw errors.
Alice Wang45d98fa2023-01-11 09:39:45 +000021/// It is the error thrown by the payload verification API `verify_payload()`.
22#[derive(Clone, Debug, PartialEq, Eq)]
David Pursella7c727b2023-08-14 16:24:40 -070023pub enum PvmfwVerifyError {
24 /// Passthrough avb::SlotVerifyError.
25 AvbError(avb::SlotVerifyError),
Alice Wang14973b22023-05-22 14:54:16 +000026 /// VBMeta has invalid descriptors.
David Pursella7c727b2023-08-14 16:24:40 -070027 InvalidDescriptors(avb::IoError),
28 /// Unknown vbmeta property.
Alice Wangab0d0202023-05-17 08:07:41 +000029 UnknownVbmetaProperty,
Alice Wang45d98fa2023-01-11 09:39:45 +000030}
31
David Pursella7c727b2023-08-14 16:24:40 -070032/// It's always possible to convert from an `avb::SlotVerifyError` since we are
33/// a superset.
34impl From<avb::SlotVerifyError> for PvmfwVerifyError {
35 fn from(error: avb::SlotVerifyError) -> Self {
36 Self::AvbError(error)
37 }
38}
39
40impl fmt::Display for PvmfwVerifyError {
Alice Wang45d98fa2023-01-11 09:39:45 +000041 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 match self {
David Pursella7c727b2023-08-14 16:24:40 -070043 Self::AvbError(e) => write!(f, "{}", e),
Alice Wang14973b22023-05-22 14:54:16 +000044 Self::InvalidDescriptors(e) => {
45 write!(f, "VBMeta has invalid descriptors. Error: {:?}", e)
46 }
Alice Wangab0d0202023-05-17 08:07:41 +000047 Self::UnknownVbmetaProperty => write!(f, "Unknown vbmeta property"),
Alice Wang45d98fa2023-01-11 09:39:45 +000048 }
49 }
50}