]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sha256.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_sha256.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26 /// $CompilerFlags: -Ivendor_directory("sha2")
27 /// $CompilerFlags: require_compiler("GCC") -Wno-long-long
28
29 #ifdef __GNUC__
30 # pragma GCC diagnostic push
31 #endif
32
33 // Fix warnings about the use of `long long` on C++03.
34 #if defined __clang__
35 # pragma clang diagnostic ignored "-Wc++11-long-long"
36 #elif defined __GNUC__
37 # pragma GCC diagnostic ignored "-Wlong-long"
38 #endif
39
40 #include "inspircd.h"
41 #include "modules/hash.h"
42
43 #include <sha2.c>
44
45 #ifdef __GNUC__
46 # pragma GCC diagnostic pop
47 #endif
48
49 class HashSHA256 : public HashProvider
50 {
51  public:
52         std::string GenerateRaw(const std::string& data) CXX11_OVERRIDE
53         {
54                 unsigned char bytes[SHA256_DIGEST_SIZE];
55                 sha256((unsigned char*)data.data(), data.length(),  bytes);
56                 return std::string((char*)bytes, SHA256_DIGEST_SIZE);
57         }
58
59         HashSHA256(Module* parent)
60                 : HashProvider(parent, "sha256", 32, 64)
61         {
62         }
63 };
64
65 class ModuleSHA256 : public Module
66 {
67         HashSHA256 sha;
68  public:
69         ModuleSHA256() : sha(this)
70         {
71         }
72
73         Version GetVersion() CXX11_OVERRIDE
74         {
75                 return Version("Allows other modules to generate SHA-256 hashes.", VF_VENDOR);
76         }
77 };
78
79 MODULE_INIT(ModuleSHA256)