]> pd.if.org Git - zpackage/blobdiff - crypto/buffer.h
commit files needed for zpm-fetchurl
[zpackage] / crypto / buffer.h
diff --git a/crypto/buffer.h b/crypto/buffer.h
new file mode 100644 (file)
index 0000000..ad37f67
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef TLS_BUFFER_H_
+#define TLS_BUFFER_H_ 1
+
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+
+/* flags:
+ * 0x1 secure: zero memory when used
+ * 0x2 fixed: buffer doesn't belong to you, and size says how big it is
+ * 0x4 
+ */
+struct tls_buffer {
+       char *buffer;
+       size_t len;
+       size_t size;
+       int32_t error;
+       uint32_t flags;
+};
+
+struct tls_buffer_reader {
+       struct tls_buffer b;
+       size_t cursor;
+};
+
+uint32_t tls_buffer_next3(struct tls_buffer_reader *rb);
+uint16_t tls_buffer_next2(struct tls_buffer_reader *rb);
+uint8_t tls_buffer_next(struct tls_buffer_reader *rb);
+void tls_buffer_nextn(struct tls_buffer_reader *rb, unsigned char *b, size_t n);
+
+void tls_buffer_init(struct tls_buffer *b, size_t initial); 
+
+/* makes sure there's at least need bytes free */
+void tls_buffer_expand(struct tls_buffer *b, size_t need);
+void tls_buffer_free(struct tls_buffer *b);
+void tls_buffer_set(struct tls_buffer *buffer, int ch);
+void tls_buffer_compact(struct tls_buffer *b);
+void tls_buffer_append(struct tls_buffer *b, const unsigned char *bytes, size_t n);
+void tls_buffer_append16(struct tls_buffer *b, uint16_t n);
+void tls_buffer_append24(struct tls_buffer *b, uint32_t n);
+void tls_buffer_append_byte(struct tls_buffer *b, uint8_t n);
+void tls_buffer_shift(struct tls_buffer *b, size_t n);
+void tls_buffer_write16(struct tls_buffer *b, uint16_t n, size_t at);
+void tls_buffer_writebe(struct tls_buffer *b, int bytes, size_t at, uint64_t val);
+uint64_t tls_buffer_readbe(struct tls_buffer *b, int bytes, size_t at);
+
+/* make room at the beginning */
+void tls_buffer_unshift(struct tls_buffer *b, size_t n);
+
+#endif