nettle  3.7.3
About: Nettle is a low-level cryptographic library.
  Fossies Dox: nettle-3.7.3.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

buffer.h
Go to the documentation of this file.
1 /* buffer.h
2 
3  A bare-bones string stream.
4 
5  Copyright (C) 2002 Niels Möller
6 
7  This file is part of GNU Nettle.
8 
9  GNU Nettle is free software: you can redistribute it and/or
10  modify it under the terms of either:
11 
12  * the GNU Lesser General Public License as published by the Free
13  Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  or
17 
18  * the GNU General Public License as published by the Free
19  Software Foundation; either version 2 of the License, or (at your
20  option) any later version.
21 
22  or both in parallel, as here.
23 
24  GNU Nettle is distributed in the hope that it will be useful,
25  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27  General Public License for more details.
28 
29  You should have received copies of the GNU General Public License and
30  the GNU Lesser General Public License along with this program. If
31  not, see http://www.gnu.org/licenses/.
32 */
33 
34 #ifndef NETTLE_BUFFER_H_INCLUDED
35 #define NETTLE_BUFFER_H_INCLUDED
36 
37 #include "realloc.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
44 {
45  uint8_t *contents;
46  /* Allocated size */
47  size_t alloc;
48 
49  void *realloc_ctx;
51 
52  /* Current size */
53  size_t size;
54 };
55 
56 /* Initializes a buffer that uses plain realloc */
57 void
58 nettle_buffer_init(struct nettle_buffer *buffer);
59 
60 void
62  void *realloc_ctx,
63  nettle_realloc_func *realloc);
64 
65 /* Initializes a buffer of fix size */
66 void
68  size_t length, uint8_t *space);
69 
70 void
71 nettle_buffer_clear(struct nettle_buffer *buffer);
72 
73 /* Resets the buffer, without freeing the buffer space. */
74 void
75 nettle_buffer_reset(struct nettle_buffer *buffer);
76 
77 int
78 nettle_buffer_grow(struct nettle_buffer *buffer,
79  size_t length);
80 
81 #define NETTLE_BUFFER_PUTC(buffer, c) \
82 ( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
83  && ((buffer)->contents[(buffer)->size++] = (c), 1) )
84 
85 int
86 nettle_buffer_write(struct nettle_buffer *buffer,
87  size_t length, const uint8_t *data);
88 
89 /* Like nettle_buffer_write, but instead of copying data to the
90  * buffer, it returns a pointer to the area where the caller can copy
91  * the data. The pointer is valid only until the next call that can
92  * reallocate the buffer. */
93 uint8_t *
94 nettle_buffer_space(struct nettle_buffer *buffer,
95  size_t length);
96 
97 /* Copy the contents of SRC to the end of DST. */
98 int
100  const struct nettle_buffer *src);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif /* NETTLE_BUFFER_H_INCLUDED */
void nettle_buffer_clear(struct nettle_buffer *buffer)
Definition: buffer.c:93
void nettle_buffer_reset(struct nettle_buffer *buffer)
Definition: buffer.c:104
int nettle_buffer_write(struct nettle_buffer *buffer, size_t length, const uint8_t *data)
Definition: buffer.c:124
void nettle_buffer_init_realloc(struct nettle_buffer *buffer, void *realloc_ctx, nettle_realloc_func *realloc)
Definition: buffer.c:70
int nettle_buffer_grow(struct nettle_buffer *buffer, size_t length)
Definition: buffer.c:45
void nettle_buffer_init(struct nettle_buffer *buffer)
Definition: buffer-init.c:45
int nettle_buffer_copy(struct nettle_buffer *dst, const struct nettle_buffer *src)
Definition: buffer.c:138
void nettle_buffer_init_size(struct nettle_buffer *buffer, size_t length, uint8_t *space)
Definition: buffer.c:82
uint8_t * nettle_buffer_space(struct nettle_buffer *buffer, size_t length)
Definition: buffer.c:110
void * nettle_realloc_func(void *ctx, void *p, size_t length)
Definition: nettle-types.h:82
nettle_realloc_func * realloc
Definition: buffer.h:50
void * realloc_ctx
Definition: buffer.h:49
uint8_t * contents
Definition: buffer.h:45
size_t size
Definition: buffer.h:53
size_t alloc
Definition: buffer.h:47