1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

LookupServer: Move case randomization into DNSName

* DNSName knows how to randomize itself
* DNSPacket no longer constructs DNSQuestion instances, it receives an already
  built DNSQuestion and just adds it to the list
* LookupServer::lookup() explicitly calls randomize_case() if it needs to
  randomize the case.
This commit is contained in:
Sergey Bugaev 2021-02-14 16:25:48 +03:00 committed by Andreas Kling
parent 89f718c4c5
commit bacbde31f3
5 changed files with 27 additions and 23 deletions

View file

@ -27,6 +27,7 @@
#include "DNSName.h"
#include <AK/Vector.h>
#include <ctype.h>
namespace LookupServer {
@ -77,6 +78,22 @@ size_t DNSName::serialized_size() const
return m_name.length() + 2;
}
void DNSName::randomize_case()
{
StringBuilder builder;
for (char c : m_name) {
// Randomize the 0x20 bit in every ASCII character.
if (isalpha(c)) {
if (arc4random_uniform(2))
c |= 0x20;
else
c &= ~0x20;
}
builder.append(c);
}
m_name = builder.to_string();
}
OutputStream& operator<<(OutputStream& stream, const DNSName& name)
{
auto parts = name.as_string().split_view('.');