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 */
15
16/**
17 * @file
18 * @kit DeviceCertificateKit
19 */
20
21import type common from '@ohos.app.ability.common';
22
23/**
24 * OpenHarmony Universal CertificateManager
25 *
26 * @namespace certificateManagerDialog
27 * @syscap SystemCapability.Security.CertificateManagerDialog
28 * @stagemodelonly
29 * @since 13
30 */
31declare namespace certificateManagerDialog {
32  /**
33   * Enum for result code
34   *
35   * @enum { number }
36   * @syscap SystemCapability.Security.CertificateManagerDialog
37   * @stagemodelonly
38   * @since 13
39   */
40  export enum CertificateDialogErrorCode {
41
42    /**
43     * Indicates that internal error.
44     *
45     * @syscap SystemCapability.Security.CertificateManagerDialog
46     * @stagemodelonly
47     * @since 13
48     */
49    ERROR_GENERIC = 29700001,
50
51    /**
52     * Indicates the user cancels the operation.
53     *
54     * @syscap SystemCapability.Security.CertificateManagerDialog
55     * @stagemodelonly
56     * @since 14
57     */
58    ERROR_OPERATION_CANCELED = 29700002,
59    
60    /**
61     * Indicates that the user operation failed in the certificate manager dialog, such as install certificate failed.
62     *
63     * @syscap SystemCapability.Security.CertificateManagerDialog
64     * @stagemodelonly
65     * @since 14
66     */
67    ERROR_OPERATION_FAILED = 29700003,
68
69    /**
70     * Indicates that the API is not supported on this device.
71     *
72     * @syscap SystemCapability.Security.CertificateManagerDialog
73     * @stagemodelonly
74     * @since 14
75     */
76    ERROR_DEVICE_NOT_SUPPORTED = 29700004
77  }
78
79
80  /**
81   * Enum for page type of certificate manager dialog
82   *
83   * @enum { number }
84   * @syscap SystemCapability.Security.CertificateManagerDialog
85   * @stagemodelonly
86   * @since 13
87   */
88  export enum CertificateDialogPageType {
89    /**
90     * Indicates the main entrance page.
91     *
92     * @syscap SystemCapability.Security.CertificateManagerDialog
93     * @stagemodelonly
94     * @since 13
95     */
96    PAGE_MAIN = 1,
97
98    /**
99     * Indicates the CA certificate list page.
100     *
101     * @syscap SystemCapability.Security.CertificateManagerDialog
102     * @stagemodelonly
103     * @since 13
104     */
105    PAGE_CA_CERTIFICATE = 2,
106    
107    /**
108     * Indicates the Credential list page.
109     *
110     * @syscap SystemCapability.Security.CertificateManagerDialog
111     * @stagemodelonly
112     * @since 13
113     */
114    PAGE_CREDENTIAL = 3,
115
116    /**
117     * Indicates the install certificate page.
118     *
119     * @syscap SystemCapability.Security.CertificateManagerDialog
120     * @stagemodelonly
121     * @since 13
122     */
123    PAGE_INSTALL_CERTIFICATE = 4
124  }
125
126  /**
127   * open certificate manager dialog and show the specified page.
128   *
129   * @permission ohos.permission.ACCESS_CERT_MANAGER
130   * @param { common.Context } context - Hap context information.
131   * @param { CertificateDialogPageType } pageType - Indicates page type.
132   * @returns { Promise<void> } The promise returned by the function.
133   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
134   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
135   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
136   * @throws { BusinessError } 29700001 - Internal error.
137   * @syscap SystemCapability.Security.CertificateManagerDialog
138   * @stagemodelonly
139   * @since 13
140   */
141  function openCertificateManagerDialog(context: common.Context, pageType: CertificateDialogPageType): Promise<void>;
142
143
144
145  /**
146   * Enum for certificate type
147   *
148   * @enum { number }
149   * @syscap SystemCapability.Security.CertificateManagerDialog
150   * @stagemodelonly
151   * @since 14
152   */
153  export enum CertificateType {
154    /**
155     * Indicates CA certificate.
156     *
157     * @syscap SystemCapability.Security.CertificateManagerDialog
158     * @stagemodelonly
159     * @since 14
160     */
161    CA_CERT = 1
162  }
163
164  /**
165   * Enum for certificate scope
166   *
167   * @enum { number }
168   * @syscap SystemCapability.Security.CertificateManagerDialog
169   * @stagemodelonly
170   * @since 14
171   */
172  export enum CertificateScope {
173    /**
174     * Indicates the certificate is for current user.
175     *
176     * @syscap SystemCapability.Security.CertificateManagerDialog
177     * @stagemodelonly
178     * @since 14
179     */
180    CURRENT_USER = 1
181  }
182
183  /**
184   * open install certificate dialog.
185   *
186   * @permission ohos.permission.ACCESS_CERT_MANAGER
187   * @param { common.Context } context - Hap context information
188   * @param { CertificateType } certType - Indicates the type of certificate to be installed.
189   * @param { CertificateScope } certScope - Indicates the user scope of certificate to be installed.
190   * @param { Uint8Array } cert - Indicates the contents of the certificate file to be installed.
191   * @returns { Promise<string> } The uri of installed certificate.
192   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
193   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
194   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
195   * @throws { BusinessError } 29700001 - Internal error.
196   * @throws { BusinessError } 29700002 - The user cancels the installation operation.
197   * @throws { BusinessError } 29700003 - The user install certificate failed in the certificate manager dialog.
198   * @throws { BusinessError } 29700004 - The API is not supported on this device.
199   * @syscap SystemCapability.Security.CertificateManagerDialog
200   * @stagemodelonly
201   * @since 14
202   */
203  function openInstallCertificateDialog(context: common.Context, certType: CertificateType, certScope: CertificateScope, cert: Uint8Array): Promise<string>;
204
205}
206
207export default certificateManagerDialog;
208