blob: 2414bf7bc13a926ae73519bf0cd436b0fa21f157 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* Include file for high-level encryption routines.
*
* (C) 2003-2011 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
#include "services.h"
#include "modules.h"
/******************************************************************************/
/**
* Encrypt string `src' of length `len', placing the result in buffer
* `dest' of size `size'. Returns 0 on success, -1 on error.
**/
int enc_encrypt(const Anope::string &src, Anope::string &dest)
{
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnEncrypt, OnEncrypt(src, dest));
if (MOD_RESULT == EVENT_ALLOW)
return 0;
return -1;
}
/**
* Decrypt encrypted string `src' into buffer `dest' of length `len'.
* Returns 1 (not 0) on success, -1 if the encryption algorithm does not
* allow decryption, and -1 if another failure occurred (e.g. destination
* buffer too small).
**/
int enc_decrypt(const Anope::string &src, Anope::string &dest)
{
size_t pos = src.find(':');
if (pos == Anope::string::npos)
{
Log() << "Error: enc_decrypt() called with invalid password string (" << src << ")";
return -1;
}
Anope::string hashm(src.begin(), src.begin() + pos);
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnDecrypt, OnDecrypt(hashm, src, dest));
if (MOD_RESULT == EVENT_ALLOW)
return 1;
return -1;
}
|