Moved TLS stack to its own library
[strongswan.git] / src / libtls / tls_reader.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_reader tls_reader
18 * @{ @ingroup libtls
19 */
20
21 #ifndef TLS_READER_H_
22 #define TLS_READER_H_
23
24 typedef struct tls_reader_t tls_reader_t;
25
26 #include <library.h>
27
28 /**
29 * TLS record parser.
30 */
31 struct tls_reader_t {
32
33 /**
34 * Get the number of remaining bytes.
35 *
36 * @return number of remaining bytes in buffer
37 */
38 u_int32_t (*remaining)(tls_reader_t *this);
39
40 /**
41 * Peek the remaining data, not consuming any bytes.
42 *
43 * @return remaining data
44 */
45 chunk_t (*peek)(tls_reader_t *this);
46
47 /**
48 * Read a 8-bit integer from the buffer, advance.
49 *
50 * @param res pointer to result
51 * @return TRUE if integer read successfully
52 */
53 bool (*read_uint8)(tls_reader_t *this, u_int8_t *res);
54
55 /**
56 * Read a 16-bit integer from the buffer, advance.
57 *
58 * @param res pointer to result
59 * @return TRUE if integer read successfully
60 */
61 bool (*read_uint16)(tls_reader_t *this, u_int16_t *res);
62
63 /**
64 * Read a 24-bit integer from the buffer, advance.
65 *
66 * @param res pointer to result
67 * @return TRUE if integer read successfully
68 */
69 bool (*read_uint24)(tls_reader_t *this, u_int32_t *res);
70
71 /**
72 * Read a 32-bit integer from the buffer, advance.
73 *
74 * @param res pointer to result
75 * @return TRUE if integer read successfully
76 */
77 bool (*read_uint32)(tls_reader_t *this, u_int32_t *res);
78
79 /**
80 * Read a chunk of len bytes, advance.
81 *
82 * @param len number of bytes to read
83 * @param res pointer to result, not cloned
84 * @return TRUE if data read successfully
85 */
86 bool (*read_data)(tls_reader_t *this, u_int32_t len, chunk_t *res);
87
88 /**
89 * Read a chunk of bytes with a 8-bit length header, advance.
90 *
91 * @param res pointer to result, not cloned
92 * @return TRUE if data read successfully
93 */
94 bool (*read_data8)(tls_reader_t *this, chunk_t *res);
95
96 /**
97 * Read a chunk of bytes with a 16-bit length header, advance.
98 *
99 * @param res pointer to result, not cloned
100 * @return TRUE if data read successfully
101 */
102 bool (*read_data16)(tls_reader_t *this, chunk_t *res);
103
104 /**
105 * Read a chunk of bytes with a 24-bit length header, advance.
106 *
107 * @param res pointer to result, not cloned
108 * @return TRUE if data read successfully
109 */
110 bool (*read_data24)(tls_reader_t *this, chunk_t *res);
111
112 /**
113 * Read a chunk of bytes with a 32-bit length header, advance.
114 *
115 * @param res pointer to result, not cloned
116 * @return TRUE if data read successfully
117 */
118 bool (*read_data32)(tls_reader_t *this, chunk_t *res);
119
120 /**
121 * Destroy a tls_reader_t.
122 */
123 void (*destroy)(tls_reader_t *this);
124 };
125
126 /**
127 * Create a tls_reader instance.
128 */
129 tls_reader_t *tls_reader_create(chunk_t data);
130
131 #endif /** tls_reader_H_ @}*/