saslutil.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* saslutil.h -- various utility functions in SASL library
  2. */
  3. #ifndef SASLUTIL_H
  4. #define SASLUTIL_H 1
  5. #ifndef SASL_H
  6. #include "sasl.h"
  7. #endif
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /* base64 decode
  12. * in -- input data
  13. * inlen -- length of input data
  14. * out -- output data (may be same as in, must have enough space)
  15. * outmax -- max size of output buffer
  16. * result:
  17. * outlen -- actual output length
  18. *
  19. * returns SASL_BADPROT on bad base64,
  20. * SASL_BUFOVER if result won't fit
  21. * SASL_OK on success
  22. */
  23. LIBSASL_API int sasl_decode64(const char *in, unsigned inlen,
  24. char *out, unsigned outmax, unsigned *outlen);
  25. /* base64 encode
  26. * in -- input data
  27. * inlen -- input data length
  28. * out -- output buffer (will be NUL terminated)
  29. * outmax -- max size of output buffer
  30. * result:
  31. * outlen -- gets actual length of output buffer (optional)
  32. *
  33. * Returns SASL_OK on success, SASL_BUFOVER if result won't fit
  34. */
  35. LIBSASL_API int sasl_encode64(const char *in, unsigned inlen,
  36. char *out, unsigned outmax, unsigned *outlen);
  37. /* make a challenge string (NUL terminated)
  38. * buf -- buffer for result
  39. * maxlen -- max length of result
  40. * hostflag -- 0 = don't include hostname, 1 = include hostname
  41. * returns final length or 0 if not enough space
  42. */
  43. LIBSASL_API int sasl_mkchal(sasl_conn_t *conn, char *buf,
  44. unsigned maxlen, unsigned hostflag);
  45. /* verify a string is valid UTF-8
  46. * if len == 0, strlen(str) will be used.
  47. * returns SASL_BADPROT on error, SASL_OK on success
  48. */
  49. LIBSASL_API int sasl_utf8verify(const char *str, unsigned len);
  50. /* create random pool seeded with OS-based params */
  51. LIBSASL_API int sasl_randcreate(sasl_rand_t **rpool);
  52. /* free random pool from randcreate */
  53. LIBSASL_API void sasl_randfree(sasl_rand_t **rpool);
  54. /* seed random number generator */
  55. LIBSASL_API void sasl_randseed(sasl_rand_t *rpool, const char *seed,
  56. unsigned len);
  57. /* generate random octets */
  58. LIBSASL_API void sasl_rand(sasl_rand_t *rpool, char *buf, unsigned len);
  59. /* churn data into random number generator */
  60. LIBSASL_API void sasl_churn(sasl_rand_t *rpool, const char *data,
  61. unsigned len);
  62. /* erase a security sensitive buffer or password.
  63. * Implementation may use recovery-resistant erase logic.
  64. */
  65. LIBSASL_API void sasl_erasebuffer(char *pass, unsigned len);
  66. /* Lowercase string in place */
  67. LIBSASL_API char *sasl_strlower (char *val);
  68. LIBSASL_API int sasl_config_init(const char *filename);
  69. LIBSASL_API void sasl_config_done(void);
  70. #ifdef WIN32
  71. /* Just in case a different DLL defines this as well */
  72. #if defined(NEED_GETOPT)
  73. LIBSASL_API int getopt(int argc, char **argv, char *optstring);
  74. #endif
  75. LIBSASL_API char * getpass(const char *prompt);
  76. #endif /* WIN32 */
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* SASLUTIL_H */