ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/doc/poddoc/crypto.pod
Revision: 1.1
Committed: Tue Aug 28 17:14:42 2007 UTC (16 years, 9 months ago) by pippijn
Branch: MAIN
CVS Tags: HEAD
Log Message:
added new files

File Contents

# Content
1 =head1 Crypto handlers
2
3 Like with the L<database backends|database.html>, ermyth has modular crypto
4 facilities.
5
6 =head2 Writing a new crypto handler
7
8 Include the interface header
9
10 #include "atheme.h"
11 #include <ermyth/crypto.h>
12
13 Add the mandatory rcsid line
14
15 static char const rcsid[] = "$Id: posix.C,v 1.3 2007-07-21 13:23:20 pippijn Exp $";
16
17 Define the handler
18
19 namespace crypto
20 {
21 struct mycrypt : handler
22 {
23 mycrypt ()
24 {
25 crypto_module_loaded = true;
26 }
27
28 virtual ~mycrypt ()
29 {
30 crypto_module_loaded = false;
31 }
32
33 virtual char const *crypt (char const * const key, char const * const salt);
34 };
35
36 char const *
37 mycrypt::crypt (char const * const key, char const * const salt)
38 {
39 // Our example merely reverses the string as encryption.
40 std::reverse (key, key + strlen (key));
41 return key;
42 }
43 } // namespace crypto
44
45 Register the handler
46
47 #define FACREG_TYPE crypto::mycrypt
48 #define FACREG_TYPE_NAME "mycrypt"
49 #define FACREG_INTERFACE_TYPE crypto::handler
50 #include <ermyth/factory_reg.h>
51
52 =head2 Using the handler
53
54 Now, we can load our crypto handler with the C<crypto> configuration directive:
55
56 crypto "mycrypt";
57
58 Encrypting a string is as simple as invoking C<< crypter->crypt ("somestring", "salt") >>.
59 Our simple crypter doesn't use the salt, it just reverses the string and
60 returns "gnirtsemos".