forked from tastytea/libravatarserv
Check if hash is valid
This commit is contained in:
parent
513391f44b
commit
1aca78df88
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.2)
|
cmake_minimum_required (VERSION 3.2)
|
||||||
project(libravatarserv
|
project(libravatarserv
|
||||||
VERSION 0.6.4
|
VERSION 0.6.5
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
28
src/hash.cpp
28
src/hash.cpp
|
@ -69,3 +69,31 @@ bool hash::fill_table()
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hash::is_valid(const string &digest)
|
||||||
|
{
|
||||||
|
if (digest.length() != 64 && digest.length() != 32)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (std::any_of(digest.begin(), digest.end(), not_hex))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hash::not_hex(const char &c)
|
||||||
|
{
|
||||||
|
if (c >= 0x61 && c <= 0x66)
|
||||||
|
{ // a-f
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (c >= 0x30 && c <= 0x39)
|
||||||
|
{ // 0-9
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,12 @@ int main()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
http::Request avatar = http::parse_request(request);
|
http::Request avatar = http::parse_request(request);
|
||||||
|
if (!hash::is_valid(avatar.digest))
|
||||||
|
{
|
||||||
|
cout << "Status: 400 Bad Request\n\n";
|
||||||
|
cerr << "Error: Hash is invalid\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!find_avatar_dir())
|
if (!find_avatar_dir())
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,6 +71,8 @@ namespace hash // hash.cpp
|
||||||
const string md5(const string &text);
|
const string md5(const string &text);
|
||||||
const string sha256(const string &text);
|
const string sha256(const string &text);
|
||||||
bool fill_table();
|
bool fill_table();
|
||||||
|
bool is_valid(const string &digest);
|
||||||
|
bool not_hex(const char &c);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace image // image.cpp
|
namespace image // image.cpp
|
||||||
|
|
Loading…
Reference in New Issue