/contrib/bind9/lib/isc/include/isc/base32.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 128 lines · 25 code · 13 blank · 90 comment · 0 complexity · 7f8cabab573f89bdbb4cdeb2c0113af1 MD5 · raw file

  1. /*
  2. * Copyright (C) 2008 Internet Systems Consortium, Inc. ("ISC")
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. * PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* $Id: base32.h,v 1.3 2008/09/25 04:02:39 tbox Exp $ */
  17. #ifndef ISC_BASE32_H
  18. #define ISC_BASE32_H 1
  19. /*! \file */
  20. /*
  21. * Routines for manipulating base 32 and base 32 hex encoded data.
  22. * Based on RFC 4648.
  23. *
  24. * Base 32 hex preserves the sort order of data when it is encoded /
  25. * decoded.
  26. */
  27. #include <isc/lang.h>
  28. #include <isc/types.h>
  29. ISC_LANG_BEGINDECLS
  30. /***
  31. *** Functions
  32. ***/
  33. isc_result_t
  34. isc_base32_totext(isc_region_t *source, int wordlength,
  35. const char *wordbreak, isc_buffer_t *target);
  36. isc_result_t
  37. isc_base32hex_totext(isc_region_t *source, int wordlength,
  38. const char *wordbreak, isc_buffer_t *target);
  39. /*!<
  40. * \brief Convert data into base32 encoded text.
  41. *
  42. * Notes:
  43. *\li The base32 encoded text in 'target' will be divided into
  44. * words of at most 'wordlength' characters, separated by
  45. * the 'wordbreak' string. No parentheses will surround
  46. * the text.
  47. *
  48. * Requires:
  49. *\li 'source' is a region containing binary data
  50. *\li 'target' is a text buffer containing available space
  51. *\li 'wordbreak' points to a null-terminated string of
  52. * zero or more whitespace characters
  53. *
  54. * Ensures:
  55. *\li target will contain the base32 encoded version of the data
  56. * in source. The 'used' pointer in target will be advanced as
  57. * necessary.
  58. */
  59. isc_result_t
  60. isc_base32_decodestring(const char *cstr, isc_buffer_t *target);
  61. isc_result_t
  62. isc_base32hex_decodestring(const char *cstr, isc_buffer_t *target);
  63. /*!<
  64. * \brief Decode a null-terminated base32 string.
  65. *
  66. * Requires:
  67. *\li 'cstr' is non-null.
  68. *\li 'target' is a valid buffer.
  69. *
  70. * Returns:
  71. *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring'
  72. * fit in 'target'.
  73. *\li #ISC_R_BADBASE32 -- 'cstr' is not a valid base32 encoding.
  74. *
  75. * Other error returns are any possible error code from:
  76. *\li isc_lex_create(),
  77. *\li isc_lex_openbuffer(),
  78. *\li isc_base32_tobuffer().
  79. */
  80. isc_result_t
  81. isc_base32_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
  82. isc_result_t
  83. isc_base32hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
  84. /*!<
  85. * \brief Convert base32 encoded text from a lexer context into data.
  86. *
  87. * Requires:
  88. *\li 'lex' is a valid lexer context
  89. *\li 'target' is a buffer containing binary data
  90. *\li 'length' is an integer
  91. *
  92. * Ensures:
  93. *\li target will contain the data represented by the base32 encoded
  94. * string parsed by the lexer. No more than length bytes will be read,
  95. * if length is positive. The 'used' pointer in target will be
  96. * advanced as necessary.
  97. */
  98. isc_result_t
  99. isc_base32_decoderegion(isc_region_t *source, isc_buffer_t *target);
  100. isc_result_t
  101. isc_base32hex_decoderegion(isc_region_t *source, isc_buffer_t *target);
  102. /*!<
  103. * \brief Decode a packed (no white space permitted) base32 region.
  104. *
  105. * Requires:
  106. *\li 'source' is a valid region.
  107. *\li 'target' is a valid buffer.
  108. *
  109. * Returns:
  110. *\li #ISC_R_SUCCESS -- the entire decoded representation of 'cstring'
  111. * fit in 'target'.
  112. *\li #ISC_R_BADBASE32 -- 'source' is not a valid base32 encoding.
  113. */
  114. ISC_LANG_ENDDECLS
  115. #endif /* ISC_BASE32_H */