renamed tls_reader|writer to bio_* and moved to libstrongswan

This commit is contained in:
Andreas Steffen
2011-05-31 15:46:51 +02:00
parent 4cefb9bd10
commit 7e432eff6b
35 changed files with 299 additions and 306 deletions
+1
View File
@@ -10,6 +10,7 @@ printf_hook.c printf_hook.h \
asn1/asn1.c asn1/asn1.h \
asn1/asn1_parser.c asn1/asn1_parser.h \
asn1/oid.c asn1/oid.h \
bio/bio_reader.h bio/bio_reader.c bio/bio_writer.h bio/bio_writer.c \
crypto/crypters/crypter.c crypto/crypters/crypter.h \
crypto/hashers/hasher.h crypto/hashers/hasher.c \
crypto/pkcs9.c crypto/pkcs9.h \
+37 -37
View File
@@ -13,21 +13,21 @@
* for more details.
*/
#include "tls_reader.h"
#include "bio_reader.h"
#include <debug.h>
typedef struct private_tls_reader_t private_tls_reader_t;
typedef struct private_bio_reader_t private_bio_reader_t;
/**
* Private data of an tls_reader_t object.
* Private data of an bio_reader_t object.
*/
struct private_tls_reader_t {
struct private_bio_reader_t {
/**
* Public tls_reader_t interface.
* Public bio_reader_t interface.
*/
tls_reader_t public;
bio_reader_t public;
/**
* Remaining data to process
@@ -35,24 +35,24 @@ struct private_tls_reader_t {
chunk_t buf;
};
METHOD(tls_reader_t, remaining, u_int32_t,
private_tls_reader_t *this)
METHOD(bio_reader_t, remaining, u_int32_t,
private_bio_reader_t *this)
{
return this->buf.len;
}
METHOD(tls_reader_t, peek, chunk_t,
private_tls_reader_t *this)
METHOD(bio_reader_t, peek, chunk_t,
private_bio_reader_t *this)
{
return this->buf;
}
METHOD(tls_reader_t, read_uint8, bool,
private_tls_reader_t *this, u_int8_t *res)
METHOD(bio_reader_t, read_uint8, bool,
private_bio_reader_t *this, u_int8_t *res)
{
if (this->buf.len < 1)
{
DBG1(DBG_TLS, "%d bytes insufficient to parse u_int8 data",
DBG1(DBG_LIB, "%d bytes insufficient to parse u_int8 data",
this->buf.len);
return FALSE;
}
@@ -61,12 +61,12 @@ METHOD(tls_reader_t, read_uint8, bool,
return TRUE;
}
METHOD(tls_reader_t, read_uint16, bool,
private_tls_reader_t *this, u_int16_t *res)
METHOD(bio_reader_t, read_uint16, bool,
private_bio_reader_t *this, u_int16_t *res)
{
if (this->buf.len < 2)
{
DBG1(DBG_TLS, "%d bytes insufficient to parse u_int16 data",
DBG1(DBG_LIB, "%d bytes insufficient to parse u_int16 data",
this->buf.len);
return FALSE;
}
@@ -75,12 +75,12 @@ METHOD(tls_reader_t, read_uint16, bool,
return TRUE;
}
METHOD(tls_reader_t, read_uint24, bool,
private_tls_reader_t *this, u_int32_t *res)
METHOD(bio_reader_t, read_uint24, bool,
private_bio_reader_t *this, u_int32_t *res)
{
if (this->buf.len < 3)
{
DBG1(DBG_TLS, "%d bytes insufficient to parse u_int24 data",
DBG1(DBG_LIB, "%d bytes insufficient to parse u_int24 data",
this->buf.len);
return FALSE;
}
@@ -89,12 +89,12 @@ METHOD(tls_reader_t, read_uint24, bool,
return TRUE;
}
METHOD(tls_reader_t, read_uint32, bool,
private_tls_reader_t *this, u_int32_t *res)
METHOD(bio_reader_t, read_uint32, bool,
private_bio_reader_t *this, u_int32_t *res)
{
if (this->buf.len < 4)
{
DBG1(DBG_TLS, "%d bytes insufficient to parse u_int32 data",
DBG1(DBG_LIB, "%d bytes insufficient to parse u_int32 data",
this->buf.len);
return FALSE;
}
@@ -103,12 +103,12 @@ METHOD(tls_reader_t, read_uint32, bool,
return TRUE;
}
METHOD(tls_reader_t, read_data, bool,
private_tls_reader_t *this, u_int32_t len, chunk_t *res)
METHOD(bio_reader_t, read_data, bool,
private_bio_reader_t *this, u_int32_t len, chunk_t *res)
{
if (this->buf.len < len)
{
DBG1(DBG_TLS, "%d bytes insufficient to parse %d bytes of data",
DBG1(DBG_LIB, "%d bytes insufficient to parse %d bytes of data",
this->buf.len, len);
return FALSE;
}
@@ -117,8 +117,8 @@ METHOD(tls_reader_t, read_data, bool,
return TRUE;
}
METHOD(tls_reader_t, read_data8, bool,
private_tls_reader_t *this, chunk_t *res)
METHOD(bio_reader_t, read_data8, bool,
private_bio_reader_t *this, chunk_t *res)
{
u_int8_t len;
@@ -129,8 +129,8 @@ METHOD(tls_reader_t, read_data8, bool,
return read_data(this, len, res);
}
METHOD(tls_reader_t, read_data16, bool,
private_tls_reader_t *this, chunk_t *res)
METHOD(bio_reader_t, read_data16, bool,
private_bio_reader_t *this, chunk_t *res)
{
u_int16_t len;
@@ -141,8 +141,8 @@ METHOD(tls_reader_t, read_data16, bool,
return read_data(this, len, res);
}
METHOD(tls_reader_t, read_data24, bool,
private_tls_reader_t *this, chunk_t *res)
METHOD(bio_reader_t, read_data24, bool,
private_bio_reader_t *this, chunk_t *res)
{
u_int32_t len;
@@ -153,8 +153,8 @@ METHOD(tls_reader_t, read_data24, bool,
return read_data(this, len, res);
}
METHOD(tls_reader_t, read_data32, bool,
private_tls_reader_t *this, chunk_t *res)
METHOD(bio_reader_t, read_data32, bool,
private_bio_reader_t *this, chunk_t *res)
{
u_int32_t len;
@@ -165,8 +165,8 @@ METHOD(tls_reader_t, read_data32, bool,
return read_data(this, len, res);
}
METHOD(tls_reader_t, destroy, void,
private_tls_reader_t *this)
METHOD(bio_reader_t, destroy, void,
private_bio_reader_t *this)
{
free(this);
}
@@ -174,9 +174,9 @@ METHOD(tls_reader_t, destroy, void,
/**
* See header
*/
tls_reader_t *tls_reader_create(chunk_t data)
bio_reader_t *bio_reader_create(chunk_t data)
{
private_tls_reader_t *this;
private_bio_reader_t *this;
INIT(this,
.public = {
+23 -23
View File
@@ -14,35 +14,35 @@
*/
/**
* @defgroup tls_reader tls_reader
* @{ @ingroup libtls
* @defgroup bio_reader bio_reader
* @{ @ingroup bio
*/
#ifndef TLS_READER_H_
#define TLS_READER_H_
#ifndef BIO_READER_H_
#define BIO_READER_H_
typedef struct tls_reader_t tls_reader_t;
typedef struct bio_reader_t bio_reader_t;
#include <library.h>
/**
* TLS record parser.
* Buffered input parser.
*/
struct tls_reader_t {
struct bio_reader_t {
/**
* Get the number of remaining bytes.
*
* @return number of remaining bytes in buffer
*/
u_int32_t (*remaining)(tls_reader_t *this);
u_int32_t (*remaining)(bio_reader_t *this);
/**
* Peek the remaining data, not consuming any bytes.
*
* @return remaining data
*/
chunk_t (*peek)(tls_reader_t *this);
chunk_t (*peek)(bio_reader_t *this);
/**
* Read a 8-bit integer from the buffer, advance.
@@ -50,7 +50,7 @@ struct tls_reader_t {
* @param res pointer to result
* @return TRUE if integer read successfully
*/
bool (*read_uint8)(tls_reader_t *this, u_int8_t *res);
bool (*read_uint8)(bio_reader_t *this, u_int8_t *res);
/**
* Read a 16-bit integer from the buffer, advance.
@@ -58,7 +58,7 @@ struct tls_reader_t {
* @param res pointer to result
* @return TRUE if integer read successfully
*/
bool (*read_uint16)(tls_reader_t *this, u_int16_t *res);
bool (*read_uint16)(bio_reader_t *this, u_int16_t *res);
/**
* Read a 24-bit integer from the buffer, advance.
@@ -66,7 +66,7 @@ struct tls_reader_t {
* @param res pointer to result
* @return TRUE if integer read successfully
*/
bool (*read_uint24)(tls_reader_t *this, u_int32_t *res);
bool (*read_uint24)(bio_reader_t *this, u_int32_t *res);
/**
* Read a 32-bit integer from the buffer, advance.
@@ -74,7 +74,7 @@ struct tls_reader_t {
* @param res pointer to result
* @return TRUE if integer read successfully
*/
bool (*read_uint32)(tls_reader_t *this, u_int32_t *res);
bool (*read_uint32)(bio_reader_t *this, u_int32_t *res);
/**
* Read a chunk of len bytes, advance.
@@ -83,7 +83,7 @@ struct tls_reader_t {
* @param res pointer to result, not cloned
* @return TRUE if data read successfully
*/
bool (*read_data)(tls_reader_t *this, u_int32_t len, chunk_t *res);
bool (*read_data)(bio_reader_t *this, u_int32_t len, chunk_t *res);
/**
* Read a chunk of bytes with a 8-bit length header, advance.
@@ -91,7 +91,7 @@ struct tls_reader_t {
* @param res pointer to result, not cloned
* @return TRUE if data read successfully
*/
bool (*read_data8)(tls_reader_t *this, chunk_t *res);
bool (*read_data8)(bio_reader_t *this, chunk_t *res);
/**
* Read a chunk of bytes with a 16-bit length header, advance.
@@ -99,7 +99,7 @@ struct tls_reader_t {
* @param res pointer to result, not cloned
* @return TRUE if data read successfully
*/
bool (*read_data16)(tls_reader_t *this, chunk_t *res);
bool (*read_data16)(bio_reader_t *this, chunk_t *res);
/**
* Read a chunk of bytes with a 24-bit length header, advance.
@@ -107,7 +107,7 @@ struct tls_reader_t {
* @param res pointer to result, not cloned
* @return TRUE if data read successfully
*/
bool (*read_data24)(tls_reader_t *this, chunk_t *res);
bool (*read_data24)(bio_reader_t *this, chunk_t *res);
/**
* Read a chunk of bytes with a 32-bit length header, advance.
@@ -115,17 +115,17 @@ struct tls_reader_t {
* @param res pointer to result, not cloned
* @return TRUE if data read successfully
*/
bool (*read_data32)(tls_reader_t *this, chunk_t *res);
bool (*read_data32)(bio_reader_t *this, chunk_t *res);
/**
* Destroy a tls_reader_t.
* Destroy a bio_reader_t.
*/
void (*destroy)(tls_reader_t *this);
void (*destroy)(bio_reader_t *this);
};
/**
* Create a tls_reader instance.
* Create a bio_reader instance.
*/
tls_reader_t *tls_reader_create(chunk_t data);
bio_reader_t *bio_reader_create(chunk_t data);
#endif /** tls_reader_H_ @}*/
#endif /** bio_reader_H_ @}*/
+39 -39
View File
@@ -13,19 +13,19 @@
* for more details.
*/
#include "tls_writer.h"
#include "bio_writer.h"
typedef struct private_tls_writer_t private_tls_writer_t;
typedef struct private_bio_writer_t private_bio_writer_t;
/**
* Private data of an tls_writer_t object.
* Private data of an bio_writer_t object.
*/
struct private_tls_writer_t {
struct private_bio_writer_t {
/**
* Public tls_writer_t interface.
* Public bio_writer_t interface.
*/
tls_writer_t public;
bio_writer_t public;
/**
* Allocated buffer
@@ -46,14 +46,14 @@ struct private_tls_writer_t {
/**
* Increase buffer size
*/
static void increase(private_tls_writer_t *this)
static void increase(private_bio_writer_t *this)
{
this->buf.len += this->increase;
this->buf.ptr = realloc(this->buf.ptr, this->buf.len);
}
METHOD(tls_writer_t, write_uint8, void,
private_tls_writer_t *this, u_int8_t value)
METHOD(bio_writer_t, write_uint8, void,
private_bio_writer_t *this, u_int8_t value)
{
if (this->used + 1 > this->buf.len)
{
@@ -63,8 +63,8 @@ METHOD(tls_writer_t, write_uint8, void,
this->used += 1;
}
METHOD(tls_writer_t, write_uint16, void,
private_tls_writer_t *this, u_int16_t value)
METHOD(bio_writer_t, write_uint16, void,
private_bio_writer_t *this, u_int16_t value)
{
if (this->used + 2 > this->buf.len)
{
@@ -74,8 +74,8 @@ METHOD(tls_writer_t, write_uint16, void,
this->used += 2;
}
METHOD(tls_writer_t, write_uint24, void,
private_tls_writer_t *this, u_int32_t value)
METHOD(bio_writer_t, write_uint24, void,
private_bio_writer_t *this, u_int32_t value)
{
if (this->used + 3 > this->buf.len)
{
@@ -86,8 +86,8 @@ METHOD(tls_writer_t, write_uint24, void,
this->used += 3;
}
METHOD(tls_writer_t, write_uint32, void,
private_tls_writer_t *this, u_int32_t value)
METHOD(bio_writer_t, write_uint32, void,
private_bio_writer_t *this, u_int32_t value)
{
if (this->used + 4 > this->buf.len)
{
@@ -97,8 +97,8 @@ METHOD(tls_writer_t, write_uint32, void,
this->used += 4;
}
METHOD(tls_writer_t, write_data, void,
private_tls_writer_t *this, chunk_t value)
METHOD(bio_writer_t, write_data, void,
private_bio_writer_t *this, chunk_t value)
{
while (this->used + value.len > this->buf.len)
{
@@ -108,36 +108,36 @@ METHOD(tls_writer_t, write_data, void,
this->used += value.len;
}
METHOD(tls_writer_t, write_data8, void,
private_tls_writer_t *this, chunk_t value)
METHOD(bio_writer_t, write_data8, void,
private_bio_writer_t *this, chunk_t value)
{
write_uint8(this, value.len);
write_data(this, value);
}
METHOD(tls_writer_t, write_data16, void,
private_tls_writer_t *this, chunk_t value)
METHOD(bio_writer_t, write_data16, void,
private_bio_writer_t *this, chunk_t value)
{
write_uint16(this, value.len);
write_data(this, value);
}
METHOD(tls_writer_t, write_data24, void,
private_tls_writer_t *this, chunk_t value)
METHOD(bio_writer_t, write_data24, void,
private_bio_writer_t *this, chunk_t value)
{
write_uint24(this, value.len);
write_data(this, value);
}
METHOD(tls_writer_t, write_data32, void,
private_tls_writer_t *this, chunk_t value)
METHOD(bio_writer_t, write_data32, void,
private_bio_writer_t *this, chunk_t value)
{
write_uint32(this, value.len);
write_data(this, value);
}
METHOD(tls_writer_t, wrap8, void,
private_tls_writer_t *this)
METHOD(bio_writer_t, wrap8, void,
private_bio_writer_t *this)
{
if (this->used + 1 > this->buf.len)
{
@@ -148,8 +148,8 @@ METHOD(tls_writer_t, wrap8, void,
this->used += 1;
}
METHOD(tls_writer_t, wrap16, void,
private_tls_writer_t *this)
METHOD(bio_writer_t, wrap16, void,
private_bio_writer_t *this)
{
if (this->used + 2 > this->buf.len)
{
@@ -160,8 +160,8 @@ METHOD(tls_writer_t, wrap16, void,
this->used += 2;
}
METHOD(tls_writer_t, wrap24, void,
private_tls_writer_t *this)
METHOD(bio_writer_t, wrap24, void,
private_bio_writer_t *this)
{
u_int32_t len;
@@ -176,8 +176,8 @@ METHOD(tls_writer_t, wrap24, void,
this->used += 3;
}
METHOD(tls_writer_t, wrap32, void,
private_tls_writer_t *this)
METHOD(bio_writer_t, wrap32, void,
private_bio_writer_t *this)
{
if (this->used + 4 > this->buf.len)
{
@@ -188,14 +188,14 @@ METHOD(tls_writer_t, wrap32, void,
this->used += 4;
}
METHOD(tls_writer_t, get_buf, chunk_t,
private_tls_writer_t *this)
METHOD(bio_writer_t, get_buf, chunk_t,
private_bio_writer_t *this)
{
return chunk_create(this->buf.ptr, this->used);
}
METHOD(tls_writer_t, destroy, void,
private_tls_writer_t *this)
METHOD(bio_writer_t, destroy, void,
private_bio_writer_t *this)
{
free(this->buf.ptr);
free(this);
@@ -204,9 +204,9 @@ METHOD(tls_writer_t, destroy, void,
/**
* See header
*/
tls_writer_t *tls_writer_create(u_int32_t bufsize)
bio_writer_t *bio_writer_create(u_int32_t bufsize)
{
private_tls_writer_t *this;
private_bio_writer_t *this;
INIT(this,
.public = {
+26 -26
View File
@@ -14,123 +14,123 @@
*/
/**
* @defgroup tls_writer tls_writer
* @{ @ingroup libtls
* @defgroup bio_writer bio_writer
* @{ @ingroup bio
*/
#ifndef TLS_WRITER_H_
#define TLS_WRITER_H_
#ifndef BIO_WRITER_H_
#define BIO_WRITER_H_
typedef struct tls_writer_t tls_writer_t;
typedef struct bio_writer_t bio_writer_t;
#include <library.h>
/**
* TLS record generator.
* Buffered output generator.
*/
struct tls_writer_t {
struct bio_writer_t {
/**
* Append a 8-bit integer to the buffer.
*
* @param value value to append
*/
void (*write_uint8)(tls_writer_t *this, u_int8_t value);
void (*write_uint8)(bio_writer_t *this, u_int8_t value);
/**
* Append a 16-bit integer to the buffer.
*
* @param value value to append
*/
void (*write_uint16)(tls_writer_t *this, u_int16_t value);
void (*write_uint16)(bio_writer_t *this, u_int16_t value);
/**
* Append a 24-bit integer to the buffer.
*
* @param value value to append
*/
void (*write_uint24)(tls_writer_t *this, u_int32_t value);
void (*write_uint24)(bio_writer_t *this, u_int32_t value);
/**
* Append a 32-bit integer to the buffer.
*
* @param value value to append
*/
void (*write_uint32)(tls_writer_t *this, u_int32_t value);
void (*write_uint32)(bio_writer_t *this, u_int32_t value);
/**
* Append a chunk of data without a length header.
*
* @param value value to append
*/
void (*write_data)(tls_writer_t *this, chunk_t value);
void (*write_data)(bio_writer_t *this, chunk_t value);
/**
* Append a chunk of data with a 8-bit length header.
*
* @param value value to append
*/
void (*write_data8)(tls_writer_t *this, chunk_t value);
void (*write_data8)(bio_writer_t *this, chunk_t value);
/**
* Append a chunk of data with a 16-bit length header.
*
* @param value value to append
*/
void (*write_data16)(tls_writer_t *this, chunk_t value);
void (*write_data16)(bio_writer_t *this, chunk_t value);
/**
* Append a chunk of data with a 24-bit length header.
*
* @param value value to append
*/
void (*write_data24)(tls_writer_t *this, chunk_t value);
void (*write_data24)(bio_writer_t *this, chunk_t value);
/**
* Append a chunk of data with a 32-bit length header.
*
* @param value value to append
*/
void (*write_data32)(tls_writer_t *this, chunk_t value);
void (*write_data32)(bio_writer_t *this, chunk_t value);
/**
* Prepend a 8-bit length header to existing data.
*/
void (*wrap8)(tls_writer_t *this);
void (*wrap8)(bio_writer_t *this);
/**
* Prepend a 16-bit length header to existing data.
*/
void (*wrap16)(tls_writer_t *this);
void (*wrap16)(bio_writer_t *this);
/**
* Prepend a 24-bit length header to existing data.
*/
void (*wrap24)(tls_writer_t *this);
void (*wrap24)(bio_writer_t *this);
/**
* Prepend a 32-bit length header to existing data.
*/
void (*wrap32)(tls_writer_t *this);
void (*wrap32)(bio_writer_t *this);
/**
* Get the encoded data buffer.
*
* @return chunk to internal buffer
*/
chunk_t (*get_buf)(tls_writer_t *this);
chunk_t (*get_buf)(bio_writer_t *this);
/**
* Destroy a tls_writer_t.
* Destroy a bio_writer_t.
*/
void (*destroy)(tls_writer_t *this);
void (*destroy)(bio_writer_t *this);
};
/**
* Create a tls_writer instance.
* Create a bio_writer instance.
*
* @param bufsize initially allocated buffer size
*/
tls_writer_t *tls_writer_create(u_int32_t bufsize);
bio_writer_t *bio_writer_create(u_int32_t bufsize);
#endif /** TLS_WRITER_H_ @}*/
#endif /** BIO_WRITER_H_ @}*/