Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
HashSerializer.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_HASHSERIALIZER
19#define INCLUDED_HASHSERIALIZER
20
21#include "maths/MD5.h"
23
24#include <cstddef>
25
26namespace Script { class Interface; }
27
29{
30 // We don't care about cryptographic strength, just about detection of
31 // unintended changes and about performance, so MD5 is an adequate choice
32 typedef MD5 HashFunc;
33
34public:
35 size_t GetHashLength();
36 const std::uint8_t* ComputeHash();
37
38 void Put(const char* /*name*/, const std::uint8_t* data, size_t len)
39 {
40 m_Hash.Update(data, len);
41 }
42
43private:
46};
47
48class CHashSerializer : public CBinarySerializer<CHashSerializerImpl>
49{
50public:
51 CHashSerializer(const Script::Interface& scriptInterface);
52
53 size_t GetHashLength();
54 const std::uint8_t* ComputeHash();
55};
56
57#endif // INCLUDED_HASHSERIALIZER
Serialize to a binary stream.
Definition: BinarySerializer.h:129
Definition: HashSerializer.h:29
void Put(const char *, const std::uint8_t *data, size_t len)
Definition: HashSerializer.h:38
const std::uint8_t * ComputeHash()
Definition: HashSerializer.cpp:46
size_t GetHashLength()
Definition: HashSerializer.cpp:41
HashFunc m_Hash
Definition: HashSerializer.h:44
MD5 HashFunc
Definition: HashSerializer.h:32
std::uint8_t m_HashData[HashFunc::DIGESTSIZE]
Definition: HashSerializer.h:45
Definition: HashSerializer.h:49
CHashSerializer(const Script::Interface &scriptInterface)
Definition: HashSerializer.cpp:26
const std::uint8_t * ComputeHash()
Definition: HashSerializer.cpp:36
size_t GetHashLength()
Definition: HashSerializer.cpp:31
MD5 hashing algorithm.
Definition: MD5.h:30
static const size_t DIGESTSIZE
Definition: MD5.h:32
void Update(const std::uint8_t *data, size_t len)
Definition: MD5.h:36
Definition: Interface.h:93
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32