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 15 use android_system_virtualizationcommon::aidl::android::system::virtualizationcommon::ErrorCode::ErrorCode as AidlErrorCode; 16 17 /// Errors reported from within a VM. 18 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 19 pub enum ErrorCode { 20 /// Error code for all other errors not listed below. 21 Unknown, 22 23 /// Error code indicating that the payload can't be verified due to various reasons (e.g 24 /// invalid merkle tree, invalid formats, etc). 25 PayloadVerificationFailed, 26 27 /// Error code indicating that the payload is verified, but has changed since the last boot. 28 PayloadChanged, 29 30 /// Error code indicating that the payload config is invalid. 31 PayloadInvalidConfig, 32 33 /// Payload sent a death reason which was not recognised by the client library. 34 Unrecognised(AidlErrorCode), 35 } 36 37 impl From<AidlErrorCode> for ErrorCode { from(error_code: AidlErrorCode) -> Self38 fn from(error_code: AidlErrorCode) -> Self { 39 match error_code { 40 AidlErrorCode::UNKNOWN => Self::Unknown, 41 AidlErrorCode::PAYLOAD_VERIFICATION_FAILED => Self::PayloadVerificationFailed, 42 AidlErrorCode::PAYLOAD_CHANGED => Self::PayloadChanged, 43 AidlErrorCode::PAYLOAD_INVALID_CONFIG => Self::PayloadInvalidConfig, 44 _ => Self::Unrecognised(error_code), 45 } 46 } 47 } 48