aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-06-29 10:47:20 +0200
committerTobias Brunner <tobias@strongswan.org>2012-08-08 15:41:02 +0200
commit6dfdcf420f789797fddccaaa00c75c77b1d5be65 (patch)
treede3dd38d584ebd5a6fb177da8987a64604f90d9f
parent59a15a7475f60049dc2b259935c2a047ec764f95 (diff)
downloadstrongswan-6dfdcf420f789797fddccaaa00c75c77b1d5be65.tar.bz2
strongswan-6dfdcf420f789797fddccaaa00c75c77b1d5be65.tar.xz
Added a method to bio_writer_t that allows to skip a number of bytes
A chunk pointing to the skipped bytes is returned, allowing users of bio_writer_t to write/copy data to the skipped bytes themselves.
-rw-r--r--src/libstrongswan/bio/bio_writer.c15
-rw-r--r--src/libstrongswan/bio/bio_writer.h9
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libstrongswan/bio/bio_writer.c b/src/libstrongswan/bio/bio_writer.c
index 16a16f4bd..8576843ee 100644
--- a/src/libstrongswan/bio/bio_writer.c
+++ b/src/libstrongswan/bio/bio_writer.c
@@ -202,6 +202,20 @@ METHOD(bio_writer_t, wrap32, void,
this->used += 4;
}
+METHOD(bio_writer_t, skip, chunk_t,
+ private_bio_writer_t *this, size_t len)
+{
+ chunk_t skipped;
+
+ while (this->used + len > this->buf.len)
+ {
+ increase(this);
+ }
+ skipped = chunk_create(this->buf.ptr + this->used, len);
+ this->used += len;
+ return skipped;
+}
+
METHOD(bio_writer_t, get_buf, chunk_t,
private_bio_writer_t *this)
{
@@ -247,6 +261,7 @@ bio_writer_t *bio_writer_create(u_int32_t bufsize)
.wrap16 = _wrap16,
.wrap24 = _wrap24,
.wrap32 = _wrap32,
+ .skip = _skip,
.get_buf = _get_buf,
.extract_buf = _extract_buf,
.destroy = _destroy,
diff --git a/src/libstrongswan/bio/bio_writer.h b/src/libstrongswan/bio/bio_writer.h
index 8f84d0500..57a5c3d38 100644
--- a/src/libstrongswan/bio/bio_writer.h
+++ b/src/libstrongswan/bio/bio_writer.h
@@ -126,6 +126,15 @@ struct bio_writer_t {
void (*wrap32)(bio_writer_t *this);
/**
+ * Skips len bytes in the buffer before the next data is written, returns
+ * a chunk covering the skipped bytes.
+ *
+ * @param len number of bytes to skip
+ * @return chunk pointing to skipped bytes in the internal buffer
+ */
+ chunk_t (*skip)(bio_writer_t *this, size_t len);
+
+ /**
* Get the encoded data buffer.
*
* @return chunk to internal buffer