aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-09-17 14:14:19 +0000
committerlloyd <[email protected]>2009-09-17 14:14:19 +0000
commitd5c7febf558af0f7a6f0edf3595d55fe04dce0f5 (patch)
treee9900a753bd2945d94c7c5bc9d7fffc1aa51bfed
parent9a13eb0a34fad9dc78e88970233020a5c0bdb4ed (diff)
parent7e839d037119055b572f40ce0cd882f85583db2e (diff)
propagate from branch 'net.randombit.botan' (head b9ca6596a127964cb9795d22bc2a5642fab5de84)
to branch 'net.randombit.botan.c++0x' (head 3c769a81bd357a14f8aca4502b67e8465cee0947)
-rw-r--r--doc/examples/bench.cpp3
-rw-r--r--src/asn1/asn1_tm.cpp22
-rw-r--r--src/cert/cvc/asn1_eac_tm.cpp59
-rw-r--r--src/cert/x509/x509opt.cpp1
-rw-r--r--src/timer/timer.cpp13
-rw-r--r--src/timer/timer.h5
6 files changed, 37 insertions, 66 deletions
diff --git a/doc/examples/bench.cpp b/doc/examples/bench.cpp
index 7d53e0557..db2170dc4 100644
--- a/doc/examples/bench.cpp
+++ b/doc/examples/bench.cpp
@@ -60,7 +60,8 @@ const std::string algos[] = {
"",
};
-int main()
+void benchmark_algo(const std::string& algo,
+ RandomNumberGenerator& rng)
{
LibraryInitializer init;
diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp
index f85ea128b..09bc4d347 100644
--- a/src/asn1/asn1_tm.cpp
+++ b/src/asn1/asn1_tm.cpp
@@ -10,28 +10,10 @@
#include <botan/ber_dec.h>
#include <botan/charset.h>
#include <botan/parsing.h>
-#include <ctime>
+#include <botan/timer.h>
namespace Botan {
-namespace {
-
-/*
-* Convert a time_t to a struct tm
-*/
-std::tm get_tm(u64bit timer)
- {
- std::time_t time_val = static_cast<std::time_t>(timer);
-
- std::tm* tm_p = std::gmtime(&time_val);
- if(tm_p == 0)
- throw Encoding_Error("X509_Time: gmtime could not encode " +
- to_string(timer));
- return (*tm_p);
- }
-
-}
-
/*
* Create an X509_Time
*/
@@ -45,7 +27,7 @@ X509_Time::X509_Time(const std::string& time_str)
*/
X509_Time::X509_Time(u64bit timer)
{
- std::tm time_info = get_tm(timer);
+ std::tm time_info = time_t_to_tm(timer);
year = time_info.tm_year + 1900;
month = time_info.tm_mon + 1;
diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp
index 05533b520..947b9e66d 100644
--- a/src/cert/cvc/asn1_eac_tm.cpp
+++ b/src/cert/cvc/asn1_eac_tm.cpp
@@ -11,53 +11,39 @@
#include <botan/ber_dec.h>
#include <botan/charset.h>
#include <botan/parsing.h>
-#include <ctime>
-#include <sstream>
+#include <botan/rounding.h>
+#include <botan/timer.h>
namespace Botan {
namespace {
-/*
-* Convert a time_t to a struct tm
-*/
-std::tm get_tm(u64bit timer)
- {
- std::time_t time_val = static_cast<std::time_t>(timer);
-
- std::tm* tm_p = std::gmtime(&time_val);
- if (tm_p == 0)
- throw Encoding_Error("EAC_Time: gmtime could not encode " +
- to_string(timer));
- return (*tm_p);
- }
SecureVector<byte> enc_two_digit(u32bit in)
{
SecureVector<byte> result;
in %= 100;
if (in < 10)
- {
result.append(0x00);
- }
else
{
- u32bit y_first_pos = (in - (in%10))/10;
+ u32bit y_first_pos = round_down(in, 10) / 10;
result.append(static_cast<byte>(y_first_pos));
}
- u32bit y_sec_pos = in%10;
+
+ u32bit y_sec_pos = in % 10;
result.append(static_cast<byte>(y_sec_pos));
return result;
}
+
u32bit dec_two_digit(byte b1, byte b2)
{
u32bit upper = (u32bit)b1;
u32bit lower = (u32bit)b2;
- if (upper > 9 || lower > 9)
- {
- throw Invalid_Argument("u32bit dec_two_digit(byte b1, byte b2): value too large");
- }
- return upper*10 + lower;
+ if(upper > 9 || lower > 9)
+ throw Invalid_Argument("CVC dec_two_digit value too large");
+
+ return upper*10 + lower;
}
}
@@ -67,12 +53,11 @@ u32bit dec_two_digit(byte b1, byte b2)
EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t)
:tag(t)
{
- std::tm time_info = get_tm(timer);
+ std::tm time_info = time_t_to_tm(timer);
year = time_info.tm_year + 1900;
month = time_info.tm_mon + 1;
day = time_info.tm_mday;
-
}
/*
@@ -272,27 +257,15 @@ bool operator<(const EAC_Time& t1, const EAC_Time& t2)
void EAC_Time::decode_from(BER_Decoder& source)
{
BER_Object obj = source.get_next_object();
- if (obj.type_tag != this->tag)
- {
- std::string message("decoding type mismatch for EAC_Time, tag is ");
- std::stringstream ss;
- std::string str_is;
- ss << std::hex << obj.type_tag;
- ss >> str_is;
- message.append(str_is);
- message.append(", while it should be ");
- std::stringstream ss2;
- std::string str_should;
- ss2 << std::hex << this->tag;
- ss2 >> str_should;
- message.append(str_should);
- throw Decoding_Error(message);
- }
- if (obj.value.size() != 6)
+ if(obj.type_tag != this->tag)
+ throw BER_Decoding_Error("Tag mismatch when decoding");
+
+ if(obj.value.size() != 6)
{
throw Decoding_Error("EAC_Time decoding failed");
}
+
try
{
u32bit tmp_year = dec_two_digit(obj.value[0], obj.value[1]);
diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp
index 988ab2cfa..03bcd20f4 100644
--- a/src/cert/x509/x509opt.cpp
+++ b/src/cert/x509/x509opt.cpp
@@ -9,7 +9,6 @@
#include <botan/oids.h>
#include <botan/parsing.h>
#include <botan/timer.h>
-#include <ctime>
namespace Botan {
diff --git a/src/timer/timer.cpp b/src/timer/timer.cpp
index e3e3c5a16..16d7dc368 100644
--- a/src/timer/timer.cpp
+++ b/src/timer/timer.cpp
@@ -19,6 +19,19 @@ u64bit system_time()
return static_cast<u64bit>(std::time(0));
}
+/*
+* Convert a time_t to a struct tm
+*/
+std::tm time_t_to_tm(u64bit timer)
+ {
+ std::time_t time_val = static_cast<std::time_t>(timer);
+
+ std::tm* tm_p = std::gmtime(&time_val);
+ if (tm_p == 0)
+ throw Encoding_Error("time_t_to_tm could not convert");
+ return (*tm_p);
+ }
+
/**
* Read the clock and return the output
*/
diff --git a/src/timer/timer.h b/src/timer/timer.h
index 3bbe85a5e..603027f6d 100644
--- a/src/timer/timer.h
+++ b/src/timer/timer.h
@@ -9,14 +9,17 @@
#define BOTAN_TIMERS_H__
#include <botan/rng.h>
+#include <ctime>
namespace Botan {
/*
-* Time Access Functions
+* Time Access/Conversion Functions
*/
BOTAN_DLL u64bit system_time();
+BOTAN_DLL std::tm time_t_to_tm(u64bit);
+
/**
* Timer Interface
*/