aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-09 22:28:13 +0000
committerlloyd <[email protected]>2008-11-09 22:28:13 +0000
commit4a98fe659be80c8688e2022aa070456eb2688ad0 (patch)
tree40abf60342b37444bf475fac7319c20f898c1b1c
parent90ef5e309f5fa1772906d65bca7557ac5686114e (diff)
Add a SCAN_Name class that encapsulates operations currently done repeatedly
all over the engine code.
-rw-r--r--src/utils/info.txt2
-rw-r--r--src/utils/scan_name.cpp35
-rw-r--r--src/utils/scan_name.h55
3 files changed, 92 insertions, 0 deletions
diff --git a/src/utils/info.txt b/src/utils/info.txt
index 4999a08e7..99d589d8c 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -33,6 +33,8 @@ mutex.h
parsing.cpp
parsing.h
rotate.h
+scan_name.cpp
+scan_name.h
secmem.h
stl_util.h
types.h
diff --git a/src/utils/scan_name.cpp b/src/utils/scan_name.cpp
new file mode 100644
index 000000000..3590ffd31
--- /dev/null
+++ b/src/utils/scan_name.cpp
@@ -0,0 +1,35 @@
+/**
+SCAN Name Abstraction
+(C) 2008 Jack Lloyd
+*/
+
+#include <botan/scan_name.h>
+#include <botan/parsing.h>
+#include <botan/libstate.h>
+#include <stdexcept>
+
+namespace Botan {
+
+SCAN_Name::SCAN_Name(const std::string& algo_spec)
+ {
+ name = parse_algorithm_name(algo_spec);
+
+ for(u32bit i = 0; i != name.size(); ++i)
+ name[i] = global_state().deref_alias(name[i]);
+ }
+
+std::string SCAN_Name::argument(u32bit i)
+ {
+ if(i > arg_count())
+ throw std::range_error("SCAN_Name::argument");
+ return name[i+1];
+ }
+
+u32bit SCAN_Name::argument_as_u32bit(u32bit i, u32bit def_value)
+ {
+ if(i >= arg_count())
+ return def_value;
+ return to_u32bit(name[i+1]);
+ }
+
+}
diff --git a/src/utils/scan_name.h b/src/utils/scan_name.h
new file mode 100644
index 000000000..37c9ffc1b
--- /dev/null
+++ b/src/utils/scan_name.h
@@ -0,0 +1,55 @@
+/**
+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>
+
+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
+ */
+ SCAN_Name(const std::string& algo_spec);
+
+ /**
+ @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 i which argument
+ @return the ith argument
+ */
+ std::string argument(u32bit i);
+
+ /**
+ @param i which argument
+ @return the ith argument as a u32bit, or a default value
+ */
+ u32bit argument_as_u32bit(u32bit i, u32bit def_value);
+
+ private:
+ std::vector<std::string> name;
+ };
+
+}
+
+#endif