diff options
author | lloyd <[email protected]> | 2013-11-29 19:34:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-11-29 19:34:27 +0000 |
commit | 0e7e188973c0361ba77cfeb0eb2bbae1c2e0ea63 (patch) | |
tree | 0fdea0550dd15776639cce8bc8864748a2636e87 /src/asn1 | |
parent | 272daa8314d68a943e3ea46788bdbe3052175171 (diff) |
Remove trailing null byte from X509_Time::to_string
Make invalid tag case report the value
Diffstat (limited to 'src/asn1')
-rw-r--r-- | src/asn1/asn1_time.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/asn1/asn1_time.cpp b/src/asn1/asn1_time.cpp index b1093158c..32f214e53 100644 --- a/src/asn1/asn1_time.cpp +++ b/src/asn1/asn1_time.cpp @@ -97,14 +97,20 @@ void X509_Time::set_to(const std::string& time_str) */ void X509_Time::set_to(const std::string& t_spec, ASN1_Tag spec_tag) { - if(spec_tag != GENERALIZED_TIME && spec_tag != UTC_TIME) - throw Invalid_Argument("X509_Time: Invalid tag " + std::to_string(spec_tag)); - - if(spec_tag == GENERALIZED_TIME && t_spec.size() != 13 && t_spec.size() != 15) - throw Invalid_Argument("Invalid GeneralizedTime: " + t_spec); - - if(spec_tag == UTC_TIME && t_spec.size() != 11 && t_spec.size() != 13) - throw Invalid_Argument("Invalid UTCTime: " + t_spec); + if(spec_tag == GENERALIZED_TIME) + { + if(t_spec.size() != 13 && t_spec.size() != 15) + throw Invalid_Argument("Invalid GeneralizedTime: " + t_spec); + } + else if(spec_tag == UTC_TIME) + { + if(t_spec.size() != 11 && t_spec.size() != 13) + throw Invalid_Argument("Invalid UTCTime: " + t_spec); + } + else + { + throw Invalid_Argument("Invalid time tag " + std::to_string(spec_tag) + " val " + t_spec); + } if(t_spec[t_spec.size()-1] != 'Z') throw Invalid_Argument("Invalid time encoding: " + t_spec); @@ -229,6 +235,8 @@ std::string X509_Time::readable_string() const std::sprintf(&output[0], "%04d/%02d/%02d %02d:%02d:%02d UTC", year, month, day, hour, minute, second); + output.resize(23); // remove trailing null + return output; } |