1/* 2 * Copyright (c) 2024 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 */ 15import Constants from '../../common/constant'; 16import EncryptProtectionShowCodeEnum from '../../common/enum/EncryptProtectionShowCodeEnum'; 17 18export default class EncryptProtectionHelper { 19 public static readonly INPUT_MAX_LENGTH = 50 * 20; 20 private static readonly ERROR_SHOW_MAP = new Map<number, Resource>([ 21 [EncryptProtectionShowCodeEnum.NET_ERROR, $r('app.string.network_invalid')], 22 [EncryptProtectionShowCodeEnum.INPUT_ERROR, $r('app.string.incorrect_work_ID')], 23 [EncryptProtectionShowCodeEnum.DEFAULT_ERROR, $r('app.string.File_cannot_be_opened')], 24 ]); 25 private static readonly BUSINESS_CODE_MAP = new Map<number, number>([ 26 [Constants.ERR_JS_NETWORK_INVALID, EncryptProtectionShowCodeEnum.NET_ERROR], 27 [Constants.ERR_JS_ACCOUNT_NOT_FOUND, EncryptProtectionShowCodeEnum.INPUT_ERROR], 28 ]); 29 30 public static isParamError(errorCode: number): boolean { 31 return errorCode === Constants.ERR_JS_ACCOUNT_NOT_FOUND; 32 } 33 34 public static getShowErr(errorCode: number): Resource | undefined { 35 return EncryptProtectionHelper.ERROR_SHOW_MAP.get(errorCode); 36 } 37 38 public static isShowErr(errorCode: number, isOver: boolean): boolean { 39 return isOver || (errorCode !== EncryptProtectionShowCodeEnum.INIT_SUCCESS); 40 } 41 42 public static convertErrorCodeToShowCode(errorCode: number): number { 43 const showCode = EncryptProtectionHelper.BUSINESS_CODE_MAP.get(errorCode); 44 if (showCode) { 45 return showCode; 46 } 47 return EncryptProtectionShowCodeEnum.DEFAULT_ERROR; 48 } 49} 50 51 52