1/** 2 * Copyright (c) 2022 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 16import { CertInfo, certAbstract, CMResult, CMContext, AsyncCallback, BusinessError, CMHandle, 17 Credential, CredentialAbstract, CMErrorCode, CMBlob, CMKeyProperties, CMSignatureSpec } from './certStubStruct' 18 19export default class certStubUtil { 20 constructor() { 21 } 22 23parseCertInfo(uri: string, certAlias: string, status: boolean, cert: Uint8Array): CertInfo { 24 let certInfo: CertInfo; 25 26 certInfo = { 27 uri: uri, 28 certAlias: certAlias, 29 status: status, 30 issuerName: "CN=SwissSign Gold CA - G2,OU=,O=SwissSign CA", 31 subjectName: "CN=SwissSign Gold CA - G2,OU=,O=SwissSign CA", 32 serial: "BB401C43F55E4FB0", 33 notBefore: "1979/5/24", 34 notAfter: "2030/5/24", 35 fingerprintSha256: "D8:C5:38:8A:B7:30:1B:1B:6E:D4:7A:E6:45:25:3A:6F:9F:1A:27:61", 36 cert: cert 37 } 38 39 return certInfo; 40} 41 42parseCertAbstract(uri: string, certAlias: string, status: boolean): certAbstract { 43 let result: certAbstract; 44 45 result = { 46 uri: uri, 47 certAlias: certAlias, 48 status: status, 49 subjectName: "CN=SwissSign Gold CA - G2,OU=,O=SwissSign", 50 } 51 52 return result; 53} 54 55 56parseCMHandle(errorCode: number, handle: number, token: Uint8Array): CMHandle { 57 let result: CMHandle; 58 59 result = { 60 errorCode: errorCode, 61 handle: handle, 62 token: token, 63 } 64 65 return result; 66} 67 68parseCredential(type: string, alias: string, keyUri: string, certNum: number, 69 keyNum: number, credData: Uint8Array): Credential { 70 let result: Credential; 71 72 result = { 73 type: type, 74 alias: alias, 75 keyUri: keyUri, 76 certNum: certNum, 77 keyNum: keyNum, 78 credData: credData 79 } 80 81 return result; 82} 83 84parseCredentialAbstract(type: string, alias: string, keyUri: string): CredentialAbstract { 85 let result: CredentialAbstract; 86 87 result = { 88 type: type, 89 alias: alias, 90 keyUri: keyUri 91 } 92 93 return result; 94} 95 96parseCMContext(userId: string, uid: string, packageName: string): CMContext { 97 let result: CMContext; 98 99 result = { 100 userId: userId, 101 uid: uid, 102 packageName: packageName 103 } 104 105 return result; 106} 107 108parseCMBlob(inData: Uint8Array, alias: string): CMBlob { 109 let result: CMBlob; 110 111 result = { 112 inData: inData, 113 alias: alias 114 } 115 116 return result; 117} 118 119parseCMKeyProperties(): CMKeyProperties { 120 let result: CMKeyProperties; 121 122 result = { 123 type: "CM_URI_TYPE_APP_KEY", // Type of the key, must be CM_URI_TYPE_APP_KEY or CM_URI_TYPE_WLAN_KEY 124 alg: "alg", 125 size: 375, 126 padding: "padding purpose", 127 purpose: "purpose property", 128 digest: "digest property", 129 authType: "Sha-256", 130 authTimeout: "30" 131 } 132 133 return result; 134} 135 136parseCMSignatureSpec(alg: string, padding: string, digest: string, authToken: Uint8Array): CMSignatureSpec { 137 let result: CMSignatureSpec; 138 139 result = { 140 alg: alg, 141 padding: padding, 142 digest: digest, 143 authToken: authToken // required only for user authentication 144 } 145 146 return result; 147} 148 149}