2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
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>.
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
17 * @defgroup tls_reader tls_reader
24 typedef struct tls_reader_t tls_reader_t
;
34 * Get the number of remaining bytes.
36 * @return number of remaining bytes in buffer
38 u_int32_t (*remaining
)(tls_reader_t
*this);
41 * Peek the remaining data, not consuming any bytes.
43 * @return remaining data
45 chunk_t (*peek
)(tls_reader_t
*this);
48 * Read a 8-bit integer from the buffer, advance.
50 * @param res pointer to result
51 * @return TRUE if integer read successfully
53 bool (*read_uint8
)(tls_reader_t
*this, u_int8_t
*res
);
56 * Read a 16-bit integer from the buffer, advance.
58 * @param res pointer to result
59 * @return TRUE if integer read successfully
61 bool (*read_uint16
)(tls_reader_t
*this, u_int16_t
*res
);
64 * Read a 24-bit integer from the buffer, advance.
66 * @param res pointer to result
67 * @return TRUE if integer read successfully
69 bool (*read_uint24
)(tls_reader_t
*this, u_int32_t
*res
);
72 * Read a 32-bit integer from the buffer, advance.
74 * @param res pointer to result
75 * @return TRUE if integer read successfully
77 bool (*read_uint32
)(tls_reader_t
*this, u_int32_t
*res
);
80 * Read a chunk of len bytes, advance.
82 * @param len number of bytes to read
83 * @param res pointer to result, not cloned
84 * @return TRUE if data read successfully
86 bool (*read_data
)(tls_reader_t
*this, u_int32_t len
, chunk_t
*res
);
89 * Read a chunk of bytes with a 8-bit length header, advance.
91 * @param res pointer to result, not cloned
92 * @return TRUE if data read successfully
94 bool (*read_data8
)(tls_reader_t
*this, chunk_t
*res
);
97 * Read a chunk of bytes with a 16-bit length header, advance.
99 * @param res pointer to result, not cloned
100 * @return TRUE if data read successfully
102 bool (*read_data16
)(tls_reader_t
*this, chunk_t
*res
);
105 * Read a chunk of bytes with a 24-bit length header, advance.
107 * @param res pointer to result, not cloned
108 * @return TRUE if data read successfully
110 bool (*read_data24
)(tls_reader_t
*this, chunk_t
*res
);
113 * Read a chunk of bytes with a 32-bit length header, advance.
115 * @param res pointer to result, not cloned
116 * @return TRUE if data read successfully
118 bool (*read_data32
)(tls_reader_t
*this, chunk_t
*res
);
121 * Destroy a tls_reader_t.
123 void (*destroy
)(tls_reader_t
*this);
127 * Create a tls_reader instance.
129 tls_reader_t
*tls_reader_create(chunk_t data
);
131 #endif /** tls_reader_H_ @}*/