1 /* 2 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * saslutil.h -- various utility functions in SASL library 8 */ 9 10 #ifndef _SASL_SASLUTIL_H 11 #define _SASL_SASLUTIL_H 12 13 #ifndef _SASL_SASL_H 14 #include <sasl/sasl.h> 15 #endif 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /* 22 * base64 decode 23 * in -- input data 24 * inlen -- length of input data 25 * out -- output data (may be same as in, must have enough space) 26 * outmax -- max size of output buffer 27 * result: 28 * outlen -- actual output length 29 * 30 * returns SASL_BADPROT on bad base64, 31 * SASL_BUFOVER if result won't fit 32 * SASL_OK on success 33 */ 34 LIBSASL_API int sasl_decode64(const char *in, unsigned inlen, 35 char *out, unsigned outmax, unsigned *outlen); 36 37 /* 38 * base64 encode 39 * in -- input data 40 * inlen -- input data length 41 * out -- output buffer (will be NUL terminated) 42 * outmax -- max size of output buffer 43 * result: 44 * outlen -- gets actual length of output buffer (optional) 45 * 46 * Returns SASL_OK on success, SASL_BUFOVER if result won't fit 47 */ 48 LIBSASL_API int sasl_encode64(const char *in, unsigned inlen, 49 char *out, unsigned outmax, unsigned *outlen); 50 51 #if 0 52 /* 53 * The following is not supported: 54 * 55 * make a challenge string (NUL terminated) 56 * buf -- buffer for result 57 * maxlen -- max length of result 58 * hostflag -- 0 = don't include hostname, 1 = include hostname 59 * returns final length or 0 if not enough space 60 */ 61 LIBSASL_API int sasl_mkchal(sasl_conn_t *conn, char *buf, 62 unsigned maxlen, unsigned hostflag); 63 #endif 64 65 /* 66 * verify a string is valid UTF-8 67 * if len == 0, strlen(str) will be used. 68 * returns SASL_BADPROT on error, SASL_OK on success 69 */ 70 LIBSASL_API int sasl_utf8verify(const char *str, unsigned len); 71 72 #if 0 73 /* The following are not supported */ 74 75 /* create random pool seeded with OS-based params */ 76 LIBSASL_API int sasl_randcreate(sasl_rand_t **rpool); 77 78 /* free random pool from randcreate */ 79 LIBSASL_API void sasl_randfree(sasl_rand_t **rpool); 80 81 /* seed random number generator */ 82 LIBSASL_API void sasl_randseed(sasl_rand_t *rpool, const char *seed, 83 unsigned len); 84 85 /* generate random octets */ 86 LIBSASL_API void sasl_rand(sasl_rand_t *rpool, char *buf, unsigned len); 87 88 /* churn data into random number generator */ 89 LIBSASL_API void sasl_churn(sasl_rand_t *rpool, const char *data, 90 unsigned len); 91 #endif 92 93 /* 94 * erase a security sensitive buffer or password. 95 * Implementation may use recovery-resistant erase logic. 96 */ 97 LIBSASL_API void sasl_erasebuffer(char *pass, unsigned len); 98 99 #ifdef __cplusplus 100 } 101 #endif 102 103 #endif /* _SASL_SASLUTIL_H */ 104