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 16 #ifndef NAPI_X509_CERTIFICATE_H 17 #define NAPI_X509_CERTIFICATE_H 18 19 #include <string> 20 21 #include "napi/native_api.h" 22 #include "napi/native_common.h" 23 #include "x509_certificate.h" 24 25 namespace OHOS { 26 namespace CryptoFramework { 27 class NapiX509Certificate { 28 public: 29 explicit NapiX509Certificate(HcfX509Certificate *x509Cert); 30 ~NapiX509Certificate(); 31 32 static void DefineX509CertJSClass(napi_env env, napi_value exports); 33 static napi_value NapiCreateX509Cert(napi_env env, napi_callback_info info); 34 static void CreateX509CertExecute(napi_env env, void *data); 35 static void CreateX509CertComplete(napi_env env, napi_status status, void *data); 36 static napi_value CreateX509Cert(napi_env env); 37 38 napi_value Verify(napi_env env, napi_callback_info info); 39 napi_value GetEncoded(napi_env env, napi_callback_info info); 40 napi_value GetPublicKey(napi_env env, napi_callback_info info); 41 napi_value CheckValidityWithDate(napi_env env, napi_callback_info info); 42 napi_value GetVersion(napi_env env, napi_callback_info info); 43 napi_value GetSerialNumber(napi_env env, napi_callback_info info); 44 napi_value GetIssuerName(napi_env env, napi_callback_info info); 45 napi_value GetSubjectName(napi_env env, napi_callback_info info); 46 napi_value GetNotBeforeTime(napi_env env, napi_callback_info info); 47 napi_value GetNotAfterTime(napi_env env, napi_callback_info info); 48 napi_value GetSignature(napi_env env, napi_callback_info info); 49 napi_value GetSigAlgName(napi_env env, napi_callback_info info); 50 napi_value GetSigAlgOID(napi_env env, napi_callback_info info); 51 napi_value GetSigAlgParams(napi_env env, napi_callback_info info); 52 napi_value GetIssuerUniqueID(napi_env env, napi_callback_info info); 53 napi_value GetSubjectUniqueID(napi_env env, napi_callback_info info); 54 napi_value GetKeyUsage(napi_env env, napi_callback_info info); 55 napi_value GetExtendedKeyUsage(napi_env env, napi_callback_info info); 56 napi_value GetBasicConstraints(napi_env env, napi_callback_info info); 57 napi_value GetSubjectAlternativeNames(napi_env env, napi_callback_info info); 58 napi_value GetIssuerAlternativeNames(napi_env env, napi_callback_info info); 59 GetX509Cert()60 HcfX509Certificate *GetX509Cert() 61 { 62 return x509Cert_; 63 } 64 65 static thread_local napi_ref classRef_; 66 67 private: 68 HcfX509Certificate *x509Cert_ = nullptr; 69 }; 70 } // namespace CryptoFramework 71 } // namespace OHOS 72 73 #endif // NAPI_X509_CERTIFICATE_H 74