aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/asn1
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-08-08 18:54:48 +0200
committerSimon Warta <[email protected]>2015-08-11 10:50:14 +0200
commit3b0ab51f41325a20ba0b8113418d9d916d8e2857 (patch)
tree05ffa5624f8aff7d1df750aa3d8416414a1b84e9 /src/lib/asn1
parentee415570876d8d91e99bab7dc7a14209419a93af (diff)
Sometimes we don't know the input format. But it is one of two
Diffstat (limited to 'src/lib/asn1')
-rw-r--r--src/lib/asn1/asn1_obj.h5
-rw-r--r--src/lib/asn1/asn1_time.cpp20
2 files changed, 22 insertions, 3 deletions
diff --git a/src/lib/asn1/asn1_obj.h b/src/lib/asn1/asn1_obj.h
index 46707e23a..f68ef675e 100644
--- a/src/lib/asn1/asn1_obj.h
+++ b/src/lib/asn1/asn1_obj.h
@@ -47,8 +47,9 @@ enum ASN1_Tag {
VISIBLE_STRING = 0x1A,
BMP_STRING = 0x1E,
- UTC_TIME = 0x17,
- GENERALIZED_TIME = 0x18,
+ UTC_TIME = 0x17,
+ GENERALIZED_TIME = 0x18,
+ UTC_OR_GENERALIZED_TIME = 0x19,
NO_OBJECT = 0xFF00,
DIRECTORY_STRING = 0xFF01
diff --git a/src/lib/asn1/asn1_time.cpp b/src/lib/asn1/asn1_time.cpp
index 381a21b2d..b61879b53 100644
--- a/src/lib/asn1/asn1_time.cpp
+++ b/src/lib/asn1/asn1_time.cpp
@@ -141,7 +141,25 @@ s32bit X509_Time::cmp(const X509_Time& other) const
void X509_Time::set_to(const std::string& t_spec, ASN1_Tag spec_tag)
{
- if(spec_tag == GENERALIZED_TIME)
+ if(spec_tag == UTC_OR_GENERALIZED_TIME)
+ {
+ try
+ {
+ set_to(t_spec, GENERALIZED_TIME);
+ return;
+ }
+ catch(Invalid_Argument) {} // Not a generalized time. Continue
+
+ try
+ {
+ set_to(t_spec, UTC_TIME);
+ return;
+ }
+ catch(Invalid_Argument) {} // Not a UTC time. Continue
+
+ throw Invalid_Argument("Time string could not be parsed as GeneralizedTime or UTCTime.");
+ }
+ else if(spec_tag == GENERALIZED_TIME)
{
if(t_spec.size() != 13 && t_spec.size() != 15)
throw Invalid_Argument("Invalid GeneralizedTime string: '" + t_spec + "'");