/*
 * Secure eXtended Message Passing framework
 * Secure eXtended Transport layer implementation: (libsxt)
 * - very similar to SSH2/TLS
 * - using already proven and tested crypto algos
 * - better than TLS for message passing
 *
 * (c) Alexander Vdolainen 2016 <avdolainen@zoho.com>
 *
 * libsxmp is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * libsxmp is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.";
 *
 */

#ifndef __SXT_SXTSAFEBUF_H__
#define __SXT_SXTSAFEBUF_H__

/* size and data, no padding */
typedef struct sxtsafebuffer_type {
  uint32_t size;
  unsigned char data[1];
} __attribute__((packed)) sxtsafebuffer_t;

/* functions to operate with this,
 * please note, since it used within network
 * context, few things must be applied.
 */
sxtsafebuffer_t *sxtsafebuffer_new(size_t);

int sxtsafebuffer_setdata(sxtsafebuffer_t *, const void *, size_t);

size_t sxtsafebuffer_length(sxtsafebuffer_t *);

void sxtsafebuffer_destroy(sxtsafebuffer_t *);

void *sxtsafebuffer_getdata(sxtsafebuffer_t *);

/* C string ops */
const char *sxtsafebuffer_tocstr(sxtsafebuffer_t *);

sxtsafebuffer_t *sxtsafebuffer_new_fromcstr(const char *);

/* returning value should be freed after use */
char *sxtsafebuffer_getcstr(sxtsafebuffer_t *);

void sxtsafebuffer_freecstr(char *);

#endif