aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-10-06 16:03:33 +0000
committerlloyd <[email protected]>2009-10-06 16:03:33 +0000
commitc86253042f0dab70fcf15030b25fcbc1a00dde76 (patch)
tree27159084e5f56768eff838d61ce13c2930c37ed4 /src/libstate
parentf05bf5994ae8955501e2355b63ec35e575125374 (diff)
Extensions to SCAN_Name for dealing with cipher mode names
Diffstat (limited to 'src/libstate')
-rw-r--r--src/libstate/scan_name.cpp46
-rw-r--r--src/libstate/scan_name.h19
2 files changed, 62 insertions, 3 deletions
diff --git a/src/libstate/scan_name.cpp b/src/libstate/scan_name.cpp
index 88992d66e..13792720c 100644
--- a/src/libstate/scan_name.cpp
+++ b/src/libstate/scan_name.cpp
@@ -44,10 +44,50 @@ SCAN_Name::SCAN_Name(const std::string& algo_spec)
{
orig_algo_spec = algo_spec;
- name = parse_and_deref_aliases(algo_spec);
+ try
+ {
+ name = parse_and_deref_aliases(algo_spec);
+ if(name.size() == 0)
+ throw Decoding_Error("Bad SCAN name " + algo_spec);
+ }
+ catch(Invalid_Algorithm_Name)
+ {
+ name.clear();
+ }
+
+ if(name.size() == 0 && algo_spec.find('/') != std::string::npos)
+ {
+ std::vector<std::string> algo_parts = split_on(algo_spec, '/');
+
+ name = parse_and_deref_aliases(algo_parts[0]);
+ if(name.size() == 0)
+ throw Decoding_Error("Bad SCAN name " + algo_spec);
+
+ for(size_t i = 1; i != algo_parts.size(); ++i)
+ mode_str.push_back(algo_parts[i]);
+ }
+ }
- if(name.size() == 0)
- throw Decoding_Error("Bad SCAN name " + algo_spec);
+std::string SCAN_Name::algo_name_and_args() const
+ {
+ std::string out;
+
+ out = name[0];
+
+ if(arg_count())
+ {
+ out += '(';
+ for(u32bit i = 0; i != arg_count(); ++i)
+ {
+ out += arg(i);
+ if(i != arg_count() - 1)
+ out += ',';
+ }
+ out += ')';
+
+ }
+
+ return out;
}
std::string SCAN_Name::arg(u32bit i) const
diff --git a/src/libstate/scan_name.h b/src/libstate/scan_name.h
index b3f2004e2..6dbd67c4f 100644
--- a/src/libstate/scan_name.h
+++ b/src/libstate/scan_name.h
@@ -38,6 +38,11 @@ class SCAN_Name
std::string algo_name() const { return name[0]; }
/**
+ @return the algorithm name plus any arguments
+ */
+ std::string algo_name_and_args() const;
+
+ /**
@return the number of arguments
*/
u32bit arg_count() const { return name.size() - 1; }
@@ -67,9 +72,23 @@ class SCAN_Name
@return the ith argument as a u32bit, or the default value
*/
u32bit arg_as_u32bit(u32bit i, u32bit def_value) const;
+
+ /**
+ @return the cipher mode (if any)
+ */
+ std::string cipher_mode() const
+ { return (mode_str.size() >= 1) ? mode_str[0] : ""; }
+
+ /**
+ @return the cipher mode padding (if any)
+ */
+ std::string cipher_mode_pad() const
+ { return (mode_str.size() >= 2) ? mode_str[1] : ""; }
+
private:
std::string orig_algo_spec;
std::vector<std::string> name;
+ std::vector<std::string> mode_str;
};
}