• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 CF_CERTIFICATE_OPENSSL_COMMON_H
17 #define CF_CERTIFICATE_OPENSSL_COMMON_H
18 
19 #include <stdint.h>
20 
21 #include "cf_blob.h"
22 #include "cf_result.h"
23 
24 #include <openssl/x509.h>
25 
26 #define CF_OPENSSL_SUCCESS 1 /* openssl return 1: success */
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef enum {
33     NAME_TYPE_SUBECT,
34     NAME_TYPE_ISSUER,
35 } X509NameType;
36 
37 const char *GetAlgorithmName(const char *oid);
38 void CfPrintOpensslError(void);
39 CfResult DeepCopyDataToBlob(const unsigned char *data, uint32_t len, CfBlob *outBlob);
40 CfResult DeepCopyBlobToBlob(const CfBlob *inBlob, CfBlob **outBlob);
41 CfResult CopyExtensionsToBlob(const X509_EXTENSIONS *ext, CfBlob *outBlob);
42 CfResult CompareDateWithCertTime(const X509 *x509, const ASN1_TIME *inputDate);
43 CfResult ConvertNameDerDataToString(const unsigned char *data, uint32_t derLen, CfBlob *out);
44 CfResult CompareNameObject(const X509 *cert, const CfBlob *derBlob, X509NameType type, bool *compareRes);
45 CfResult CompareBigNum(const CfBlob *lhs, const CfBlob *rhs, int *out);
46 uint8_t *GetX509EncodedDataStream(const X509 *certificate, int *dataLength);
47 #ifdef __cplusplus
48 }
49 #endif
50 
51 #endif
52