| 1 | #ifndef util_h |
| 2 | #define util_h |
| 3 | |
| 4 | #include "secnet.h" |
| 5 | #include <gmp.h> |
| 6 | |
| 7 | #define BUF_ASSERT_FREE(buf) do { buffer_assert_free((buf), \ |
| 8 | __FILE__,__LINE__); } \ |
| 9 | while(0) |
| 10 | #define BUF_ASSERT_USED(buf) do { buffer_assert_used((buf), \ |
| 11 | __FILE__,__LINE__); } \ |
| 12 | while(0) |
| 13 | #define BUF_ALLOC(buf,own) do { buffer_assert_free((buf),__FILE__,__LINE__); \ |
| 14 | (buf)->free=False; (buf)->owner=(own); (buf)->start=(buf)->base; \ |
| 15 | (buf)->size=0; } while(0) |
| 16 | #define BUF_FREE(buf) do { (buf)->free=True; } while(0) |
| 17 | |
| 18 | extern void buffer_assert_free(struct buffer_if *buffer, cstring_t file, |
| 19 | uint32_t line); |
| 20 | extern void buffer_assert_used(struct buffer_if *buffer, cstring_t file, |
| 21 | uint32_t line); |
| 22 | extern void buffer_new(struct buffer_if *buffer, uint32_t len); |
| 23 | extern void buffer_init(struct buffer_if *buffer, uint32_t max_start_pad); |
| 24 | extern void *buf_append(struct buffer_if *buf, uint32_t amount); |
| 25 | extern void *buf_prepend(struct buffer_if *buf, uint32_t amount); |
| 26 | extern void *buf_unappend(struct buffer_if *buf, uint32_t amount); |
| 27 | extern void *buf_unprepend(struct buffer_if *buf, uint32_t amount); |
| 28 | |
| 29 | extern void buf_append_string(struct buffer_if *buf, cstring_t s); |
| 30 | |
| 31 | extern void read_mpbin(MP_INT *a, uint8_t *bin, int binsize); |
| 32 | |
| 33 | extern char *write_mpstring(MP_INT *a); |
| 34 | |
| 35 | extern uint32_t write_mpbin(MP_INT *a, uint8_t *buffer, uint32_t buflen); |
| 36 | |
| 37 | extern struct log_if *init_log(list_t *loglist); |
| 38 | |
| 39 | #endif /* util_h */ |