aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate/scan_name.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-07-21 04:28:09 +0000
committerlloyd <[email protected]>2009-07-21 04:28:09 +0000
commitabcfd1cf4b351f856c2df11ed1cd972a3a5155a9 (patch)
tree7b05ce4f33fe8c1c94d77ce235b4cd6b9bedc3b0 /src/libstate/scan_name.cpp
parentb1fc3ff3fe19152eaf1adbdd9f503dfaf2b8a500 (diff)
parent57d64c1026cfa0fba775d393920aebaa02bf0f56 (diff)
propagate from branch 'net.randombit.botan' (head 95eb8083f5884531e5ca0667388f8a6fb6d05c41)
to branch 'net.randombit.botan.c++0x' (head 56e105e678540c8bcafa4d0198c19a9489fbf8d1)
Diffstat (limited to 'src/libstate/scan_name.cpp')
-rw-r--r--src/libstate/scan_name.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/libstate/scan_name.cpp b/src/libstate/scan_name.cpp
new file mode 100644
index 000000000..4ca6e6d59
--- /dev/null
+++ b/src/libstate/scan_name.cpp
@@ -0,0 +1,75 @@
+/**
+SCAN Name Abstraction
+(C) 2008 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/scan_name.h>
+#include <botan/parsing.h>
+#include <botan/libstate.h>
+#include <botan/exceptn.h>
+#include <stdexcept>
+
+namespace Botan {
+
+namespace {
+
+std::vector<std::string>
+parse_and_deref_aliases(const std::string& algo_spec)
+ {
+ std::vector<std::string> parts = parse_algorithm_name(algo_spec);
+ std::vector<std::string> out;
+
+ for(size_t i = 0; i != parts.size(); ++i)
+ {
+ std::string part_i = global_state().deref_alias(parts[i]);
+
+ if(i == 0 && part_i.find_first_of(",()") != std::string::npos)
+ {
+ std::vector<std::string> parts_i = parse_and_deref_aliases(part_i);
+
+ for(size_t j = 0; j != parts_i.size(); ++j)
+ out.push_back(parts_i[j]);
+ }
+ else
+ out.push_back(part_i);
+ }
+
+ return out;
+ }
+
+}
+
+SCAN_Name::SCAN_Name(const std::string& algo_spec)
+ {
+ orig_algo_spec = algo_spec;
+
+ name = parse_and_deref_aliases(algo_spec);
+
+ if(name.size() == 0)
+ throw Decoding_Error("Bad SCAN name " + algo_spec);
+ }
+
+std::string SCAN_Name::arg(u32bit i) const
+ {
+ if(i >= arg_count())
+ throw std::range_error("SCAN_Name::argument");
+ return name[i+1];
+ }
+
+std::string SCAN_Name::arg(u32bit i, const std::string& def_value) const
+ {
+ if(i >= arg_count())
+ return def_value;
+ return name[i+1];
+ }
+
+u32bit SCAN_Name::arg_as_u32bit(u32bit i, u32bit def_value) const
+ {
+ if(i >= arg_count())
+ return def_value;
+ return to_u32bit(name[i+1]);
+ }
+
+}