- if ( len > *p->sasl_maxbuf - 100 ) {
- len = *p->sasl_maxbuf - 100; /* For safety margin */
- }
-
- {
- unsigned tmpsize = p->buf_out.buf_size;
- ret = sasl_encode( p->sasl_context, buf, len,
- (SASL_CONST char **)&p->buf_out.buf_base,
- &tmpsize );
- p->buf_out.buf_size = tmpsize;
- }
-
- if ( ret != SASL_OK ) {
- ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
- "sb_sasl_write: failed to encode packet: %s\n",
- sasl_errstring( ret, NULL, NULL ) );
- errno = EIO;
- return -1;
- }
- p->buf_out.buf_end = p->buf_out.buf_size;
-
- ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
-
- /* return number of bytes encoded, not written, to ensure
- * no byte is encoded twice (even if only sent once).
- */
- return len;