• 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 function mockCryptoFramework() {
19  const DataBlob = {
20    data: paramMock.paramArrayMock,
21  }
22  const DataArray = {
23    data: [paramMock.paramArrayMock],
24  }
25  const EncodingBlob = {
26    data: paramMock.paramArrayMock,
27    encodingFormat: "[PC Preview] unknow encodingFormat",
28  }
29  const SymKey = {
30    format: "[PC Preview] unknow format",
31    algName: "[PC Preview] unknow algName",
32    getEncoded: function () {
33      console.warn("SymKey.getEncoded interface mocked in the Previewer." +
34      " How this interface works on the Previewer may be different from that on a real device.")
35      return DataBlob
36    },
37    clearMem: function () {
38      console.warn("SymKey.clearMem interface mocked in the Previewer." +
39      " How this interface works on the Previewer may be different from that on a real device.")
40    },
41  }
42  const PriKey = {
43    format: "[PC Preview] unknow format",
44    algName: "[PC Preview] unknow algName",
45    getEncoded: function () {
46      console.warn("PriKey.getEncoded interface mocked in the Previewer." +
47      " How this interface works on the Previewer may be different from that on a real device.")
48      return DataBlob
49    },
50    clearMem: function () {
51      console.warn("PriKey.clearMem interface mocked in the Previewer." +
52      " How this interface works on the Previewer may be different from that on a real device.")
53    },
54  }
55  const PubKey = {
56    format: "[PC Preview] unknow format",
57    algName: "[PC Preview] unknow algName",
58    getEncoded: function () {
59      console.warn("PubKey.getEncoded interface mocked in the Previewer." +
60      " How this interface works on the Previewer may be different from that on a real device.")
61      return DataBlob
62    },
63  }
64  const KeyPair = {
65    priKey: PriKey,
66    pubKey: PubKey,
67  }
68  const Random = {
69    generateRandom: function (...args) {
70      console.warn("Random.generateRandom interface mocked in the Previewer." +
71        " How this interface works on the Previewer may be different from that on a real device.")
72      const len = args.length
73      if (typeof args[len - 1] === 'function') {
74        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
75      } else {
76        return new Promise((resolve, reject) => {
77          resolve(DataBlob);
78        })
79      }
80    },
81    setSeed: function (...args) {
82      console.warn("Random.setSeed interface mocked in the Previewer." +
83      " How this interface works on the Previewer may be different from that on a real device.")
84      const len = args.length
85      if (typeof args[len - 1] === 'function') {
86        args[len - 1].call(this, paramMock.businessErrorMock);
87      } else {
88        return new Promise((resolve, reject) => {
89          resolve();
90        })
91      }
92    },
93  }
94  const AsyKeyGenerator = {
95    algName: "[PC Preview] unknow algName",
96    generateKeyPair: function (...args) {
97      console.warn("AsyKeyGenerator.generateKeyPair interface mocked in the Previewer." +
98        " How this interface works on the Previewer may be different from that on a real device.")
99      const len = args.length
100      if (typeof args[len - 1] === 'function') {
101        args[len - 1].call(this, paramMock.businessErrorMock, KeyPair);
102      } else {
103        return new Promise((resolve, reject) => {
104          resolve(KeyPair);
105        })
106      }
107    },
108    convertKey: function (...args) {
109      console.warn("AsyKeyGenerator.convertKey interface mocked in the Previewer." +
110      " How this interface works on the Previewer may be different from that on a real device.")
111      const len = args.length
112      if (typeof args[len - 1] === 'function') {
113        args[len - 1].call(this, paramMock.businessErrorMock, KeyPair);
114      } else {
115        return new Promise((resolve, reject) => {
116          resolve(KeyPair);
117        })
118      }
119    },
120  }
121  const SymKeyGenerator = {
122    algName: "[PC Preview] unknow algName",
123    generateSymKey: function (...args) {
124      console.warn("SymKeyGenerator.generateSymKey interface mocked in the Previewer." +
125        " How this interface works on the Previewer may be different from that on a real device.")
126      const len = args.length
127      if (typeof args[len - 1] === 'function') {
128        args[len - 1].call(this, paramMock.businessErrorMock, SymKey);
129      } else {
130        return new Promise((resolve, reject) => {
131          resolve(SymKey);
132        })
133      }
134    },
135    convertKey: function (...args) {
136      console.warn("SymKeyGenerator.convertKey interface mocked in the Previewer." +
137      " How this interface works on the Previewer may be different from that on a real device.")
138      const len = args.length
139      if (typeof args[len - 1] === 'function') {
140        args[len - 1].call(this, paramMock.businessErrorMock, SymKey);
141      } else {
142        return new Promise((resolve, reject) => {
143          resolve(SymKey);
144        })
145      }
146    },
147  }
148  const Mac = {
149    algName: "[PC Preview] unknow algName",
150    init: function (...args) {
151      console.warn("Mac.init interface mocked in the Previewer." +
152        " How this interface works on the Previewer may be different from that on a real device.")
153      const len = args.length
154      if (typeof args[len - 1] === 'function') {
155        args[len - 1].call(this, paramMock.businessErrorMock);
156      } else {
157        return new Promise((resolve, reject) => {
158          resolve();
159        })
160      }
161    },
162    update: function (...args) {
163      console.warn("Mac.update interface mocked in the Previewer." +
164      " How this interface works on the Previewer may be different from that on a real device.")
165      const len = args.length
166      if (typeof args[len - 1] === 'function') {
167        args[len - 1].call(this, paramMock.businessErrorMock);
168      } else {
169        return new Promise((resolve, reject) => {
170          resolve();
171        })
172      }
173    },
174    doFinal: function (...args) {
175      console.warn("Mac.doFinal interface mocked in the Previewer." +
176      " How this interface works on the Previewer may be different from that on a real device.")
177      const len = args.length
178      if (typeof args[len - 1] === 'function') {
179        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
180      } else {
181        return new Promise((resolve, reject) => {
182          resolve(DataBlob);
183        })
184      }
185    },
186    getMacLength: function () {
187      console.warn("Mac.getMacLength interface mocked in the Previewer." +
188      " How this interface works on the Previewer may be different from that on a real device.")
189      return paramMock.paramNumberMock
190    },
191  }
192  const Md = {
193    algName: "[PC Preview] unknow algName",
194    update: function (...args) {
195      console.warn("Md.update interface mocked in the Previewer." +
196      " How this interface works on the Previewer may be different from that on a real device.")
197      const len = args.length
198      if (typeof args[len - 1] === 'function') {
199        args[len - 1].call(this, paramMock.businessErrorMock);
200      } else {
201        return new Promise((resolve, reject) => {
202          resolve();
203        })
204      }
205    },
206    digest: function (...args) {
207      console.warn("Md.digest interface mocked in the Previewer." +
208      " How this interface works on the Previewer may be different from that on a real device.")
209      const len = args.length
210      if (typeof args[len - 1] === 'function') {
211        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
212      } else {
213        return new Promise((resolve, reject) => {
214          resolve(DataBlob);
215        })
216      }
217    },
218    getMdLength: function () {
219      console.warn("Md.getMdLength interface mocked in the Previewer." +
220      " How this interface works on the Previewer may be different from that on a real device.")
221      return paramMock.paramNumberMock
222    },
223  }
224  const Cipher = {
225    algName: "[PC Preview] unknow algName",
226    init: function (...args) {
227      console.warn("Cipher.init interface mocked in the Previewer." +
228        " How this interface works on the Previewer may be different from that on a real device.")
229      const len = args.length
230      if (typeof args[len - 1] === 'function') {
231        args[len - 1].call(this, paramMock.businessErrorMock);
232      } else {
233        return new Promise((resolve, reject) => {
234          resolve();
235        })
236      }
237    },
238    update: function (...args) {
239      console.warn("Cipher.update interface mocked in the Previewer." +
240      " How this interface works on the Previewer may be different from that on a real device.")
241      const len = args.length
242      if (typeof args[len - 1] === 'function') {
243        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
244      } else {
245        return new Promise((resolve, reject) => {
246          resolve(DataBlob);
247        })
248      }
249    },
250    doFinal: function (...args) {
251      console.warn("Cipher.doFinal interface mocked in the Previewer." +
252      " How this interface works on the Previewer may be different from that on a real device.")
253      const len = args.length
254      if (typeof args[len - 1] === 'function') {
255        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
256      } else {
257        return new Promise((resolve, reject) => {
258          resolve(DataBlob);
259        })
260      }
261    },
262  }
263  const Sign = {
264    algName: "[PC Preview] unknow algName",
265    init: function (...args) {
266      console.warn("Sign.init interface mocked in the Previewer." +
267        " How this interface works on the Previewer may be different from that on a real device.")
268      const len = args.length
269      if (typeof args[len - 1] === 'function') {
270        args[len - 1].call(this, paramMock.businessErrorMock);
271      } else {
272        return new Promise((resolve, reject) => {
273          resolve();
274        })
275      }
276    },
277    update: function (...args) {
278      console.warn("Sign.update interface mocked in the Previewer." +
279      " How this interface works on the Previewer may be different from that on a real device.")
280      const len = args.length
281      if (typeof args[len - 1] === 'function') {
282        args[len - 1].call(this, paramMock.businessErrorMock);
283      } else {
284        return new Promise((resolve, reject) => {
285          resolve();
286        })
287      }
288    },
289    sign: function (...args) {
290      console.warn("Sign.sign interface mocked in the Previewer." +
291      " How this interface works on the Previewer may be different from that on a real device.")
292      const len = args.length
293      if (typeof args[len - 1] === 'function') {
294        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
295      } else {
296        return new Promise((resolve, reject) => {
297          resolve(DataBlob);
298        })
299      }
300    },
301  }
302  const Verify = {
303    algName: "[PC Preview] unknow algName",
304    init: function (...args) {
305      console.warn("Verify.init interface mocked in the Previewer." +
306        " How this interface works on the Previewer may be different from that on a real device.")
307      const len = args.length
308      if (typeof args[len - 1] === 'function') {
309        args[len - 1].call(this, paramMock.businessErrorMock);
310      } else {
311        return new Promise((resolve, reject) => {
312          resolve();
313        })
314      }
315    },
316    update: function (...args) {
317      console.warn("Verify.update interface mocked in the Previewer." +
318      " How this interface works on the Previewer may be different from that on a real device.")
319      const len = args.length
320      if (typeof args[len - 1] === 'function') {
321        args[len - 1].call(this, paramMock.businessErrorMock);
322      } else {
323        return new Promise((resolve, reject) => {
324          resolve();
325        })
326      }
327    },
328    verify: function (...args) {
329      console.warn("Verify.verify interface mocked in the Previewer." +
330      " How this interface works on the Previewer may be different from that on a real device.")
331      const len = args.length
332      if (typeof args[len - 1] === 'function') {
333        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
334      } else {
335        return new Promise((resolve, reject) => {
336          resolve(paramMock.paramBooleanMock);
337        })
338      }
339    },
340  }
341  const KeyAgreement = {
342    algName: "[PC Preview] unknow algName",
343    generateSecret: function (...args) {
344      console.warn("KeyAgreement.generateSecret interface mocked in the Previewer." +
345        " How this interface works on the Previewer may be different from that on a real device.")
346      const len = args.length
347      if (typeof args[len - 1] === 'function') {
348        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
349      } else {
350        return new Promise((resolve, reject) => {
351          resolve(DataBlob);
352        })
353      }
354    },
355  }
356  const X509Cert = {
357    verify: function (...args) {
358      console.warn("X509Cert.verify interface mocked in the Previewer." +
359        " How this interface works on the Previewer may be different from that on a real device.")
360      const len = args.length
361      if (typeof args[len - 1] === 'function') {
362        args[len - 1].call(this, paramMock.businessErrorMock);
363      } else {
364        return new Promise((resolve, reject) => {
365          resolve();
366        })
367      }
368    },
369    getEncoded: function (...args) {
370      console.warn("X509Cert.getEncoded interface mocked in the Previewer." +
371        " How this interface works on the Previewer may be different from that on a real device.")
372      const len = args.length
373      if (typeof args[len - 1] === 'function') {
374        args[len - 1].call(this, paramMock.businessErrorMock, EncodingBlob);
375      } else {
376        return new Promise((resolve, reject) => {
377          resolve(EncodingBlob);
378        })
379      }
380    },
381    getPublicKey: function (...args) {
382      console.warn("X509Cert.getPublicKey interface mocked in the Previewer." +
383        " How this interface works on the Previewer may be different from that on a real device.")
384      const len = args.length
385      if (typeof args[len - 1] === 'function') {
386        args[len - 1].call(this, paramMock.businessErrorMock, PubKey);
387      } else {
388        return new Promise((resolve, reject) => {
389          resolve(PubKey);
390        })
391      }
392    },
393    checkValidityWithDate: function (...args) {
394      console.warn("X509Cert.checkValidityWithDate interface mocked in the Previewer." +
395        " How this interface works on the Previewer may be different from that on a real device.")
396      const len = args.length
397      if (typeof args[len - 1] === 'function') {
398        args[len - 1].call(this, paramMock.businessErrorMock);
399      } else {
400        return new Promise((resolve, reject) => {
401          resolve();
402        })
403      }
404    },
405    getVersion: function () {
406      console.warn("X509Cert.getVersion interface mocked in the Previewer." +
407        " How this interface works on the Previewer may be different from that on a real device.")
408      return paramMock.paramNumberMock
409    },
410    getSerialNumber: function () {
411      console.warn("X509Cert.getSerialNumber interface mocked in the Previewer." +
412        " How this interface works on the Previewer may be different from that on a real device.")
413      return paramMock.paramNumberMock
414    },
415    getIssuerName: function () {
416      console.warn("X509Cert.getIssuerName interface mocked in the Previewer." +
417        " How this interface works on the Previewer may be different from that on a real device.")
418      return DataBlob
419    },
420    getSubjectName: function () {
421      console.warn("X509Cert.getSubjectName interface mocked in the Previewer." +
422        " How this interface works on the Previewer may be different from that on a real device.")
423      return DataBlob
424    },
425    getNotBeforeTime: function () {
426      console.warn("X509Cert.getNotBeforeTime interface mocked in the Previewer." +
427        " How this interface works on the Previewer may be different from that on a real device.")
428      return paramMock.paramStringMock
429    },
430    getNotAfterTime: function () {
431      console.warn("X509Cert.getNotAfterTime interface mocked in the Previewer." +
432        " How this interface works on the Previewer may be different from that on a real device.")
433      return paramMock.paramStringMock
434    },
435    getSignature: function () {
436      console.warn("X509Cert.getSignature interface mocked in the Previewer." +
437        " How this interface works on the Previewer may be different from that on a real device.")
438      return DataBlob
439    },
440    getSignatureAlgName: function () {
441      console.warn("X509Cert.getSignatureAlgName interface mocked in the Previewer." +
442        " How this interface works on the Previewer may be different from that on a real device.")
443      return paramMock.paramStringMock
444    },
445    getSignatureAlgOid: function () {
446      console.warn("X509Cert.getSignatureAlgOid interface mocked in the Previewer." +
447        " How this interface works on the Previewer may be different from that on a real device.")
448      return paramMock.paramStringMock
449    },
450    getSignatureAlgParams: function () {
451      console.warn("X509Cert.getSignatureAlgParams interface mocked in the Previewer." +
452        " How this interface works on the Previewer may be different from that on a real device.")
453      return DataBlob
454    },
455    getKeyUsage: function () {
456      console.warn("X509Cert.getKeyUsage interface mocked in the Previewer." +
457        " How this interface works on the Previewer may be different from that on a real device.")
458      return DataBlob
459    },
460    getExtKeyUsage: function () {
461      console.warn("X509Cert.getExtKeyUsage interface mocked in the Previewer." +
462        " How this interface works on the Previewer may be different from that on a real device.")
463      return DataArray
464    },
465    getBasicConstraints: function () {
466      console.warn("X509Cert.getBasicConstraints interface mocked in the Previewer." +
467        " How this interface works on the Previewer may be different from that on a real device.")
468      return paramMock.paramNumberMock
469    },
470    getSubjectAltNames: function () {
471      console.warn("X509Cert.getSubjectAltNames interface mocked in the Previewer." +
472        " How this interface works on the Previewer may be different from that on a real device.")
473      return DataArray
474    },
475    getIssuerAltNames: function () {
476      console.warn("X509Cert.getIssuerAltNames interface mocked in the Previewer." +
477        " How this interface works on the Previewer may be different from that on a real device.")
478      return DataArray
479    },
480  }
481  const X509CrlEntry = {
482    getEncoded: function (...args) {
483      console.warn("X509CrlEntry.getEncoded interface mocked in the Previewer." +
484        " How this interface works on the Previewer 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, EncodingBlob);
488      } else {
489        return new Promise((resolve, reject) => {
490          resolve(EncodingBlob);
491        })
492      }
493    },
494    getSerialNumber: function () {
495      console.warn("X509CrlEntry.getSerialNumber interface mocked in the Previewer." +
496        " How this interface works on the Previewer may be different from that on a real device.")
497      return paramMock.paramNumberMock
498    },
499    getCertIssuer: function (...args) {
500      console.warn("X509CrlEntry.getCertIssuer interface mocked in the Previewer." +
501        " How this interface works on the Previewer may be different from that on a real device.")
502      const len = args.length
503      if (typeof args[len - 1] === 'function') {
504        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
505      } else {
506        return new Promise((resolve, reject) => {
507          resolve(DataBlob);
508        })
509      }
510    },
511    getRevocationDate: function (...args) {
512      console.warn("X509CrlEntry.getRevocationDate interface mocked in the Previewer." +
513        " How this interface works on the Previewer may be different from that on a real device.")
514      const len = args.length
515      if (typeof args[len - 1] === 'function') {
516        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
517      } else {
518        return new Promise((resolve, reject) => {
519          resolve(paramMock.paramStringMock);
520        })
521      }
522    },
523  }
524  const X509Crl = {
525    isRevoked: function (...args) {
526      console.warn("X509Crl.isRevoked interface mocked in the Previewer." +
527        " How this interface works on the Previewer may be different from that on a real device.")
528      const len = args.length
529      if (typeof args[len - 1] === 'function') {
530        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
531      } else {
532        return new Promise((resolve, reject) => {
533          resolve(paramMock.paramBooleanMock);
534        })
535      }
536    },
537    getType: function () {
538      console.warn("X509Crl.getType interface mocked in the Previewer." +
539        " How this interface works on the Previewer may be different from that on a real device.")
540      return paramMock.paramStringMock
541    },
542    getEncoded: function (...args) {
543      console.warn("X509Crl.getEncoded interface mocked in the Previewer." +
544        " How this interface works on the Previewer may be different from that on a real device.")
545      const len = args.length
546      if (typeof args[len - 1] === 'function') {
547        args[len - 1].call(this, paramMock.businessErrorMock, EncodingBlob);
548      } else {
549        return new Promise((resolve, reject) => {
550          resolve(EncodingBlob);
551        })
552      }
553    },
554    verify: function (...args) {
555      console.warn("X509Crl.verify interface mocked in the Previewer." +
556        " How this interface works on the Previewer may be different from that on a real device.")
557      const len = args.length
558      if (typeof args[len - 1] === 'function') {
559        args[len - 1].call(this, paramMock.businessErrorMock);
560      } else {
561        return new Promise((resolve, reject) => {
562          resolve();
563        })
564      }
565    },
566    getVersion: function () {
567      console.warn("X509Crl.getVersion interface mocked in the Previewer." +
568        " How this interface works on the Previewer may be different from that on a real device.")
569      return paramMock.paramNumberMock
570    },
571    getIssuerName: function () {
572      console.warn("X509Crl.getIssuerName interface mocked in the Previewer." +
573        " How this interface works on the Previewer may be different from that on a real device.")
574      return DataBlob
575    },
576    getLastUpdate: function () {
577      console.warn("X509Crl.getLastUpdate interface mocked in the Previewer." +
578        " How this interface works on the Previewer may be different from that on a real device.")
579      return paramMock.paramStringMock
580    },
581    getNextUpdate: function () {
582      console.warn("X509Crl.getNextUpdate interface mocked in the Previewer." +
583        " How this interface works on the Previewer may be different from that on a real device.")
584      return paramMock.paramStringMock
585    },
586    getRevokedCert: function (...args) {
587      console.warn("X509Crl.getRevokedCert interface mocked in the Previewer." +
588        " How this interface works on the Previewer may be different from that on a real device.")
589      const len = args.length
590      if (typeof args[len - 1] === 'function') {
591        args[len - 1].call(this, paramMock.businessErrorMock, X509CrlEntry);
592      } else {
593        return new Promise((resolve, reject) => {
594          resolve(X509CrlEntry);
595        })
596      }
597    },
598    getRevokedCertWithCert: function (...args) {
599      console.warn("X509Crl.getRevokedCertWithCert interface mocked in the Previewer." +
600        " How this interface works on the Previewer may be different from that on a real device.")
601      const len = args.length
602      if (typeof args[len - 1] === 'function') {
603        args[len - 1].call(this, paramMock.businessErrorMock, X509CrlEntry);
604      } else {
605        return new Promise((resolve, reject) => {
606          resolve(X509CrlEntry);
607        })
608      }
609    },
610    getRevokedCerts: function (...args) {
611      console.warn("X509Crl.getRevokedCerts interface mocked in the Previewer." +
612        " How this interface works on the Previewer may be different from that on a real device.")
613      const len = args.length
614      if (typeof args[len - 1] === 'function') {
615        args[len - 1].call(this, paramMock.businessErrorMock, [X509CrlEntry]);
616      } else {
617        return new Promise((resolve, reject) => {
618          resolve([X509CrlEntry]);
619        })
620      }
621    },
622    getTbsInfo: function (...args) {
623      console.warn("X509Crl.getTbsInfo interface mocked in the Previewer." +
624        " How this interface works on the Previewer may be different from that on a real device.")
625      const len = args.length
626      if (typeof args[len - 1] === 'function') {
627        args[len - 1].call(this, paramMock.businessErrorMock, DataBlob);
628      } else {
629        return new Promise((resolve, reject) => {
630          resolve(DataBlob);
631        })
632      }
633    },
634    getSignature: function () {
635      console.warn("X509Crl.getSignature interface mocked in the Previewer." +
636        " How this interface works on the Previewer may be different from that on a real device.")
637      return DataBlob
638    },
639    getSignatureAlgName: function () {
640      console.warn("X509Crl.getSignatureAlgName interface mocked in the Previewer." +
641        " How this interface works on the Previewer may be different from that on a real device.")
642      return paramMock.paramStringMock
643    },
644    getSignatureAlgOid: function () {
645      console.warn("X509Crl.getSignatureAlgOid interface mocked in the Previewer." +
646        " How this interface works on the Previewer may be different from that on a real device.")
647      return paramMock.paramStringMock
648    },
649    getSignatureAlgParams: function () {
650      console.warn("X509Crl.getSignatureAlgParams interface mocked in the Previewer." +
651        " How this interface works on the Previewer may be different from that on a real device.")
652      return DataBlob
653    },
654  }
655  const CertChainValidator = {
656    algorithm: "[PC Preview] unknow algorithm",
657    validate: function (...args) {
658      console.warn("CertChainValidator.validate interface mocked in the Previewer." +
659        " How this interface works on the Previewer may be different from that on a real device.")
660      const len = args.length
661      if (typeof args[len - 1] === 'function') {
662        args[len - 1].call(this, paramMock.businessErrorMock);
663      } else {
664        return new Promise((resolve, reject) => {
665          resolve();
666        })
667      }
668    },
669  }
670  const cryptoFramework = {
671    Result: {
672      INVALID_PARAMS: 401,
673      NOT_SUPPORT: 801,
674      ERR_OUT_OF_MEMORY: 17620001,
675      ERR_INTERNAL_ERROR: 17620002,
676      ERR_CRYPTO_OPERATION: 17630001,
677      ERR_CERT_SIGNATURE_FAILURE: 17630002,
678      ERR_CERT_NOT_YET_VALID: 17630003,
679      ERR_CERT_HAS_EXPIRED: 17630004,
680      ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: 17630005,
681      ERR_KEYUSAGE_NO_CERTSIGN: 17630006,
682      ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE: 17630007,
683    },
684    EncodingFormat: {
685      FORMAT_DER: 0,
686      FORMAT_PEM: 1,
687    },
688    CryptoMode: {
689      ENCRYPT_MODE: 0,
690      DECRYPT_MODE: 1,
691    },
692    createRandom: function () {
693      console.warn("cryptoFramework.createRandom interface mocked in the Previewer." +
694        " How this interface works on the Previewer may be different from that on a real device.")
695      return Random;
696    },
697    createAsyKeyGenerator: function (...args) {
698      console.warn("cryptoFramework.createAsyKeyGenerator interface mocked in the Previewer." +
699        " How this interface works on the Previewer may be different from that on a real device.")
700      return AsyKeyGenerator;
701    },
702    createSymKeyGenerator: function (...args) {
703      console.warn("cryptoFramework.createSymKeyGenerator interface mocked in the Previewer." +
704        " How this interface works on the Previewer may be different from that on a real device.")
705      return SymKeyGenerator;
706    },
707    createMac: function (...args) {
708      console.warn("cryptoFramework.createMac interface mocked in the Previewer." +
709        " How this interface works on the Previewer may be different from that on a real device.")
710      return Mac;
711    },
712    createMd: function (...args) {
713      console.warn("cryptoFramework.createMd interface mocked in the Previewer." +
714        " How this interface works on the Previewer may be different from that on a real device.")
715      return Md;
716    },
717    createCipher: function (...args) {
718      console.warn("cryptoFramework.createCipher interface mocked in the Previewer." +
719        " How this interface works on the Previewer may be different from that on a real device.")
720      return Cipher;
721    },
722    createSign: function (...args) {
723      console.warn("cryptoFramework.createSign interface mocked in the Previewer." +
724        " How this interface works on the Previewer may be different from that on a real device.")
725      return Sign;
726    },
727    createVerify: function (...args) {
728      console.warn("cryptoFramework.createVerify interface mocked in the Previewer." +
729        " How this interface works on the Previewer may be different from that on a real device.")
730      return Verify;
731    },
732    createKeyAgreement: function (...args) {
733      console.warn("cryptoFramework.createKeyAgreement interface mocked in the Previewer." +
734        " How this interface works on the Previewer may be different from that on a real device.")
735      return KeyAgreement;
736    },
737    createX509Cert: function (...args) {
738      console.warn("cryptoFramework.createX509Cert interface mocked in the Previewer." +
739        " How this interface works on the Previewer may be different from that on a real device.")
740      const len = args.length
741      if (typeof args[len - 1] === 'function') {
742        args[len - 1].call(this, paramMock.businessErrorMock, X509Cert);
743      } else {
744        return new Promise((resolve, reject) => {
745          resolve(X509Cert);
746        })
747      }
748    },
749    createX509Crl: function (...args) {
750      console.warn("cryptoFramework.createX509Crl interface mocked in the Previewer." +
751        " How this interface works on the Previewer may be different from that on a real device.")
752      const len = args.length
753      if (typeof args[len - 1] === 'function') {
754        args[len - 1].call(this, paramMock.businessErrorMock, X509Crl);
755      } else {
756        return new Promise((resolve, reject) => {
757          resolve(X509Crl);
758        })
759      }
760    },
761    createCertChainValidator: function (...args) {
762      console.warn("cryptoFramework.createCertChainValidator interface mocked in the Previewer." +
763        " How this interface works on the Previewer may be different from that on a real device.")
764      return CertChainValidator;
765    },
766  }
767  return cryptoFramework;
768}
769