diff --git a/src/actions/transformations/sha1.cc b/src/actions/transformations/sha1.cc index 684e5f96..04d49d4d 100644 --- a/src/actions/transformations/sha1.cc +++ b/src/actions/transformations/sha1.cc @@ -24,6 +24,8 @@ #include "modsecurity/assay.h" #include "actions/transformations/transformation.h" +#include "utils/sha1.h" +#include "src/utils.h" namespace ModSecurity { @@ -37,15 +39,12 @@ Sha1::Sha1(std::string action) std::string Sha1::evaluate(std::string value, Assay *assay) { - /** - * @todo Implement the transformation Sha1 - */ - if (assay) { -#ifndef NO_LOGS - assay->debug(4, "Transformation Sha1 is not implemented yet."); -#endif - } - return value; + + Utils::SHA1 sha1; + sha1.update(&value); + std::string sha1_bin = sha1.final_bin(); + + return sha1_bin; } } // namespace transformations diff --git a/src/utils/sha1.cc b/src/utils/sha1.cc index c029b806..bb7d10c1 100644 --- a/src/utils/sha1.cc +++ b/src/utils/sha1.cc @@ -65,7 +65,7 @@ void SHA1::update(std::istream *is) { } -std::string SHA1::final() { +std::string SHA1::final_bin(bool toReset = true) { /* Total number of hashed bits */ uint64_t total_bits = (transforms*BLOCK_BYTES + buffer.size()) * 8; @@ -91,6 +91,22 @@ std::string SHA1::final() { block[BLOCK_INTS - 2] = (total_bits >> 32); transform(block); + if (toReset) { + /* Reset for next run */ + reset(); + } + + std::string bin; + bin.append((const char*) digest, BLOCK_INTS); + + return bin; +} + + +std::string SHA1::final() { + + final_bin(false); + /* Hex std::string */ std::ostringstream result; for (unsigned int i = 0; i < DIGEST_INTS; i++) { diff --git a/src/utils/sha1.h b/src/utils/sha1.h index e1b42e97..5ac3a6e4 100644 --- a/src/utils/sha1.h +++ b/src/utils/sha1.h @@ -47,6 +47,10 @@ class SHA1 { void update(std::string *s); void update(std::istream *is); std::string final(); + std::string final_bin() { + return final_bin(true); + } + std::string final_bin(bool reset); private: /* number of 32bit integers per SHA1 digest */