Line data Source code
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" 22 : #include "simulation2/serialization/BinarySerializer.h" 23 : 24 : #include <cstddef> 25 : 26 : namespace Script { class Interface; } 27 : 28 22 : class CHashSerializerImpl 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 : 34 : public: 35 : size_t GetHashLength(); 36 : const std::uint8_t* ComputeHash(); 37 : 38 431007 : void Put(const char* /*name*/, const std::uint8_t* data, size_t len) 39 : { 40 431007 : m_Hash.Update(data, len); 41 0 : } 42 : 43 : private: 44 : HashFunc m_Hash; 45 : std::uint8_t m_HashData[HashFunc::DIGESTSIZE]; 46 : }; 47 : 48 22 : class CHashSerializer : public CBinarySerializer<CHashSerializerImpl> 49 : { 50 : public: 51 : CHashSerializer(const Script::Interface& scriptInterface); 52 : 53 : size_t GetHashLength(); 54 : const std::uint8_t* ComputeHash(); 55 : }; 56 : 57 : #endif // INCLUDED_HASHSERIALIZER