Mbed TLS v4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
16 
17 #include <stddef.h>
18 
26 #define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080
27 
28 #define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100
29 
30 #define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200
31 
32 #define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280
33 
34 #define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300
35 
36 #define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380
37 
38 #define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400
39 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #if defined(MBEDTLS_PEM_PARSE_C)
46 
49 typedef struct mbedtls_pem_context {
50  unsigned char *MBEDTLS_PRIVATE(buf);
51  size_t MBEDTLS_PRIVATE(buflen);
52  unsigned char *MBEDTLS_PRIVATE(info);
53 }
55 
62 
89 int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const char *footer,
90  const unsigned char *data,
91  const unsigned char *pwd,
92  size_t pwdlen, size_t *use_len);
93 
106 static inline const unsigned char *mbedtls_pem_get_buffer(mbedtls_pem_context *ctx, size_t *buflen)
107 {
108  *buflen = ctx->MBEDTLS_PRIVATE(buflen);
109  return ctx->MBEDTLS_PRIVATE(buf);
110 }
111 
112 
119 #endif /* MBEDTLS_PEM_PARSE_C */
120 
121 #if defined(MBEDTLS_PEM_WRITE_C)
122 
148 int mbedtls_pem_write_buffer(const char *header, const char *footer,
149  const unsigned char *der_data, size_t der_len,
150  unsigned char *buf, size_t buf_len, size_t *olen);
151 #endif /* MBEDTLS_PEM_WRITE_C */
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 #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.
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:106
PEM context structure.
Definition: pem.h:49
void mbedtls_pem_free(mbedtls_pem_context *ctx)
PEM context memory freeing.
Compatibility definitions for MbedTLS 3.x code built with MbedTLS 4.x or TF-PSA-Crypto 1...
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.