blob: dfb2f1ed20350802892400ec126818c893db060c [file] [log] [blame]
Paul Bakker96743fc2011-02-12 14:30:57 +00001/**
2 * \file pem.h
3 *
4 * \brief Privacy Enhanced Mail (PEM) decoding
5 *
6 * Copyright (C) 2006-2010, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
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.
17 *
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.
22 *
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.
26 */
27#ifndef POLARSSL_PEM_H
28#define POLARSSL_PEM_H
29
30/**
31 * \name PEM Error codes
32 * These error codes are returned in case of errors reading the
33 * PEM data.
34 * \{
35 */
36#define POLARSSL_ERR_PEM_NO_HEADER_PRESENT -0x0500 /**< No PEM header found. */
37#define POLARSSL_ERR_PEM_INVALID_DATA -0x0520 /**< PEM string is not as expected. */
38#define POLARSSL_ERR_PEM_MALLOC_FAILED -0x0540 /**< Failed to allocate memory. */
39#define POLARSSL_ERR_PEM_INVALID_ENC_IV -0x0560 /**< RSA IV is not in hex-format. */
40#define POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG -0x0580 /**< Unsupported key encryption algorithm. */
41#define POLARSSL_ERR_PEM_PASSWORD_REQUIRED -0x05A0 /**< Private key password can't be empty. */
42#define POLARSSL_ERR_PEM_PASSWORD_MISMATCH -0x05C0 /**< Given private key password does not allow for correct decryption. */
43#define POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE -0x05E0 /**< Unavailable feature, e.g. hashing/encryption combination. */
44/* \} name */
45
46/**
47 * \brief PEM context structure
48 */
49typedef struct
50{
51 unsigned char *buf; /*!< buffer for decoded data */
52 int buflen; /*!< length of the buffer */
53 unsigned char *info; /*!< buffer for extra header information */
54}
55pem_context;
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61/**
62 * \brief PEM context setup
63 *
64 * \param ctx context to be initialized
65 */
66void pem_init( pem_context *ctx );
67
68/**
69 * \brief Read a buffer for PEM information and store the resulting
70 * data into the specified context buffers.
71 *
72 * \param ctx context to use
73 * \param header header string to seek and expect
74 * \param footer footer string to seek and expect
75 * \param data source data to look in
76 * \param pwd password for decryption (can be NULL)
77 * \param pwdlen length of password
78 * \param use_len destination for total length used
79 *
80 * \return 0 on success, ior a specific PEM error code
81 */
82int pem_read_buffer( pem_context *ctx, char *header, char *footer,
83 const unsigned char *data,
84 const unsigned char *pwd,
85 int pwdlen, int *use_len );
86
87/**
88 * \brief PEM context memory freeing
89 *
90 * \param ctx context to be freed
91 */
92void pem_free( pem_context *ctx );
93
94#ifdef __cplusplus
95}
96#endif
97
98#endif /* pem.h */