buffer.h revision 204917
122347Spst/* $OpenBSD: buffer.h,v 1.19 2010/02/09 03:56:28 djm Exp $ */
222347Spst
322347Spst/*
429967Sache * Author: Tatu Ylonen <ylo@cs.hut.fi>
592914Smarkm * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
622347Spst *                    All rights reserved
722347Spst * Code for manipulating FIFO buffers.
822347Spst *
922347Spst * As far as I am concerned, the code I have written for this software
1022347Spst * can be used freely for any purpose.  Any derived versions of this
1122347Spst * software must be clearly marked as such, and if the derived work is
1222347Spst * incompatible with the protocol description in the RFC file, it must be
1322347Spst * called by a name other than "ssh" or "Secure Shell".
1422347Spst */
1522347Spst
1622347Spst#ifndef BUFFER_H
1722347Spst#define BUFFER_H
1892914Smarkm
1992914Smarkmtypedef struct {
2092914Smarkm	u_char	*buf;		/* Buffer for data. */
2159121Skris	u_int	 alloc;		/* Number of bytes allocated for data. */
2259121Skris	u_int	 offset;	/* Offset of first byte containing data. */
2329967Sache	u_int	 end;		/* Offset of last byte containing data. */
2422347Spst}       Buffer;
2522347Spst
2622347Spstvoid	 buffer_init(Buffer *);
2722347Spstvoid	 buffer_clear(Buffer *);
2822347Spstvoid	 buffer_free(Buffer *);
2922347Spst
3022347Spstu_int	 buffer_len(const Buffer *);
3122347Spstvoid	*buffer_ptr(const Buffer *);
3222347Spst
3322347Spstvoid	 buffer_append(Buffer *, const void *, u_int);
3422347Spstvoid	*buffer_append_space(Buffer *, u_int);
3522347Spst
3622347Spstint	 buffer_check_alloc(Buffer *, u_int);
3722347Spst
3822347Spstvoid	 buffer_get(Buffer *, void *, u_int);
3959121Skris
4059121Skrisvoid	 buffer_consume(Buffer *, u_int);
4122347Spstvoid	 buffer_consume_end(Buffer *, u_int);
4222347Spst
4329967Sachevoid     buffer_dump(const Buffer *);
4422347Spst
4522347Spstint	 buffer_get_ret(Buffer *, void *, u_int);
4622347Spstint	 buffer_consume_ret(Buffer *, u_int);
4722347Spstint	 buffer_consume_end_ret(Buffer *, u_int);
4822347Spst
4922347Spst#include <openssl/bn.h>
5022347Spst
5122347Spstvoid    buffer_put_bignum(Buffer *, const BIGNUM *);
5222347Spstvoid    buffer_put_bignum2(Buffer *, const BIGNUM *);
5322347Spstvoid	buffer_get_bignum(Buffer *, BIGNUM *);
5422347Spstvoid	buffer_get_bignum2(Buffer *, BIGNUM *);
5522347Spst
5622347Spstu_short	buffer_get_short(Buffer *);
5722347Spstvoid	buffer_put_short(Buffer *, u_short);
5822347Spst
5992914Smarkmu_int	buffer_get_int(Buffer *);
6022347Spstvoid    buffer_put_int(Buffer *, u_int);
6192914Smarkm
6222347Spstu_int64_t buffer_get_int64(Buffer *);
6322347Spstvoid	buffer_put_int64(Buffer *, u_int64_t);
6422347Spst
6522347Spstint     buffer_get_char(Buffer *);
6622347Spstvoid    buffer_put_char(Buffer *, int);
6722347Spst
6822347Spstvoid   *buffer_get_string(Buffer *, u_int *);
6922347Spstvoid   *buffer_get_string_ptr(Buffer *, u_int *);
7022347Spstvoid    buffer_put_string(Buffer *, const void *, u_int);
7122347Spstvoid	buffer_put_cstring(Buffer *, const char *);
7260572Skris
7360572Skris#define buffer_skip_string(b) \
7460572Skris    do { u_int l = buffer_get_int(b); buffer_consume(b, l); } while (0)
7522347Spst
7660572Skrisint	buffer_put_bignum_ret(Buffer *, const BIGNUM *);
7722347Spstint	buffer_get_bignum_ret(Buffer *, BIGNUM *);
7822347Spstint	buffer_put_bignum2_ret(Buffer *, const BIGNUM *);
7922347Spstint	buffer_get_bignum2_ret(Buffer *, BIGNUM *);
8022347Spstint	buffer_get_short_ret(u_short *, Buffer *);
8122347Spstint	buffer_get_int_ret(u_int *, Buffer *);
8222347Spstint	buffer_get_int64_ret(u_int64_t *, Buffer *);
8322347Spstvoid	*buffer_get_string_ret(Buffer *, u_int *);
8492914Smarkmvoid	*buffer_get_string_ptr_ret(Buffer *, u_int *);
8592914Smarkmint	buffer_get_char_ret(char *, Buffer *);
8692914Smarkm
8792914Smarkm#endif				/* BUFFER_H */
8822347Spst