pem.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  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. #include <string.h>
  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 -0x1080 /**< No PEM header found. */
  37. #define POLARSSL_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */
  38. #define POLARSSL_ERR_PEM_MALLOC_FAILED -0x1180 /**< Failed to allocate memory. */
  39. #define POLARSSL_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */
  40. #define POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */
  41. #define POLARSSL_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */
  42. #define POLARSSL_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */
  43. #define POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */
  44. /* \} name */
  45. /**
  46. * \brief PEM context structure
  47. */
  48. typedef struct
  49. {
  50. unsigned char *buf; /*!< buffer for decoded data */
  51. size_t buflen; /*!< length of the buffer */
  52. unsigned char *info; /*!< buffer for extra header information */
  53. }
  54. pem_context;
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58. /**
  59. * \brief PEM context setup
  60. *
  61. * \param ctx context to be initialized
  62. */
  63. void pem_init( pem_context *ctx );
  64. /**
  65. * \brief Read a buffer for PEM information and store the resulting
  66. * data into the specified context buffers.
  67. *
  68. * \param ctx context to use
  69. * \param header header string to seek and expect
  70. * \param footer footer string to seek and expect
  71. * \param data source data to look in
  72. * \param pwd password for decryption (can be NULL)
  73. * \param pwdlen length of password
  74. * \param use_len destination for total length used
  75. *
  76. * \return 0 on success, ior a specific PEM error code
  77. */
  78. int pem_read_buffer( pem_context *ctx, char *header, char *footer,
  79. const unsigned char *data,
  80. const unsigned char *pwd,
  81. size_t pwdlen, size_t *use_len );
  82. /**
  83. * \brief PEM context memory freeing
  84. *
  85. * \param ctx context to be freed
  86. */
  87. void pem_free( pem_context *ctx );
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* pem.h */