aboutsummaryrefslogtreecommitdiffstats
path: root/src/algo_base/key_spec.h
blob: 7788bb98859f3daf372928988ae4a6938f368b45 (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
53
54
55
56
57
58
59
60
61
62
/*
* Symmetric Key Length Specification
* (C) 2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_KEY_LEN_SPECIFICATION_H__
#define BOTAN_KEY_LEN_SPECIFICATION_H__

#include <botan/types.h>

namespace Botan {

class BOTAN_DLL Key_Length_Specification
   {
   public:
      Key_Length_Specification(size_t keylen) :
         min_keylen(keylen),
         max_keylen(keylen),
         keylen_mod(1)
         {
         }

      Key_Length_Specification(size_t min_k,
                               size_t max_k,
                               size_t k_mod = 1) :
         min_keylen(min_k),
         max_keylen(max_k ? max_k : min_k),
         keylen_mod(k_mod)
         {
         }

      bool valid_keylength(size_t length) const
         {
         return ((length >= min_keylen) &&
                 (length <= max_keylen) &&
                 (length % keylen_mod == 0));
         }

      size_t minimum_keylength() const
         {
         return min_keylen;
         }

      size_t maximum_keylength() const
         {
         return max_keylen;
         }

      size_t keylength_multiple() const
         {
         return keylen_mod;
         }

   private:
      size_t min_keylen, max_keylen, keylen_mod;
   };

}

#endif