Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilm3 committed Jul 9, 2024
1 parent 21afc1c commit cd315a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/processor/fingerprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ ddwaf_object generate_fragment(std::string_view header, Args... generators)
return res;
}

// Retur true if the first argument is less than (i.e. is ordered before) the second
// Return true if the first argument is less than (i.e. is ordered before) the second
bool str_casei_cmp(std::string_view left, std::string_view right)
{
auto n = std::min(left.size(), right.size());
Expand All @@ -183,8 +183,6 @@ bool str_casei_cmp(std::string_view left, std::string_view right)

void normalize_string(std::string_view key, std::string &buffer, bool trailing_separator)
{
// Clear should not deallocate...
// TODO: verify
buffer.clear();

if (buffer.capacity() < key.size()) {
Expand Down
16 changes: 8 additions & 8 deletions src/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,22 @@ sha256_hash &sha256_hash::operator<<(std::string_view str)
return *this;
}

template <std::size_t N>
template <std::size_t DigestLength>
std::string sha256_hash::digest()
requires(N % 8 == 0 && N <= 64)
requires(DigestLength % 8 == 0 && DigestLength <= 64)
{
std::string final_digest;
final_digest.resize(N, 0);
write_digest(std::span<char, N>{final_digest});
final_digest.resize(DigestLength, 0);
write_digest(std::span<char, DigestLength>{final_digest});
return final_digest;
}

template std::string sha256_hash::digest<64>();
template std::string sha256_hash::digest<8>();

template <std::size_t N>
void sha256_hash::write_digest(std::span<char, N> output)
requires(N % 8 == 0 && N <= 64)
template <std::size_t DigestLength>
void sha256_hash::write_digest(std::span<char, DigestLength> output)
requires(DigestLength % 8 == 0 && DigestLength <= 64)
{
auto *p = buffer.data();
size_t n = num;
Expand Down Expand Up @@ -193,7 +193,7 @@ void sha256_hash::write_digest(std::span<char, N> output)
num = 0;
memset(p, 0, block_size);

for (unsigned int nn = 0; nn < N; nn += 8) {
for (unsigned int nn = 0; nn < DigestLength; nn += 8) {
uint32_t ll = hash[nn >> 3];
output[nn + 0] = UINT8_TO_HEX_CHAR(static_cast<uint8_t>((ll >> 28) & 0x0f));
output[nn + 1] = UINT8_TO_HEX_CHAR(static_cast<uint8_t>((ll >> 24) & 0x0f));
Expand Down

0 comments on commit cd315a4

Please sign in to comment.