diff options
-rw-r--r-- | src/libstrongswan/chunk.c | 51 | ||||
-rw-r--r-- | src/libstrongswan/chunk.h | 35 |
2 files changed, 30 insertions, 56 deletions
diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c index e23450259..1d0f9279a 100644 --- a/src/libstrongswan/chunk.c +++ b/src/libstrongswan/chunk.c @@ -45,15 +45,6 @@ chunk_t chunk_empty = { NULL, 0 }; /** * Described in header. */ -chunk_t chunk_create(u_char *ptr, size_t len) -{ - chunk_t chunk = {ptr, len}; - return chunk; -} - -/** - * Described in header. - */ chunk_t chunk_create_clone(u_char *ptr, chunk_t chunk) { chunk_t clone = chunk_empty; @@ -439,39 +430,6 @@ chunk_t chunk_from_base64(chunk_t base64, char *buf) /** * Described in header. */ -void chunk_free(chunk_t *chunk) -{ - free(chunk->ptr); - chunk->ptr = NULL; - chunk->len = 0; -} - -/** - * Described in header. - */ -void chunk_clear(chunk_t *chunk) -{ - memset(chunk->ptr, 0, chunk->len); - chunk_free(chunk); -} - -/** - * Described in header. - */ -chunk_t chunk_skip(chunk_t chunk, size_t bytes) -{ - if (chunk.len > bytes) - { - chunk.ptr += bytes; - chunk.len -= bytes; - return chunk; - } - return chunk_empty; -} - -/** - * Described in header. - */ int chunk_compare(chunk_t a, chunk_t b) { int compare_len = a.len - b.len; @@ -486,15 +444,6 @@ int chunk_compare(chunk_t a, chunk_t b) /** * Described in header. - */ -bool chunk_equals(chunk_t a, chunk_t b) -{ - return a.ptr != NULL && b.ptr != NULL && - a.len == b.len && memeq(a.ptr, b.ptr, a.len); -} - -/** - * Described in header. * * The implementation is based on Paul Hsieh's SuperFastHash: * http://www.azillionmonkeys.com/qed/hash.html diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h index 46ac7db4e..566137589 100644 --- a/src/libstrongswan/chunk.h +++ b/src/libstrongswan/chunk.h @@ -51,7 +51,11 @@ extern chunk_t chunk_empty; /** * Create a new chunk pointing to "ptr" with length "len" */ -chunk_t chunk_create(u_char *ptr, size_t len); +static inline chunk_t chunk_create(u_char *ptr, size_t len) +{ + chunk_t chunk = {ptr, len}; + return chunk; +} /** * Create a clone of a chunk pointing to "ptr" @@ -136,12 +140,20 @@ chunk_t chunk_from_base64(chunk_t base64, char *buf); /** * Free contents of a chunk */ -void chunk_free(chunk_t *chunk); +static inline void chunk_free(chunk_t *chunk) +{ + free(chunk->ptr); + *chunk = chunk_empty; +} /** * Overwrite the contents of a chunk and free it */ -void chunk_clear(chunk_t *chunk); +static inline void chunk_clear(chunk_t *chunk) +{ + memset(chunk->ptr, 0, chunk->len); + chunk_free(chunk); +} /** * Initialize a chunk to point to buffer inspectable by sizeof() @@ -186,7 +198,16 @@ void chunk_clear(chunk_t *chunk); /** * Skip n bytes in chunk (forward pointer, shorten length) */ -chunk_t chunk_skip(chunk_t chunk, size_t bytes); +static inline chunk_t chunk_skip(chunk_t chunk, size_t bytes) +{ + if (chunk.len > bytes) + { + chunk.ptr += bytes; + chunk.len -= bytes; + return chunk; + } + return chunk_empty; +} /** * Compare two chunks, returns zero if a equals b @@ -198,7 +219,11 @@ int chunk_compare(chunk_t a, chunk_t b); * Compare two chunks for equality, * NULL chunks are never equal. */ -bool chunk_equals(chunk_t a, chunk_t b); +static inline bool chunk_equals(chunk_t a, chunk_t b) +{ + return a.ptr != NULL && b.ptr != NULL && + a.len == b.len && memeq(a.ptr, b.ptr, a.len); +} /** * Computes a 32 bit hash of the given chunk. |