error.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * \file error.h
  3. *
  4. * \brief Error to string translation
  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_ERROR_H
  28. #define POLARSSL_ERROR_H
  29. /**
  30. * Error code layout.
  31. *
  32. * Currently we try to keep all error codes within the negative space of 16
  33. * bytes signed integers to support all platforms (-0x0000 - -0x8000). In
  34. * addition we'd like to give two layers of information on the error if
  35. * possible.
  36. *
  37. * For that purpose the error codes are segmented in the following manner:
  38. *
  39. * 16 bit error code bit-segmentation
  40. *
  41. * 1 bit - Intentionally not used
  42. * 3 bits - High level module ID
  43. * 5 bits - Module-dependent error code
  44. * 6 bits - Low level module errors
  45. * 1 bit - Intentionally not used
  46. *
  47. * Low-level module errors (0x007E-0x0002)
  48. *
  49. * Module Nr Codes assigned
  50. * MPI 7 0x0002-0x000E
  51. * BASE64 2 0x0010-0x0012
  52. * ASN1 5 0x0014-0x001C
  53. * AES 2 0x0020-0x0022
  54. * CAMELLIA 2 0x0024-0x0026
  55. * XTEA 1 0x0028-0x0028
  56. * PADLOCK 1 0x0030-0x0030
  57. * DES 1 0x0032-0x0032
  58. * NET 11 0x0040-0x0054
  59. *
  60. * High-level module nr (3 bits - 0x1...-0x8...)
  61. * Name ID Nr of Errors
  62. * PEM 1 8
  63. * X509 2 20
  64. * DHM 3 6
  65. * RSA 4 9
  66. * MD 5 1
  67. * CIPER 6 1
  68. * SSL 7 27
  69. *
  70. * Module dependent error code (5 bits 0x.08.-0x.F8.)
  71. */
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75. /**
  76. * \brief Translate a PolarSSL error code into a string representation,
  77. * Result is truncated if necessary and always includes a terminating
  78. * null byte.
  79. *
  80. * \param errnum error code
  81. * \param buffer buffer to place representation in
  82. * \param buflen length of the buffer
  83. */
  84. void error_strerror( int errnum, char *buffer, size_t buflen );
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* error.h */