Mbed TLS v3.6.3
pem.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright The Mbed TLS Contributors
8  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  */
10 #ifndef MBEDTLS_PEM_H
11 #define MBEDTLS_PEM_H
12 #include "mbedtls/private_access.h"
13 
14 #include "mbedtls/build_info.h"
15 
16 #include <stddef.h>
17 
25 #define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080
26 
27 #define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100
28 
29 #define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180
30 
31 #define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200
32 
33 #define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280
34 
35 #define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300
36 
37 #define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380
38 
39 #define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400
40 
41 #define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480
42 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #if defined(MBEDTLS_PEM_PARSE_C)
49 
52 typedef struct mbedtls_pem_context {
53  unsigned char *MBEDTLS_PRIVATE(buf);
54  size_t MBEDTLS_PRIVATE(buflen);
55  unsigned char *MBEDTLS_PRIVATE(info);
56 }
58 
65 
92 int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const char *footer,
93  const unsigned char *data,
94  const unsigned char *pwd,
95  size_t pwdlen, size_t *use_len);
96 
109 static inline const unsigned char *mbedtls_pem_get_buffer(mbedtls_pem_context *ctx, size_t *buflen)
110 {
111  *buflen = ctx->MBEDTLS_PRIVATE(buflen);
112  return ctx->MBEDTLS_PRIVATE(buf);
113 }
114 
115 
122 #endif /* MBEDTLS_PEM_PARSE_C */
123 
124 #if defined(MBEDTLS_PEM_WRITE_C)
125 
151 int mbedtls_pem_write_buffer(const char *header, const char *footer,
152  const unsigned char *der_data, size_t der_len,
153  unsigned char *buf, size_t buf_len, size_t *olen);
154 #endif /* MBEDTLS_PEM_WRITE_C */
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* pem.h */
int mbedtls_pem_write_buffer(const char *header, const char *footer, const unsigned char *der_data, size_t der_len, unsigned char *buf, size_t buf_len, size_t *olen)
Write a buffer of PEM information from a DER encoded buffer.
#define MBEDTLS_PRIVATE(member)
struct mbedtls_pem_context mbedtls_pem_context
PEM context structure.
static const unsigned char * mbedtls_pem_get_buffer(mbedtls_pem_context *ctx, size_t *buflen)
Get the pointer to the decoded binary data in a PEM context.
Definition: pem.h:109
PEM context structure.
Definition: pem.h:52
void mbedtls_pem_free(mbedtls_pem_context *ctx)
PEM context memory freeing.
Macro wrapper for struct's members.
Build-time configuration info.
int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const char *footer, const unsigned char *data, const unsigned char *pwd, size_t pwdlen, size_t *use_len)
Read a buffer for PEM information and store the resulting data into the specified context buffers...
void mbedtls_pem_init(mbedtls_pem_context *ctx)
PEM context setup.