Alice Wang | 45d98fa | 2023-01-11 09:39:45 +0000 | [diff] [blame] | 1 | // 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 Wang | 1865563 | 2023-01-18 09:11:34 +0000 | [diff] [blame] | 15 | //! This module contains the error thrown by the payload verification API |
| 16 | //! and other errors used in the library. |
Alice Wang | 45d98fa | 2023-01-11 09:39:45 +0000 | [diff] [blame] | 17 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 18 | use avb::{IoError, SlotVerifyError}; |
Alice Wang | 45d98fa | 2023-01-11 09:39:45 +0000 | [diff] [blame] | 19 | use core::fmt; |
| 20 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 21 | /// Wrapper around `SlotVerifyError` to add custom pvmfw errors. |
Alice Wang | 45d98fa | 2023-01-11 09:39:45 +0000 | [diff] [blame] | 22 | /// It is the error thrown by the payload verification API `verify_payload()`. |
David Pursell | 009580b | 2023-11-20 17:38:09 -0800 | [diff] [blame] | 23 | #[derive(Debug, PartialEq, Eq)] |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 24 | pub enum PvmfwVerifyError { |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 25 | /// Passthrough `SlotVerifyError` with no `SlotVerifyData`. |
| 26 | AvbError(SlotVerifyError<'static>), |
Alice Wang | 14973b2 | 2023-05-22 14:54:16 +0000 | [diff] [blame] | 27 | /// VBMeta has invalid descriptors. |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 28 | InvalidDescriptors(IoError), |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 29 | /// Unknown vbmeta property. |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 30 | UnknownVbmetaProperty, |
Alice Wang | 45d98fa | 2023-01-11 09:39:45 +0000 | [diff] [blame] | 31 | } |
| 32 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 33 | impl From<SlotVerifyError<'_>> for PvmfwVerifyError { |
| 34 | fn from(error: SlotVerifyError) -> Self { |
David Pursell | 009580b | 2023-11-20 17:38:09 -0800 | [diff] [blame] | 35 | // We don't use verification data on failure, drop it to get a `'static` lifetime. |
| 36 | Self::AvbError(error.without_verify_data()) |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| 40 | impl fmt::Display for PvmfwVerifyError { |
Alice Wang | 45d98fa | 2023-01-11 09:39:45 +0000 | [diff] [blame] | 41 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 42 | match self { |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 43 | Self::AvbError(e) => write!(f, "{}", e), |
Alice Wang | 14973b2 | 2023-05-22 14:54:16 +0000 | [diff] [blame] | 44 | Self::InvalidDescriptors(e) => { |
| 45 | write!(f, "VBMeta has invalid descriptors. Error: {:?}", e) |
| 46 | } |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 47 | Self::UnknownVbmetaProperty => write!(f, "Unknown vbmeta property"), |
Alice Wang | 45d98fa | 2023-01-11 09:39:45 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |