• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { paramMock } from "../utils"
17
18export const HuksErrorCode = {
19  HUKS_SUCCESS: 0,
20  HUKS_FAILURE: -1,
21  HUKS_ERROR_BAD_STATE: -2,
22  HUKS_ERROR_INVALID_ARGUMENT: -3,
23  HUKS_ERROR_NOT_SUPPORTED: -4,
24  HUKS_ERROR_NO_PERMISSION: -5,
25  HUKS_ERROR_INSUFFICIENT_DATA: -6,
26  HUKS_ERROR_BUFFER_TOO_SMALL: -7,
27  HUKS_ERROR_INSUFFICIENT_MEMORY: -8,
28  HUKS_ERROR_COMMUNICATION_FAILURE: -9,
29  HUKS_ERROR_STORAGE_FAILURE: -10,
30  HUKS_ERROR_HARDWARE_FAILURE: -11,
31  HUKS_ERROR_ALREADY_EXISTS: -12,
32  HUKS_ERROR_NOT_EXIST: -13,
33  HUKS_ERROR_NULL_POINTER: -14,
34  HUKS_ERROR_FILE_SIZE_FAIL: -15,
35  HUKS_ERROR_READ_FILE_FAIL: -16,
36  HUKS_ERROR_INVALID_PUBLIC_KEY: -17,
37  HUKS_ERROR_INVALID_PRIVATE_KEY: -18,
38  HUKS_ERROR_INVALID_KEY_INFO: -19,
39  HUKS_ERROR_HASH_NOT_EQUAL: -20,
40  HUKS_ERROR_MALLOC_FAIL: -21,
41  HUKS_ERROR_WRITE_FILE_FAIL: -22,
42  HUKS_ERROR_REMOVE_FILE_FAIL: -23,
43  HUKS_ERROR_OPEN_FILE_FAIL: -24,
44  HUKS_ERROR_CLOSE_FILE_FAIL: -25,
45  HUKS_ERROR_MAKE_DIR_FAIL: -26,
46  HUKS_ERROR_INVALID_KEY_FILE: -27,
47  HUKS_ERROR_IPC_MSG_FAIL: -28,
48  HUKS_ERROR_REQUEST_OVERFLOWS: -29,
49  HUKS_ERROR_PARAM_NOT_EXIST: -30,
50  HUKS_ERROR_CRYPTO_ENGINE_ERROR: -31,
51  HUKS_ERROR_COMMUNICATION_TIMEOUT: -32,
52  HUKS_ERROR_IPC_INIT_FAIL: -33,
53  HUKS_ERROR_IPC_DLOPEN_FAIL: -34,
54  HUKS_ERROR_EFUSE_READ_FAIL: -35,
55  HUKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST: -36,
56  HUKS_ERROR_UPDATE_ROOT_KEY_MATERIAL_FAIL: -37,
57  HUKS_ERROR_VERIFICATION_FAILED: -38,
58
59  HUKS_ERROR_GET_USERIAM_SECINFO_FAILED: -40,
60  HUKS_ERROR_GET_USERIAM_AUTHINFO_FAILED: -41,
61  HUKS_ERROR_USER_AUTH_TYPE_NOT_SUPPORT: -42,
62  HUKS_ERROR_KEY_AUTH_FAILED: -43,
63  HUKS_ERROR_DEVICE_NO_CREDENTIAL: -44,
64
65  HUKS_ERROR_CHECK_GET_ALG_FAIL: -100,
66  HUKS_ERROR_CHECK_GET_KEY_SIZE_FAIL: -101,
67  HUKS_ERROR_CHECK_GET_PADDING_FAIL: -102,
68  HUKS_ERROR_CHECK_GET_PURPOSE_FAIL: -103,
69  HUKS_ERROR_CHECK_GET_DIGEST_FAIL: -104,
70  HUKS_ERROR_CHECK_GET_MODE_FAIL: -105,
71  HUKS_ERROR_CHECK_GET_NONCE_FAIL: -106,
72  HUKS_ERROR_CHECK_GET_AAD_FAIL: -107,
73  HUKS_ERROR_CHECK_GET_IV_FAIL: -108,
74  HUKS_ERROR_CHECK_GET_AE_TAG_FAIL: -109,
75  HUKS_ERROR_CHECK_GET_SALT_FAIL: -110,
76  HUKS_ERROR_CHECK_GET_ITERATION_FAIL: -111,
77  HUKS_ERROR_INVALID_ALGORITHM: -112,
78  HUKS_ERROR_INVALID_KEY_SIZE: -113,
79  HUKS_ERROR_INVALID_PADDING: -114,
80  HUKS_ERROR_INVALID_PURPOSE: -115,
81  HUKS_ERROR_INVALID_MODE: -116,
82  HUKS_ERROR_INVALID_DIGEST: -117,
83  HUKS_ERROR_INVALID_SIGNATURE_SIZE: -118,
84  HUKS_ERROR_INVALID_IV: -119,
85  HUKS_ERROR_INVALID_AAD: -120,
86  HUKS_ERROR_INVALID_NONCE: -121,
87  HUKS_ERROR_INVALID_AE_TAG: -122,
88  HUKS_ERROR_INVALID_SALT: -123,
89  HUKS_ERROR_INVALID_ITERATION: -124,
90  HUKS_ERROR_INVALID_OPERATION: -125,
91  HUKS_ERROR_INVALID_WRAPPED_FORMAT: -126,
92  HUKS_ERROR_INVALID_USAGE_OF_KEY: -127,
93
94  HUKS_ERROR_INTERNAL_ERROR: -999,
95  HUKS_ERROR_UNKNOWN_ERROR: -1000,
96}
97
98export const HuksKeyPurpose = {
99  HUKS_KEY_PURPOSE_ENCRYPT: 1,
100  HUKS_KEY_PURPOSE_DECRYPT: 2,
101  HUKS_KEY_PURPOSE_SIGN: 4,
102  HUKS_KEY_PURPOSE_VERIFY: 8,
103  HUKS_KEY_PURPOSE_DERIVE: 16,
104  HUKS_KEY_PURPOSE_WRAP: 32,
105  HUKS_KEY_PURPOSE_UNWRAP: 64,
106  HUKS_KEY_PURPOSE_MAC: 128,
107  HUKS_KEY_PURPOSE_AGREE: 256,
108}
109
110export const HuksKeyDigest = {
111  HUKS_DIGEST_NONE: 0,
112  HUKS_DIGEST_MD5: 1,
113  HUKS_DIGEST_SM3: 2,
114  HUKS_DIGEST_SHA1: 10,
115  HUKS_DIGEST_SHA224: 11,
116  HUKS_DIGEST_SHA256: 12,
117  HUKS_DIGEST_SHA384: 13,
118  HUKS_DIGEST_SHA512: 14,
119}
120
121export const HuksKeyPadding = {
122  HUKS_PADDING_NONE: 0,
123  HUKS_PADDING_OAEP: 1,
124  HUKS_PADDING_PSS: 2,
125  HUKS_PADDING_PKCS1_V1_5: 3,
126  HUKS_PADDING_PKCS5: 4,
127  HUKS_PADDING_PKCS7: 5,
128}
129
130export const HuksCipherMode = {
131  HUKS_MODE_ECB: 1,
132  HUKS_MODE_CBC: 2,
133  HUKS_MODE_CTR: 3,
134  HUKS_MODE_OFB: 4,
135  HUKS_MODE_CCM: 31,
136  HUKS_MODE_GCM: 32,
137}
138
139export const HuksKeySize = {
140  HUKS_RSA_KEY_SIZE_512: 512,
141  HUKS_RSA_KEY_SIZE_768: 768,
142  HUKS_RSA_KEY_SIZE_1024: 1024,
143  HUKS_RSA_KEY_SIZE_2048: 2048,
144  HUKS_RSA_KEY_SIZE_3072: 3072,
145  HUKS_RSA_KEY_SIZE_4096: 4096,
146
147  HUKS_ECC_KEY_SIZE_224: 224,
148  HUKS_ECC_KEY_SIZE_256: 256,
149  HUKS_ECC_KEY_SIZE_384: 384,
150  HUKS_ECC_KEY_SIZE_521: 521,
151
152  HUKS_AES_KEY_SIZE_128: 128,
153  HUKS_AES_KEY_SIZE_192: 192,
154  HUKS_AES_KEY_SIZE_256: 256,
155  HUKS_AES_KEY_SIZE_512: 512,
156
157  HUKS_CURVE25519_KEY_SIZE_256: 256,
158
159  HUKS_DH_KEY_SIZE_2048: 2048,
160  HUKS_DH_KEY_SIZE_3072: 3072,
161  HUKS_DH_KEY_SIZE_4096: 4096,
162
163  HUKS_SM2_KEY_SIZE_256: 256,
164  HUKS_SM4_KEY_SIZE_128: 128,
165}
166
167export const HuksKeyAlg = {
168  HUKS_ALG_RSA: 1,
169  HUKS_ALG_ECC: 2,
170  HUKS_ALG_DSA: 3,
171
172  HUKS_ALG_AES: 20,
173  HUKS_ALG_HMAC: 50,
174  HUKS_ALG_HKDF: 51,
175  HUKS_ALG_PBKDF2: 52,
176
177  HUKS_ALG_ECDH: 100,
178  HUKS_ALG_X25519: 101,
179  HUKS_ALG_ED25519: 102,
180  HUKS_ALG_DH: 103,
181
182  HUKS_ALG_SM2: 150,
183  HUKS_ALG_SM3: 151,
184  HUKS_ALG_SM4: 152,
185}
186
187export const HuksUnwrapSuite = {
188  HUKS_UNWRAP_SUITE_X25519_AES_256_GCM_NOPADDING: 1,
189  HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING: 2,
190}
191
192export const HuksKeyGenerateType = {
193  HUKS_KEY_GENERATE_TYPE_DEFAULT: 0,
194  HUKS_KEY_GENERATE_TYPE_DERIVE: 1,
195  HUKS_KEY_GENERATE_TYPE_AGREE: 2,
196}
197
198export const HuksKeyFlag = {
199  HUKS_KEY_FLAG_IMPORT_KEY: 1,
200  HUKS_KEY_FLAG_GENERATE_KEY: 2,
201  HUKS_KEY_FLAG_AGREE_KEY: 3,
202  HUKS_KEY_FLAG_DERIVE_KEY: 4,
203}
204
205export const HuksKeyStorageType = {
206  HUKS_STORAGE_TEMP: 0,
207  HUKS_STORAGE_PERSISTENT: 1,
208}
209
210export const HuksImportKeyType = {
211  HUKS_KEY_TYPE_PUBLIC_KEY: 0,
212  HUKS_KEY_TYPE_PRIVATE_KEY: 1,
213  HUKS_KEY_TYPE_KEY_PAIR: 2,
214}
215
216export const HuksUserAuthType = {
217  HUKS_USER_AUTH_TYPE_FINGERPRINT: 1,
218  HUKS_USER_AUTH_TYPE_FACE: 2,
219  HUKS_USER_AUTH_TYPE_PIN: 4,
220}
221
222export const HuksAuthAccessType = {
223  HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD: 1,
224  HUKS_AUTH_ACCESS_INVALID_NEW_BIO_ENROLL: 2,
225}
226
227export const HuksChallengeType = {
228  HUKS_CHALLENGE_TYPE_NORMAL: 0,
229  HUKS_CHALLENGE_TYPE_CUSTOM: 1,
230  HUKS_CHALLENGE_TYPE_NONE: 2,
231}
232
233export const HuksChallengePosition = {
234  HUKS_CHALLENGE_POS_0: 0,
235  HUKS_CHALLENGE_POS_1: 1,
236  HUKS_CHALLENGE_POS_2: 2,
237  HUKS_CHALLENGE_POS_3: 3,
238}
239
240export const HuksSecureSignType = {
241  HUKS_SECURE_SIGN_WITH_AUTHINFO: 1,
242}
243
244export const HuksSendType = {
245  HUKS_SEND_TYPE_ASYNC: 0,
246  HUKS_SEND_TYPE_SYNC: 1,
247}
248
249export const HuksTagType = {
250  HUKS_TAG_TYPE_INVALID: 0,
251  HUKS_TAG_TYPE_INT: 1,
252  HUKS_TAG_TYPE_UINT: 2,
253  HUKS_TAG_TYPE_ULONG: 3,
254  HUKS_TAG_TYPE_BOOL: 4,
255  HUKS_TAG_TYPE_BYTES: 5,
256}
257
258export const HuksTag = {
259  HUKS_TAG_INVALID: 0,
260
261  HUKS_TAG_ALGORITHM: 1,
262  HUKS_TAG_PURPOSE: 2,
263  HUKS_TAG_KEY_SIZE: 3,
264  HUKS_TAG_DIGEST: 4,
265  HUKS_TAG_PADDING: 5,
266  HUKS_TAG_BLOCK_MODE: 6,
267  HUKS_TAG_KEY_TYPE: 7,
268  HUKS_TAG_ASSOCIATED_DATA: 8,
269  HUKS_TAG_NONCE: 9,
270  HUKS_TAG_IV: 10,
271
272  HUKS_TAG_INFO: 11,
273  HUKS_TAG_SALT: 12,
274  HUKS_TAG_PWD: 13,
275  HUKS_TAG_ITERATION: 14,
276
277  HUKS_TAG_KEY_GENERATE_TYPE: 15,
278  HUKS_TAG_DERIVE_MAIN_KEY: 16,
279  HUKS_TAG_DERIVE_FACTOR: 17,
280  HUKS_TAG_DERIVE_ALG: 18,
281  HUKS_TAG_AGREE_ALG: 19,
282  HUKS_TAG_AGREE_PUBLIC_KEY_IS_KEY_ALIAS: 20,
283  HUKS_TAG_AGREE_PRIVATE_KEY_ALIAS: 21,
284  HUKS_TAG_AGREE_PUBLIC_KEY: 22,
285  HUKS_TAG_KEY_ALIAS: 23,
286  HUKS_TAG_DERIVE_KEY_SIZE: 24,
287  HUKS_TAG_IMPORT_KEY_TYPE: 25,
288  HUKS_TAG_UNWRAP_ALGORITHM_SUITE: 26,
289
290  HUKS_TAG_ACTIVE_DATETIME: 201,
291
292  HUKS_TAG_ORIGINATION_EXPIRE_DATETIME: 202,
293
294  HUKS_TAG_USAGE_EXPIRE_DATETIME: 203,
295
296  HUKS_TAG_CREATION_DATETIME: 204,
297
298  HUKS_TAG_ALL_USERS: 301,
299  HUKS_TAG_USER_ID: 302,
300  HUKS_TAG_NO_AUTH_REQUIRED: 303,
301  HUKS_TAG_USER_AUTH_TYPE: 304,
302  HUKS_TAG_AUTH_TIMEOUT: 305,
303  HUKS_TAG_AUTH_TOKEN: 306,
304  HUKS_TAG_KEY_AUTH_ACCESS_TYPE: 307,
305  HUKS_TAG_KEY_SECURE_SIGN_TYPE: 308,
306  HUKS_TAG_CHALLENGE_TYPE: 309,
307  HUKS_TAG_CHALLENGE_POS: 310,
308
309  HUKS_TAG_ATTESTATION_CHALLENGE: 501,
310  HUKS_TAG_ATTESTATION_APPLICATION_ID: 502,
311  HUKS_TAG_ATTESTATION_ID_BRAND: 503,
312  HUKS_TAG_ATTESTATION_ID_DEVICE: 504,
313  HUKS_TAG_ATTESTATION_ID_PRODUCT: 505,
314  HUKS_TAG_ATTESTATION_ID_SERIAL: 506,
315  HUKS_TAG_ATTESTATION_ID_IMEI: 507,
316  HUKS_TAG_ATTESTATION_ID_MEID: 508,
317  HUKS_TAG_ATTESTATION_ID_MANUFACTURER: 509,
318  HUKS_TAG_ATTESTATION_ID_MODEL: 510,
319  HUKS_TAG_ATTESTATION_ID_ALIAS: 511,
320  HUKS_TAG_ATTESTATION_ID_SOCID: 512,
321  HUKS_TAG_ATTESTATION_ID_UDID: 513,
322  HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO: 514,
323  HUKS_TAG_ATTESTATION_ID_VERSION_INFO: 515,
324
325  HUKS_TAG_IS_KEY_ALIAS: 1001,
326  HUKS_TAG_KEY_STORAGE_FLAG: 1002,
327  HUKS_TAG_IS_ALLOWED_WRAP: 1003,
328  HUKS_TAG_KEY_WRAP_TYPE: 1004,
329  HUKS_TAG_KEY_AUTH_ID: 1005,
330  HUKS_TAG_KEY_ROLE: 1006,
331  HUKS_TAG_KEY_FLAG: 1007,
332  HUKS_TAG_IS_ASYNCHRONIZED: 1008,
333  HUKS_TAG_SECURE_KEY_ALIAS: 1009,
334  HUKS_TAG_SECURE_KEY_UUID: 1010,
335  HUKS_TAG_KEY_DOMAIN: 1011,
336
337  HUKS_TAG_PROCESS_NAME: 10001,
338  HUKS_TAG_PACKAGE_NAME: 10002,
339  HUKS_TAG_ACCESS_TIME: 10003,
340  HUKS_TAG_USES_TIME: 10004,
341  HUKS_TAG_CRYPTO_CTX: 10005,
342  HUKS_TAG_KEY: 10006,
343  HUKS_TAG_KEY_VERSION: 10007,
344  HUKS_TAG_PAYLOAD_LEN: 10008,
345  HUKS_TAG_AE_TAG: 10009,
346  HUKS_TAG_IS_KEY_HANDLE: 10010,
347
348  HUKS_TAG_OS_VERSION: 10101,
349  HUKS_TAG_OS_PATCHLEVEL: 10102,
350
351  HUKS_TAG_SYMMETRIC_KEY_DATA: 20001,
352  HUKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA: 20002,
353  HUKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA: 20003,
354}
355
356export function mockHuks() {
357  const HuksParam = {
358    tag: HuksTag,
359    value: '[PC preview] unknow value',
360  }
361  const HuksHandle = {
362    errorCode: '[PC preview] unknow errorCode',
363    handle: '[PC preview] unknow handle',
364    token: paramMock.paramArrayMock,
365  }
366  const HuksOptions = {
367    properties: [HuksParam],
368    inData: paramMock.paramArrayMock,
369  }
370  const HuksResult = {
371    errorCode: '[PC preview] unknow errorCode',
372    outData: paramMock.paramArrayMock,
373    properties: [HuksParam],
374    certChains: [paramMock.paramStringMock],
375  }
376  const huks = {
377    HuksErrorCode,
378    HuksKeyPurpose,
379    HuksKeyDigest,
380    HuksKeyPadding,
381    HuksCipherMode,
382    HuksKeySize,
383    HuksKeyAlg,
384    HuksUnwrapSuite,
385    HuksKeyGenerateType,
386    HuksKeyFlag,
387    HuksKeyStorageType,
388    HuksImportKeyType,
389    HuksUserAuthType,
390    HuksAuthAccessType,
391    HuksChallengeType,
392    HuksChallengePosition,
393    HuksSecureSignType,
394    HuksSendType,
395    HuksTagType,
396    HuksTag,
397
398    generateKey: function (...args) {
399      console.warn("huks.generateKey interface mocked in the Previewer. How this interface works on the Previewer" +
400        " may be different from that on a real device.")
401      const len = args.length
402      if (typeof args[len - 1] === 'function') {
403        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
404      } else {
405        return new Promise((resolve, reject) => {
406          resolve(HuksResult)
407        })
408      }
409    },
410    deleteKey: function (...args) {
411      console.warn("huks.deleteKey interface mocked in the Previewer. How this interface works on the Previewer" +
412        " may be different from that on a real device.")
413      const len = args.length
414      if (typeof args[len - 1] === 'function') {
415        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
416      } else {
417        return new Promise((resolve, reject) => {
418          resolve(HuksResult)
419        })
420      }
421    },
422    importKey: function (...args) {
423      console.warn("huks.importKey interface mocked in the Previewer. How this interface works on the Previewer" +
424        " may be different from that on a real device.")
425      const len = args.length
426      if (typeof args[len - 1] === 'function') {
427        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
428      } else {
429        return new Promise((resolve, reject) => {
430          resolve(HuksResult)
431        })
432      }
433    },
434    importWrappedKey: function (...args) {
435      console.warn("huks.importWrappedKey interface mocked in the Previewer. How this interface works on the Previewer" +
436        " may be different from that on a real device.")
437      const len = args.length
438      if (typeof args[len - 1] === 'function') {
439        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
440      } else {
441        return new Promise((resolve, reject) => {
442          resolve(HuksResult)
443        })
444      }
445    },
446    exportKey: function (...args) {
447      console.warn("huks.exportKey interface mocked in the Previewer. How this interface works on the Previewer" +
448        " may be different from that on a real device.")
449      const len = args.length
450      if (typeof args[len - 1] === 'function') {
451        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
452      } else {
453        return new Promise((resolve, reject) => {
454          resolve(HuksResult)
455        })
456      }
457    },
458    getKeyProperties: function (...args) {
459      console.warn("huks.getKeyProperties interface mocked in the Previewer. How this interface works on the Previewer" +
460        " may be different from that on a real device.")
461      const len = args.length
462      if (typeof args[len - 1] === 'function') {
463        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
464      } else {
465        return new Promise((resolve, reject) => {
466          resolve(HuksResult)
467        })
468      }
469    },
470    isKeyExist: function (...args) {
471      console.warn("huks.isKeyExist interface mocked in the Previewer. How this interface works on the Previewer" +
472        " may be different from that on a real device.")
473      const len = args.length
474      if (typeof args[len - 1] === 'function') {
475        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
476      } else {
477        return new Promise((resolve, reject) => {
478          resolve(paramMock.paramBooleanMock)
479        })
480      }
481    },
482    init: function (...args) {
483      console.warn("huks.init interface mocked in the Previewer. How this interface works on the Previewer" +
484        " may be different from that on a real device.")
485      const len = args.length
486      if (typeof args[len - 1] === 'function') {
487        args[len - 1].call(this, paramMock.businessErrorMock, HuksHandle)
488      } else {
489        return new Promise((resolve, reject) => {
490          resolve(HuksResult)
491        })
492      }
493    },
494    update: function (...args) {
495      console.warn("huks.update interface mocked in the Previewer. How this interface works on the Previewer" +
496        " may be different from that on a real device.")
497      const len = args.length
498      if (typeof args[len - 1] === 'function') {
499        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
500      } else {
501        return new Promise((resolve, reject) => {
502          resolve(HuksResult)
503        })
504      }
505    },
506    finish: function (...args) {
507      console.warn("huks.finish interface mocked in the Previewer. How this interface works on the Previewer" +
508        " may be different from that on a real device.")
509      const len = args.length
510      if (typeof args[len - 1] === 'function') {
511        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
512      } else {
513        return new Promise((resolve, reject) => {
514          resolve(HuksResult)
515        })
516      }
517    },
518    abort: function (...args) {
519      console.warn("huks.abort interface mocked in the Previewer. How this interface works on the Previewer" +
520        " may be different from that on a real device.")
521      const len = args.length
522      if (typeof args[len - 1] === 'function') {
523        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
524      } else {
525        return new Promise((resolve, reject) => {
526          resolve(HuksResult)
527        })
528      }
529    },
530    attestKey: function (...args) {
531      console.warn("huks.attestKey interface mocked in the Previewer. How this interface works on the Previewer" +
532        " may be different from that on a real device.")
533      const len = args.length
534      if (typeof args[len - 1] === 'function') {
535        args[len - 1].call(this, paramMock.businessErrorMock, HuksResult)
536      } else {
537        return new Promise((resolve, reject) => {
538          resolve(HuksResult)
539        })
540      }
541    },
542    getSdkVersion: function (...args) {
543      console.warn("huks.getSdkVersion interface mocked in the Previewer. How this interface works on the Previewer" +
544        " may be different from that on a real device.")
545      return paramMock.paramStringMock;
546    },
547  }
548  return huks
549}