2025-06-03 05:13:41 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-09 11:20:14 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-09 11:20:14 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-09 11:20:14 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-09 11:20:14 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_HASHSERIALIZER
|
|
|
|
|
#define INCLUDED_HASHSERIALIZER
|
|
|
|
|
|
2025-08-07 10:53:23 -07:00
|
|
|
#include "lib/types.h"
|
2010-01-10 11:29:27 -08:00
|
|
|
#include "maths/MD5.h"
|
2025-08-07 10:53:23 -07:00
|
|
|
#include "simulation2/serialization/BinarySerializer.h"
|
|
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
|
|
class ScriptInterface;
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2010-05-25 12:01:30 -07:00
|
|
|
class CHashSerializerImpl
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
|
|
|
|
// We don't care about cryptographic strength, just about detection of
|
2010-01-10 11:29:27 -08:00
|
|
|
// unintended changes and about performance, so MD5 is an adequate choice
|
|
|
|
|
typedef MD5 HashFunc;
|
2010-05-25 12:01:30 -07:00
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
public:
|
|
|
|
|
size_t GetHashLength();
|
|
|
|
|
const u8* ComputeHash();
|
|
|
|
|
|
2025-06-03 05:13:41 -07:00
|
|
|
void Put(const char* /*name*/, const u8* data, size_t len)
|
2010-05-25 12:01:30 -07:00
|
|
|
{
|
|
|
|
|
m_Hash.Update(data, len);
|
|
|
|
|
}
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
HashFunc m_Hash;
|
|
|
|
|
u8 m_HashData[HashFunc::DIGESTSIZE];
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-25 12:01:30 -07:00
|
|
|
class CHashSerializer : public CBinarySerializer<CHashSerializerImpl>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-08-23 17:32:42 -07:00
|
|
|
CHashSerializer(const ScriptInterface& scriptInterface);
|
2010-05-25 12:01:30 -07:00
|
|
|
|
|
|
|
|
size_t GetHashLength();
|
|
|
|
|
const u8* ComputeHash();
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
#endif // INCLUDED_HASHSERIALIZER
|