]> pd.if.org Git - zpackage/blob - crypto/buffer.h
remove stray debug fprintf
[zpackage] / crypto / buffer.h
1 #ifndef TLS_BUFFER_H_
2 #define TLS_BUFFER_H_ 1
3
4 #include <stdint.h>
5 #include <string.h>
6 #include <errno.h>
7
8 /* flags:
9  * 0x1 secure: zero memory when used
10  * 0x2 fixed: buffer doesn't belong to you, and size says how big it is
11  * 0x4 
12  */
13 struct tls_buffer {
14         char *buffer;
15         size_t len;
16         size_t size;
17         int32_t error;
18         uint32_t flags;
19 };
20
21 struct tls_buffer_reader {
22         struct tls_buffer b;
23         size_t cursor;
24 };
25
26 uint32_t tls_buffer_next3(struct tls_buffer_reader *rb);
27 uint16_t tls_buffer_next2(struct tls_buffer_reader *rb);
28 uint8_t tls_buffer_next(struct tls_buffer_reader *rb);
29 void tls_buffer_nextn(struct tls_buffer_reader *rb, unsigned char *b, size_t n);
30
31 void tls_buffer_init(struct tls_buffer *b, size_t initial); 
32
33 /* makes sure there's at least need bytes free */
34 void tls_buffer_expand(struct tls_buffer *b, size_t need);
35 void tls_buffer_free(struct tls_buffer *b);
36 void tls_buffer_set(struct tls_buffer *buffer, int ch);
37 void tls_buffer_compact(struct tls_buffer *b);
38 void tls_buffer_append(struct tls_buffer *b, const unsigned char *bytes, size_t n);
39 void tls_buffer_append_str(struct tls_buffer *b, const unsigned char *bytes);
40 void tls_buffer_append16(struct tls_buffer *b, uint16_t n);
41 void tls_buffer_append24(struct tls_buffer *b, uint32_t n);
42 void tls_buffer_append_byte(struct tls_buffer *b, uint8_t n);
43 void tls_buffer_shift(struct tls_buffer *b, size_t n);
44 void tls_buffer_write16(struct tls_buffer *b, uint16_t n, size_t at);
45 void tls_buffer_writebe(struct tls_buffer *b, int bytes, size_t at, uint64_t val);
46 uint64_t tls_buffer_readbe(struct tls_buffer *b, int bytes, size_t at);
47
48 /* make room at the beginning */
49 void tls_buffer_unshift(struct tls_buffer *b, size_t n);
50
51 #endif