initial commit; it works
[psslcertgen.git] / src / libpolarssl / pem.h
blobe95dc10a0be0339012dbc852a8a422624b513a12
1 /**
2 * \file pem.h
4 * \brief Privacy Enhanced Mail (PEM) decoding
6 * Copyright (C) 2006-2013, Brainspark B.V.
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11 * All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #ifndef POLARSSL_PEM_H
28 #define POLARSSL_PEM_H
30 #include <string.h>
32 /**
33 * \name PEM Error codes
34 * These error codes are returned in case of errors reading the
35 * PEM data.
36 * \{
38 #define POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 /**< No PEM header or footer found. */
39 #define POLARSSL_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */
40 #define POLARSSL_ERR_PEM_MALLOC_FAILED -0x1180 /**< Failed to allocate memory. */
41 #define POLARSSL_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */
42 #define POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */
43 #define POLARSSL_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */
44 #define POLARSSL_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */
45 #define POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */
46 #define POLARSSL_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */
47 /* \} name */
49 /**
50 * \brief PEM context structure
52 typedef struct
54 unsigned char *buf; /*!< buffer for decoded data */
55 size_t buflen; /*!< length of the buffer */
56 unsigned char *info; /*!< buffer for extra header information */
58 pem_context;
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
64 /**
65 * \brief PEM context setup
67 * \param ctx context to be initialized
69 void pem_init( pem_context *ctx );
71 /**
72 * \brief Read a buffer for PEM information and store the resulting
73 * data into the specified context buffers.
75 * \param ctx context to use
76 * \param header header string to seek and expect
77 * \param footer footer string to seek and expect
78 * \param data source data to look in
79 * \param pwd password for decryption (can be NULL)
80 * \param pwdlen length of password
81 * \param use_len destination for total length used (set after header is
82 * correctly read, so unless you get
83 * POLARSSL_ERR_PEM_BAD_INPUT_DATA or
84 * POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is
85 * the length to skip)
87 * \return 0 on success, ior a specific PEM error code
89 int pem_read_buffer( pem_context *ctx, char *header, char *footer,
90 const unsigned char *data,
91 const unsigned char *pwd,
92 size_t pwdlen, size_t *use_len );
94 /**
95 * \brief PEM context memory freeing
97 * \param ctx context to be freed
99 void pem_free( pem_context *ctx );
101 #ifdef __cplusplus
103 #endif
105 #endif /* pem.h */