summaryrefslogtreecommitdiff
path: root/src/libstrongswan/chunk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/chunk.c')
-rw-r--r--src/libstrongswan/chunk.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c
index c9c181f87..40a93e21a 100644
--- a/src/libstrongswan/chunk.c
+++ b/src/libstrongswan/chunk.c
@@ -19,6 +19,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
+#include <ctype.h>
#include "chunk.h"
@@ -442,6 +443,32 @@ int chunk_compare(chunk_t a, chunk_t b)
};
/**
+ * Remove non-printable characters from a chunk.
+ */
+bool chunk_printable(chunk_t chunk, chunk_t *sane, char replace)
+{
+ bool printable = TRUE;
+ int i;
+
+ if (sane)
+ {
+ *sane = chunk_clone(chunk);
+ }
+ for (i = 0; i < chunk.len; i++)
+ {
+ if (!isprint(chunk.ptr[i]))
+ {
+ if (sane)
+ {
+ sane->ptr[i] = replace;
+ }
+ printable = FALSE;
+ }
+ }
+ return printable;
+}
+
+/**
* Described in header.
*
* The implementation is based on Paul Hsieh's SuperFastHash: