Lines Matching refs:buf

34 static int tls_buffer_resize(struct tls_buffer *buf, size_t capacity);
39 struct tls_buffer *buf = NULL; in tls_buffer_new() local
41 if ((buf = calloc(1, sizeof(struct tls_buffer))) == NULL) in tls_buffer_new()
44 buf->capacity_limit = TLS_BUFFER_CAPACITY_LIMIT; in tls_buffer_new()
46 if (!tls_buffer_resize(buf, init_size)) in tls_buffer_new()
49 return buf; in tls_buffer_new()
52 tls_buffer_free(buf); in tls_buffer_new()
58 tls_buffer_clear(struct tls_buffer *buf) in tls_buffer_clear() argument
60 freezero(buf->data, buf->capacity); in tls_buffer_clear()
62 buf->data = NULL; in tls_buffer_clear()
63 buf->capacity = 0; in tls_buffer_clear()
64 buf->len = 0; in tls_buffer_clear()
65 buf->offset = 0; in tls_buffer_clear()
69 tls_buffer_free(struct tls_buffer *buf) in tls_buffer_free() argument
71 if (buf == NULL) in tls_buffer_free()
74 tls_buffer_clear(buf); in tls_buffer_free()
76 freezero(buf, sizeof(struct tls_buffer)); in tls_buffer_free()
80 tls_buffer_grow(struct tls_buffer *buf, size_t capacity) in tls_buffer_grow() argument
82 if (buf->capacity >= capacity) in tls_buffer_grow()
85 return tls_buffer_resize(buf, capacity); in tls_buffer_grow()
89 tls_buffer_resize(struct tls_buffer *buf, size_t capacity) in tls_buffer_resize() argument
97 if (buf->capacity == capacity) in tls_buffer_resize()
100 if (capacity > buf->capacity_limit) in tls_buffer_resize()
103 if ((data = recallocarray(buf->data, buf->capacity, capacity, 1)) == NULL) in tls_buffer_resize()
106 buf->data = data; in tls_buffer_resize()
107 buf->capacity = capacity; in tls_buffer_resize()
110 if (buf->len > buf->capacity) in tls_buffer_resize()
111 buf->len = buf->capacity; in tls_buffer_resize()
112 if (buf->offset > buf->len) in tls_buffer_resize()
113 buf->offset = buf->len; in tls_buffer_resize()
119 tls_buffer_set_capacity_limit(struct tls_buffer *buf, size_t limit) in tls_buffer_set_capacity_limit() argument
125 buf->capacity_limit = limit; in tls_buffer_set_capacity_limit()
129 tls_buffer_extend(struct tls_buffer *buf, size_t len, in tls_buffer_extend() argument
134 if (len == buf->len) in tls_buffer_extend()
135 return buf->len; in tls_buffer_extend()
137 if (len < buf->len) in tls_buffer_extend()
140 if (!tls_buffer_resize(buf, len)) in tls_buffer_extend()
144 if ((ret = read_cb(&buf->data[buf->len], in tls_buffer_extend()
145 buf->capacity - buf->len, cb_arg)) <= 0) in tls_buffer_extend()
148 if (ret > buf->capacity - buf->len) in tls_buffer_extend()
151 buf->len += ret; in tls_buffer_extend()
153 if (buf->len == buf->capacity) in tls_buffer_extend()
154 return buf->len; in tls_buffer_extend()
159 tls_buffer_remaining(struct tls_buffer *buf) in tls_buffer_remaining() argument
161 if (buf->offset > buf->len) in tls_buffer_remaining()
164 return buf->len - buf->offset; in tls_buffer_remaining()
168 tls_buffer_read(struct tls_buffer *buf, uint8_t *rbuf, size_t n) in tls_buffer_read() argument
170 if (buf->offset > buf->len) in tls_buffer_read()
173 if (buf->offset == buf->len) in tls_buffer_read()
176 if (n > buf->len - buf->offset) in tls_buffer_read()
177 n = buf->len - buf->offset; in tls_buffer_read()
179 memcpy(rbuf, &buf->data[buf->offset], n); in tls_buffer_read()
181 buf->offset += n; in tls_buffer_read()
187 tls_buffer_write(struct tls_buffer *buf, const uint8_t *wbuf, size_t n) in tls_buffer_write() argument
189 if (buf->offset > buf->len) in tls_buffer_write()
198 if (buf->offset == buf->len) { in tls_buffer_write()
199 buf->len = 0; in tls_buffer_write()
200 buf->offset = 0; in tls_buffer_write()
202 if (buf->offset >= 4096) { in tls_buffer_write()
203 memmove(buf->data, &buf->data[buf->offset], in tls_buffer_write()
204 buf->len - buf->offset); in tls_buffer_write()
205 buf->len -= buf->offset; in tls_buffer_write()
206 buf->offset = 0; in tls_buffer_write()
209 if (buf->len > SIZE_MAX - n) in tls_buffer_write()
211 if (!tls_buffer_grow(buf, buf->len + n)) in tls_buffer_write()
214 memcpy(&buf->data[buf->len], wbuf, n); in tls_buffer_write()
216 buf->len += n; in tls_buffer_write()
222 tls_buffer_append(struct tls_buffer *buf, const uint8_t *wbuf, size_t n) in tls_buffer_append() argument
224 return tls_buffer_write(buf, wbuf, n) == n; in tls_buffer_append()
228 tls_buffer_data(struct tls_buffer *buf, CBS *out_cbs) in tls_buffer_data() argument
232 CBS_init(&cbs, buf->data, buf->len); in tls_buffer_data()
234 if (!CBS_skip(&cbs, buf->offset)) in tls_buffer_data()
243 tls_buffer_finish(struct tls_buffer *buf, uint8_t **out, size_t *out_len) in tls_buffer_finish() argument
248 *out = buf->data; in tls_buffer_finish()
249 *out_len = buf->len; in tls_buffer_finish()
251 buf->data = NULL; in tls_buffer_finish()
252 buf->capacity = 0; in tls_buffer_finish()
253 buf->len = 0; in tls_buffer_finish()
254 buf->offset = 0; in tls_buffer_finish()