• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 
16 //! This crate defines the common constants.
17 
18 use asset_definition::{impl_enum_trait, AssetError, ErrCode};
19 mod calling_info;
20 pub use calling_info::CallingInfo;
21 /// success code.
22 pub const SUCCESS: i32 = 0;
23 
24 impl_enum_trait! {
25     /// The type of the calling.
26     #[repr(C)]
27     #[derive(PartialEq, Eq)]
28     #[derive(Copy, Clone)]
29     pub enum OwnerType {
30         /// The calling is a application.
31         Hap = 0,
32         /// The calling is a native process.
33         Native = 1,
34     }
35 }
36 
37 /// Transfer error code to AssetError
transfer_error_code(err_code: ErrCode) -> AssetError38 pub fn transfer_error_code(err_code: ErrCode) -> AssetError {
39     match err_code {
40         ErrCode::AccessDenied => {
41             AssetError::new(ErrCode::AccessDenied, "[FATAL]HUKS verify auth token failed".to_string())
42         },
43         ErrCode::StatusMismatch => {
44             AssetError::new(ErrCode::StatusMismatch, "[FATAL]Screen status does not match".to_string())
45         },
46         ErrCode::InvalidArgument => {
47             AssetError::new(ErrCode::InvalidArgument, "[FATAL]Invalid argument.".to_string())
48         },
49         ErrCode::BmsError => {
50             AssetError::new(ErrCode::BmsError, "[FATAL]Get owner info from bms failed.".to_string())
51         },
52         ErrCode::AccessTokenError => {
53             AssetError::new(ErrCode::AccessTokenError, "[FATAL]Get process info failed.".to_string())
54         },
55         _ => AssetError::new(ErrCode::CryptoError, "[FATAL]HUKS execute crypt failed".to_string())
56     }
57 }