aboutsummaryrefslogtreecommitdiffstats
path: root/src/asn1
diff options
context:
space:
mode:
Diffstat (limited to 'src/asn1')
-rw-r--r--src/asn1/asn1_int.cpp4
-rw-r--r--src/asn1/asn1_oid.cpp2
-rw-r--r--src/asn1/asn1_str.cpp2
-rw-r--r--src/asn1/asn1_tm.cpp47
-rw-r--r--src/asn1/der_enc.cpp2
5 files changed, 33 insertions, 24 deletions
diff --git a/src/asn1/asn1_int.cpp b/src/asn1/asn1_int.cpp
index 5e18f3961..af01d8fa3 100644
--- a/src/asn1/asn1_int.cpp
+++ b/src/asn1/asn1_int.cpp
@@ -20,11 +20,11 @@ BER_Decoding_Error::BER_Decoding_Error(const std::string& str) :
Decoding_Error("BER: " + str) {}
BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) :
- BER_Decoding_Error(str + ": " + to_string(tag)) {}
+ BER_Decoding_Error(str + ": " + std::to_string(tag)) {}
BER_Bad_Tag::BER_Bad_Tag(const std::string& str,
ASN1_Tag tag1, ASN1_Tag tag2) :
- BER_Decoding_Error(str + ": " + to_string(tag1) + "/" + to_string(tag2)) {}
+ BER_Decoding_Error(str + ": " + std::to_string(tag1) + "/" + std::to_string(tag2)) {}
namespace ASN1 {
diff --git a/src/asn1/asn1_oid.cpp b/src/asn1/asn1_oid.cpp
index 531ceb9b2..c72ee7a1a 100644
--- a/src/asn1/asn1_oid.cpp
+++ b/src/asn1/asn1_oid.cpp
@@ -44,7 +44,7 @@ std::string OID::as_string() const
std::string oid_str;
for(u32bit j = 0; j != id.size(); ++j)
{
- oid_str += to_string(id[j]);
+ oid_str += std::to_string(id[j]);
if(j != id.size() - 1)
oid_str += '.';
}
diff --git a/src/asn1/asn1_str.cpp b/src/asn1/asn1_str.cpp
index 25782e239..892a44472 100644
--- a/src/asn1/asn1_str.cpp
+++ b/src/asn1/asn1_str.cpp
@@ -89,7 +89,7 @@ ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : tag(t)
tag != UTF8_STRING &&
tag != BMP_STRING)
throw Invalid_Argument("ASN1_String: Unknown string type " +
- to_string(tag));
+ std::to_string(tag));
}
/*
diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp
index c57d1bc73..9df10f4a3 100644
--- a/src/asn1/asn1_tm.cpp
+++ b/src/asn1/asn1_tm.cpp
@@ -103,11 +103,13 @@ void X509_Time::set_to(const std::string& time_str)
void X509_Time::set_to(const std::string& t_spec, ASN1_Tag tag)
{
if(tag != GENERALIZED_TIME && tag != UTC_TIME)
- throw Invalid_Argument("X509_Time: Invalid tag " + to_string(tag));
+ throw Invalid_Argument("X509_Time: Invalid tag " + std::to_string(tag));
+
if(tag == GENERALIZED_TIME && t_spec.size() != 13 && t_spec.size() != 15)
throw Invalid_Argument("Invalid GeneralizedTime: " + t_spec);
if(tag == UTC_TIME && t_spec.size() != 11 && t_spec.size() != 13)
throw Invalid_Argument("Invalid UTCTime: " + t_spec);
+
if(t_spec[t_spec.size()-1] != 'Z')
throw Invalid_Argument("Invalid time encoding: " + t_spec);
@@ -179,21 +181,30 @@ std::string X509_Time::as_string() const
if(time_is_set() == false)
throw Invalid_State("X509_Time::as_string: No time set");
- std::string asn1rep;
- if(tag == GENERALIZED_TIME)
- asn1rep = to_string(year, 4);
- else
+ u32bit full_year = year;
+
+ if(tag == UTC_TIME)
{
if(year < 1950 || year >= 2050)
throw Encoding_Error("X509_Time: The time " + readable_string() +
" cannot be encoded as a UTCTime");
- u32bit asn1year = (year >= 2000) ? (year - 2000) : (year - 1900);
- asn1rep = to_string(asn1year, 2);
+
+ full_year = (year >= 2000) ? (year - 2000) : (year - 1900);
}
- asn1rep += to_string(month, 2) + to_string(day, 2);
- asn1rep += to_string(hour, 2) + to_string(minute, 2) + to_string(second, 2);
- asn1rep += "Z";
- return asn1rep;
+
+ std::string repr = std::to_string(full_year*10000000000 +
+ month*100000000 +
+ day*1000000 +
+ hour*10000 +
+ minute*100 +
+ second) + "Z";
+
+ u32bit desired_size = (tag == UTC_TIME) ? 13 : 15;
+
+ while(repr.size() < desired_size)
+ repr = "0" + repr;
+
+ return repr;
}
/*
@@ -212,14 +223,12 @@ std::string X509_Time::readable_string() const
if(time_is_set() == false)
throw Invalid_State("X509_Time::readable_string: No time set");
- std::string readable;
- readable += to_string(year, 4) + "/";
- readable += to_string(month ) + "/";
- readable += to_string(day ) + " ";
- readable += to_string(hour ) + ":";
- readable += to_string(minute, 2) + ":";
- readable += to_string(second, 2) + " UTC";
- return readable;
+ std::string output(24, 0);
+
+ std::sprintf(&output[0], "%04d/%02d/%02d %02d:%02d:%02d UTC",
+ year, month, day, hour, minute, second);
+
+ return output;
}
/*
diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp
index bee269431..1863e400d 100644
--- a/src/asn1/der_enc.cpp
+++ b/src/asn1/der_enc.cpp
@@ -24,7 +24,7 @@ SecureVector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if((class_tag | 0xE0) != 0xE0)
throw Encoding_Error("DER_Encoder: Invalid class tag " +
- to_string(class_tag));
+ std::to_string(class_tag));
SecureVector<byte> encoded_tag;
if(type_tag <= 30)