Debian Codegraph @

src/lib/crypto/CryptoFactory.cpp

raw
1 /*
2 * Copyright (c) 2010 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 CryptoFactory.cpp
29
30 This class is a factory for all cryptographic algorithm implementations. It
31 is an abstract base class for a factory that produces cryptographic library
32 specific implementations of cryptographic algorithms.
33 *****************************************************************************/
34
35 #include "config.h"
36 #include "CryptoFactory.h"
37
38 #if defined(WITH_OPENSSL)
39
40 #include "OSSLCryptoFactory.h"
41
42 // Return the one-and-only instance
43 CryptoFactory* CryptoFactory::i()
44 {
45 return OSSLCryptoFactory::i();
46 }
47
48 // This will destroy the one-and-only instance.
49 void CryptoFactory::reset()
50 {
51 OSSLCryptoFactory::reset();
52 }
53
54 #elif defined(WITH_BOTAN)
55
56 #include "BotanCryptoFactory.h"
57
58 // Return the one-and-only instance
59 CryptoFactory* CryptoFactory::i()
60 {
61 return BotanCryptoFactory::i();
62 }
63
64 // This will destroy the one-and-only instance.
65 void CryptoFactory::reset()
66 {
67 BotanCryptoFactory::reset();
68 }
69
70 #else
71
72 #error "You must configure a cryptographic library to use"
73
74 #endif
75
76 // Recycle a symmetric algorithm instance -- override this function in the derived
77 // class if you need to perform specific clean-up
78 void CryptoFactory::recycleSymmetricAlgorithm(SymmetricAlgorithm* toRecycle)
79 {
80 delete toRecycle;
81 }
82
83 // Recycle an asymmetric algorithm instance -- override this function in the derived
84 // class if you need to perform specific clean-up
85 void CryptoFactory::recycleAsymmetricAlgorithm(AsymmetricAlgorithm* toRecycle)
86 {
87 delete toRecycle;
88 }
89
90 // Recycle a hash algorithm instance -- override this function in the derived
91 // class if you need to perform specific clean-up
92 void CryptoFactory::recycleHashAlgorithm(HashAlgorithm* toRecycle)
93 {
94 delete toRecycle;
95 }
96
97 // Recycle a MAC algorithm instance -- override this function in the derived
98 // class if you need to perform specific clean-up
99 void CryptoFactory::recycleMacAlgorithm(MacAlgorithm* toRecycle)
100 {
101 delete toRecycle;
102 }