Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

key_filt.h
Go to the documentation of this file.
1 /*
2 * Keyed_Filter
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_KEYED_FILTER_H__
9 #define BOTAN_KEYED_FILTER_H__
10
11 #include <botan/filter.h>
12 #include <botan/cipher_mode.h>
13 #include <botan/sym_algo.h>
14
15 namespace Botan {
16
17 /**
18 * This class represents keyed filters, i.e. filters that have to be
19 * fed with a key in order to function.
20 */
21 class BOTAN_DLL Keyed_Filter : public Filter
22 {
23 public:
24 /**
25 * Set the key of this filter
26 * @param key the key to use
27 */
28 virtual void set_key(const SymmetricKey& key) = 0;
29
30 /**
31 * Set the initialization vector of this filter. Note: you should
32 * call set_iv() only after you have called set_key()
33 * @param iv the initialization vector to use
34 */
35 virtual void set_iv(const InitializationVector& iv);
36
37 /**
38 * Check whether a key length is valid for this filter
39 * @param length the key length to be checked for validity
40 * @return true if the key length is valid, false otherwise
41 */
42 bool valid_keylength(size_t length) const
43 {
44 return key_spec().valid_keylength(length);
45 }
46
47 /**
48 * @return object describing limits on key size
49 */
50 virtual Key_Length_Specification key_spec() const = 0;
51
52 /**
53 * Check whether an IV length is valid for this filter
54 * @param length the IV length to be checked for validity
55 * @return true if the IV length is valid, false otherwise
56 */
57 virtual bool valid_iv_length(size_t length) const
58 { return (length == 0); }
59 };
60
61
62
63 /*
64 * Get a cipher object
65 */
66
67 /**
68 * Factory method for general symmetric cipher filters.
69 * @param algo_spec the name of the desired cipher
70 * @param key the key to be used for encryption/decryption performed by
71 * the filter
72 * @param iv the initialization vector to be used
73 * @param direction determines whether the filter will be an encrypting
74 * or decrypting filter
75 * @return pointer to newly allocated encryption or decryption filter
76 */
77 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec,
78 const SymmetricKey& key,
79 const InitializationVector& iv,
80 Cipher_Dir direction);
81
82 /**
83 * Factory method for general symmetric cipher filters.
84 * @param algo_spec the name of the desired cipher
85 * @param key the key to be used for encryption/decryption performed by
86 * the filter
87 * @param direction determines whether the filter will be an encrypting
88 * or decrypting filter
89 * @return pointer to the encryption or decryption filter
90 */
91 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec,
92 const SymmetricKey& key,
93 Cipher_Dir direction);
94
95 /**
96 * Factory method for general symmetric cipher filters. No key will be
97 * set in the filter.
98 *
99 * @param algo_spec the name of the desired cipher
100 * @param direction determines whether the filter will be an encrypting or
101 * decrypting filter
102 * @return pointer to the encryption or decryption filter
103 */
104 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec,
105 Cipher_Dir direction);
106
107 }
108
109 #endif
Botan::InitializationVector
OctetString InitializationVector
Definition: symkey.h:141
Botan::OctetString
Definition: symkey.h:19
Botan::Keyed_Filter
Definition: key_filt.h:21
Botan::Key_Length_Specification
Definition: key_spec.h:18
Botan::Filter
Definition: filter.h:21
Botan::Keyed_Filter::valid_iv_length
virtual bool valid_iv_length(size_t length) const
Definition: key_filt.h:57
Botan
Definition: alg_id.cpp:13
Botan::SymmetricKey
OctetString SymmetricKey
Definition: symkey.h:136
Botan::Keyed_Filter::valid_keylength
bool valid_keylength(size_t length) const
Definition: key_filt.h:42
Botan::Cipher_Dir
Cipher_Dir
Definition: cipher_mode.h:212
Botan::get_cipher
Keyed_Filter * get_cipher(const std::string &algo_spec, Cipher_Dir direction)
Definition: key_filt.cpp:12