aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/scan_name.h
blob: b01411c942eb4ffabff0b57f6e38e5640820962d (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
SCAN Name Abstraction
(C) 2008 Jack Lloyd
*/

#ifndef BOTAN_SCAN_NAME_H__
#define BOTAN_SCAN_NAME_H__

#include <botan/types.h>
#include <string>
#include <vector>
#include <set>

namespace Botan {

/**
A class encapsulating a SCAN name (similar to JCE conventions)
http://www.users.zetnet.co.uk/hopwood/crypto/scan/
*/
class SCAN_Name
   {
   public:
      /**
      @param algo_spec A SCAN name
      @param providers An optional provider name
      */
      SCAN_Name(const std::string& algo_spec,
                const std::string& providers = "");

      /**
      @return the original input string
      */
      std::string as_string() const { return orig_algo_spec; }

      /**
      @return the provider name (or empty)
      */
      std::string provider() const { return m_provider; }

      /**
      @return the algorithm name
      */
      std::string algo_name() const { return name[0]; }

      /**
      @return the number of arguments
      */
      u32bit arg_count() const { return name.size() - 1; }

      /**
      @param provider a provider name
      @returns if this provider was allowed by the request
      */
      bool provider_allowed(const std::string& provider) const
         {
         return (m_provider == "" || m_provider == provider);
         }

      /**
      @return if the number of arguments is between lower and upper
      */
      bool arg_count_between(u32bit lower, u32bit upper) const
         { return ((arg_count() >= lower) && (arg_count() <= upper)); }

      /**
      @param i which argument
      @return the ith argument
      */
      std::string arg_as_string(u32bit i) const;

      /**
      @param i which argument
      @return the ith argument
      */
      SCAN_Name arg(u32bit i) const;

      /**
      @param i which argument
      @return the ith argument as a u32bit, or a default value
      */
      u32bit arg_as_u32bit(u32bit i, u32bit def_value) const;
   private:
      std::string orig_algo_spec, m_provider;
      std::vector<std::string> name;
   };

}

#endif