aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/parsing.h2
-rw-r--r--src/config.cpp28
-rw-r--r--src/parsing.cpp31
3 files changed, 34 insertions, 27 deletions
diff --git a/include/parsing.h b/include/parsing.h
index 9542e330a..aedfd1cbc 100644
--- a/include/parsing.h
+++ b/include/parsing.h
@@ -26,6 +26,8 @@ BOTAN_DLL bool x500_name_cmp(const std::string&, const std::string&);
BOTAN_DLL std::string to_string(u64bit, u32bit = 0);
BOTAN_DLL u32bit to_u32bit(const std::string&);
+BOTAN_DLL u32bit timespec_to_u32bit(const std::string& timespec);
+
/*************************************************
* String/Network Address Conversions *
*************************************************/
diff --git a/src/config.cpp b/src/config.cpp
index d131b2f59..0d4d459b6 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -126,33 +126,7 @@ std::string Config::option(const std::string& key) const
*************************************************/
u32bit Config::option_as_time(const std::string& key) const
{
- const std::string timespec = option(key);
- if(timespec == "")
- return 0;
-
- const char suffix = timespec[timespec.size()-1];
- std::string value = timespec.substr(0, timespec.size()-1);
-
- u32bit scale = 1;
-
- if(Charset::is_digit(suffix))
- value += suffix;
- else if(suffix == 's')
- scale = 1;
- else if(suffix == 'm')
- scale = 60;
- else if(suffix == 'h')
- scale = 60 * 60;
- else if(suffix == 'd')
- scale = 24 * 60 * 60;
- else if(suffix == 'y')
- scale = 365 * 24 * 60 * 60;
- else
- throw Decoding_Error(
- "Config::option_as_time: Unknown time value " + value
- );
-
- return scale * to_u32bit(value);
+ return timespec_to_u32bit(option(key));
}
}
diff --git a/src/parsing.cpp b/src/parsing.cpp
index 59c0e3324..550cd3586 100644
--- a/src/parsing.cpp
+++ b/src/parsing.cpp
@@ -55,6 +55,37 @@ std::string to_string(u64bit n, u32bit min_len)
}
/*************************************************
+* Convert a string into a time duration *
+*************************************************/
+u32bit timespec_to_u32bit(const std::string& timespec)
+ {
+ if(timespec == "")
+ return 0;
+
+ const char suffix = timespec[timespec.size()-1];
+ std::string value = timespec.substr(0, timespec.size()-1);
+
+ u32bit scale = 1;
+
+ if(Charset::is_digit(suffix))
+ value += suffix;
+ else if(suffix == 's')
+ scale = 1;
+ else if(suffix == 'm')
+ scale = 60;
+ else if(suffix == 'h')
+ scale = 60 * 60;
+ else if(suffix == 'd')
+ scale = 24 * 60 * 60;
+ else if(suffix == 'y')
+ scale = 365 * 24 * 60 * 60;
+ else
+ throw Decoding_Error("timespec_to_u32bit: Bad input " + timespec);
+
+ return scale * to_u32bit(value);
+ }
+
+/*************************************************
* Parse a SCAN-style algorithm name *
*************************************************/
std::vector<std::string> parse_algorithm_name(const std::string& namex)