Register hmac/xcbc algorithms after potentially underlying PKCS#11
[strongswan.git] / src / libtls / tls_writer.h
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup tls_writer tls_writer
18 * @{ @ingroup libtls
19 */
20
21 #ifndef TLS_WRITER_H_
22 #define TLS_WRITER_H_
23
24 typedef struct tls_writer_t tls_writer_t;
25
26 #include <library.h>
27
28 /**
29 * TLS record generator.
30 */
31 struct tls_writer_t {
32
33 /**
34 * Append a 8-bit integer to the buffer.
35 *
36 * @param value value to append
37 */
38 void (*write_uint8)(tls_writer_t *this, u_int8_t value);
39
40 /**
41 * Append a 16-bit integer to the buffer.
42 *
43 * @param value value to append
44 */
45 void (*write_uint16)(tls_writer_t *this, u_int16_t value);
46
47 /**
48 * Append a 24-bit integer to the buffer.
49 *
50 * @param value value to append
51 */
52 void (*write_uint24)(tls_writer_t *this, u_int32_t value);
53
54 /**
55 * Append a 32-bit integer to the buffer.
56 *
57 * @param value value to append
58 */
59 void (*write_uint32)(tls_writer_t *this, u_int32_t value);
60
61 /**
62 * Append a chunk of data without a length header.
63 *
64 * @param value value to append
65 */
66 void (*write_data)(tls_writer_t *this, chunk_t value);
67
68 /**
69 * Append a chunk of data with a 16-bit length header.
70 *
71 * @param value value to append
72 */
73 void (*write_data8)(tls_writer_t *this, chunk_t value);
74
75 /**
76 * Append a chunk of data with a 8-bit length header.
77 *
78 * @param value value to append
79 */
80 void (*write_data16)(tls_writer_t *this, chunk_t value);
81
82 /**
83 * Append a chunk of data with a 24-bit length header.
84 *
85 * @param value value to append
86 */
87 void (*write_data24)(tls_writer_t *this, chunk_t value);
88
89 /**
90 * Append a chunk of data with a 32-bit length header.
91 *
92 * @param value value to append
93 */
94 void (*write_data32)(tls_writer_t *this, chunk_t value);
95
96 /**
97 * Prepend a 8-bit length header to existing data.
98 */
99 void (*wrap8)(tls_writer_t *this);
100
101 /**
102 * Prepend a 16-bit length header to existing data.
103 */
104 void (*wrap16)(tls_writer_t *this);
105
106 /**
107 * Prepend a 24-bit length header to existing data.
108 */
109 void (*wrap24)(tls_writer_t *this);
110
111 /**
112 * Prepend a 32-bit length header to existing data.
113 */
114 void (*wrap32)(tls_writer_t *this);
115
116 /**
117 * Get the encoded data buffer.
118 *
119 * @return chunk to internal buffer
120 */
121 chunk_t (*get_buf)(tls_writer_t *this);
122
123 /**
124 * Destroy a tls_writer_t.
125 */
126 void (*destroy)(tls_writer_t *this);
127 };
128
129 /**
130 * Create a tls_writer instance.
131 *
132 * @param bufsize initially allocated buffer size
133 */
134 tls_writer_t *tls_writer_create(u_int32_t bufsize);
135
136 #endif /** TLS_WRITER_H_ @}*/