From 93c3bc804ea8b1d21aa3c98f1149dd086d1784ea Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 23 Oct 2015 13:35:23 -0300 Subject: [PATCH] Adds hexEncode transformation --- src/actions/transformations/hex_encode.cc | 16 ++++++++-------- src/actions/transformations/transformation.cc | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/actions/transformations/hex_encode.cc b/src/actions/transformations/hex_encode.cc index fa645e2a..827d702b 100644 --- a/src/actions/transformations/hex_encode.cc +++ b/src/actions/transformations/hex_encode.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include "modsecurity/assay.h" #include "actions/transformations/transformation.h" @@ -37,15 +38,14 @@ HexEncode::HexEncode(std::string action) std::string HexEncode::evaluate(std::string value, Assay *assay) { - /** - * @todo Implement the transformation HexEncode - */ - if (assay) { -#ifndef NO_LOGS - assay->debug(4, "Transformation HexEncode is not implemented yet."); -#endif + + std::stringstream result; + for (std::size_t i=0; i < value.length(); i++) { + int ii = (char)value[i]; + result << std::setw(2) << std::setfill('0') << std::hex << ii; } - return value; + + return result.str(); } } // namespace transformations diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index 1dfc8177..5a48f2f0 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -81,7 +81,7 @@ Transformation* Transformation::instantiate(std::string a) { IF_MATCH(cssDecode) { return new CssDecode(a); } IF_MATCH(escape_seq_decode) { return new EscapeSeqDecode(a); } IF_MATCH(hex_decode) { return new HexDecode(a); } - IF_MATCH(hex_encode) { return new HexEncode(a); } + IF_MATCH(hexEncode) { return new HexEncode(a); } IF_MATCH(htmlEntityDecode) { return new HtmlEntityDecode(a); } IF_MATCH(jsDecode) { return new JsDecode(a); } IF_MATCH(length) { return new Length(a); }