• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 #ifndef BSL_PEM_INTERNAL_H
16 #define BSL_PEM_INTERNAL_H
17 
18 #include "hitls_build.h"
19 #ifdef HITLS_BSL_PEM
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define BSL_PEM_CERT_BEGIN_STR "-----BEGIN CERTIFICATE-----"
27 #define BSL_PEM_CERT_END_STR "-----END CERTIFICATE-----"
28 
29 #define BSL_PEM_CRL_BEGIN_STR "-----BEGIN X509 CRL-----"
30 #define BSL_PEM_CRL_END_STR "-----END X509 CRL-----"
31 
32 #define BSL_PEM_PUB_KEY_BEGIN_STR "-----BEGIN PUBLIC KEY-----"
33 #define BSL_PEM_PUB_KEY_END_STR "-----END PUBLIC KEY-----"
34 
35 #define BSL_PEM_RSA_PUB_KEY_BEGIN_STR "-----BEGIN RSA PUBLIC KEY-----"
36 #define BSL_PEM_RSA_PUB_KEY_END_STR "-----END RSA PUBLIC KEY-----"
37 
38 #define BSL_PEM_RSA_PRI_KEY_BEGIN_STR "-----BEGIN RSA PRIVATE KEY-----"
39 #define BSL_PEM_RSA_PRI_KEY_END_STR "-----END RSA PRIVATE KEY-----"
40 
41 /** rfc5915 section 4 */
42 #define BSL_PEM_EC_PRI_KEY_BEGIN_STR "-----BEGIN EC PRIVATE KEY-----"
43 #define BSL_PEM_EC_PRI_KEY_END_STR "-----END EC PRIVATE KEY-----"
44 
45 /** rfc5958 section 5 */
46 #define BSL_PEM_PRI_KEY_BEGIN_STR "-----BEGIN PRIVATE KEY-----"
47 #define BSL_PEM_PRI_KEY_END_STR "-----END PRIVATE KEY-----"
48 
49 /** rfc5958 section 5 */
50 #define BSL_PEM_P8_PRI_KEY_BEGIN_STR "-----BEGIN ENCRYPTED PRIVATE KEY-----"
51 #define BSL_PEM_P8_PRI_KEY_END_STR "-----END ENCRYPTED PRIVATE KEY-----"
52 
53 #define BSL_PEM_CERT_REQ_BEGIN_STR "-----BEGIN CERTIFICATE REQUEST-----"
54 #define BSL_PEM_CERT_REQ_END_STR "-----END CERTIFICATE REQUEST-----"
55 
56 typedef struct {
57     const char *head;
58     const char *tail;
59 } BSL_PEM_Symbol;
60 
61 int32_t BSL_PEM_EncodeAsn1ToPem(uint8_t *asn1Encode, uint32_t asn1Len, BSL_PEM_Symbol *symbol,
62     char **encode, uint32_t *encodeLen);
63 
64 /* encode must end in '\0' */
65 int32_t BSL_PEM_DecodePemToAsn1(char **encode, uint32_t *encodeLen, BSL_PEM_Symbol *symbol, uint8_t **asn1Encode,
66     uint32_t *asn1Len);
67 
68 /* encode must end in '\0' */
69 bool BSL_PEM_IsPemFormat(char *encode, uint32_t encodeLen);
70 
71 int32_t BSL_PEM_GetSymbolAndType(char *encode, uint32_t encodeLen, BSL_PEM_Symbol *symbol, char **type);
72 
73 #ifdef __cplusplus
74 }
75 #endif /* __cplusplus */
76 #endif /* HITLS_BSL_PEM */
77 #endif /* BSL_PEM_INTERNAL_H */