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