pem.h
mbedtls/config.h
stddef.h
mbedtls/check_config.h
mbedtls/config.h
pem.h
limits.h
stddef.h
mbedtls_pem_context
PEM Error codes

These error codes are returned in case of errors reading the PEM data.

MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT
-0x1080

No PEM header or footer found.

MBEDTLS_ERR_PEM_INVALID_DATA
-0x1100

PEM string is not as expected.

MBEDTLS_ERR_PEM_ALLOC_FAILED
-0x1180

Failed to allocate memory.

MBEDTLS_ERR_PEM_INVALID_ENC_IV
-0x1200

RSA IV is not in hex-format.

MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG
-0x1280

Unsupported key encryption algorithm.

MBEDTLS_ERR_PEM_PASSWORD_REQUIRED
-0x1300

Private key password can't be empty.

MBEDTLS_ERR_PEM_PASSWORD_MISMATCH
-0x1380

Given private key password does not allow for correct decryption.

MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE
-0x1400

Unavailable feature, e.g. hashing/encryption combination.

MBEDTLS_ERR_PEM_BAD_INPUT_DATA
-0x1480

Bad input parameters to function.

struct mbedtls_pem_context typedef struct mbedtls_pem_context mbedtls_pem_context mbedtls_pem_context

PEM context structure.

void void mbedtls_pem_init (mbedtls_pem_context *ctx) mbedtls_pem_init mbedtls_pem_context * ctx

PEM context setup.

ctx

context to be initialized

int 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) 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.

ctx

context to use

header

header string to seek and expect

footer

footer string to seek and expect

data

source data to look in (must be nul-terminated)

pwd

password for decryption (can be NULL)

pwdlen

length of password

use_len

destination for total length used (set after header is correctly read, so unless you get MBEDTLS_ERR_PEM_BAD_INPUT_DATA or MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is the length to skip)

Attempts to check password correctness by verifying if the decrypted text starts with an ASN.1 sequence of appropriate length

0 on success, or a specific PEM error code

void void mbedtls_pem_free (mbedtls_pem_context *ctx) mbedtls_pem_free mbedtls_pem_context * ctx

PEM context memory freeing.

ctx

context to be freed

int 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) 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.

header

The header string to write.

footer

The footer string to write.

der_data

The DER data to encode.

der_len

The length of the DER data `der_data` in Bytes.

buf

The buffer to write to.

buf_len

The length of the output buffer `buf` in Bytes.

olen

The address at which to store the total length written or required (if `buf_len` is not enough).

You may pass `NULL` for `buf` and `0` for `buf_len` to request the length of the resulting PEM buffer in `*olen`.

This function may be called with overlapping `der_data` and `buf` buffers.

`0` on success.

MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL if `buf` isn't large enough to hold the PEM buffer. In this case, `*olen` holds the required minimum size of `buf`.

Another PEM or BASE64 error code on other kinds of failure.

Privacy Enhanced Mail (PEM) decoding.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */
    #ifndefMBEDTLS_PEM_H
    #defineMBEDTLS_PEM_H

    #if!defined(MBEDTLS_CONFIG_FILE)
    #include"mbedtls/config.h"
    #else
    #includeMBEDTLS_CONFIG_FILE
    #endif

    #include<stddef.h>

    #defineMBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT-0x1080
    #defineMBEDTLS_ERR_PEM_INVALID_DATA-0x1100
    #defineMBEDTLS_ERR_PEM_ALLOC_FAILED-0x1180
    #defineMBEDTLS_ERR_PEM_INVALID_ENC_IV-0x1200
    #defineMBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG-0x1280
    #defineMBEDTLS_ERR_PEM_PASSWORD_REQUIRED-0x1300
    #defineMBEDTLS_ERR_PEM_PASSWORD_MISMATCH-0x1380
    #defineMBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE-0x1400
    #defineMBEDTLS_ERR_PEM_BAD_INPUT_DATA-0x1480
    #ifdef__cplusplus
    extern"C"{
    #endif

    #ifdefined(MBEDTLS_PEM_PARSE_C)
    typedefstructmbedtls_pem_context{
    unsignedchar*buf;
    size_tbuflen;
    unsignedchar*info;
    }
    mbedtls_pem_context;

    voidmbedtls_pem_init(mbedtls_pem_context*ctx);

    intmbedtls_pem_read_buffer(mbedtls_pem_context*ctx,constchar*header,constchar*footer,
    constunsignedchar*data,
    constunsignedchar*pwd,
    size_tpwdlen,size_t*use_len);

    voidmbedtls_pem_free(mbedtls_pem_context*ctx);
    #endif/*MBEDTLS_PEM_PARSE_C*/

    #ifdefined(MBEDTLS_PEM_WRITE_C)
    intmbedtls_pem_write_buffer(constchar*header,constchar*footer,
    constunsignedchar*der_data,size_tder_len,
    unsignedchar*buf,size_tbuf_len,size_t*olen);
    #endif/*MBEDTLS_PEM_WRITE_C*/

    #ifdef__cplusplus
    }
    #endif

    #endif/*pem.h*/