8 #include <botan/asn1_obj.h>
9 #include <botan/der_enc.h>
10 #include <botan/ber_dec.h>
11 #include <botan/charset.h>
12 #include <botan/parsing.h>
13 #include <botan/time.h>
57 year = month = day = hour = minute = second = 0;
62 std::vector<std::string> params;
65 for(
size_t j = 0; j != time_str.size(); ++j)
68 current += time_str[j];
72 params.push_back(current);
77 params.push_back(current);
79 if(params.size() < 3 || params.size() > 6)
85 hour = (params.size() >= 4) ?
to_u32bit(params[3]) : 0;
86 minute = (params.size() >= 5) ?
to_u32bit(params[4]) : 0;
87 second = (params.size() == 6) ?
to_u32bit(params[5]) : 0;
91 if(!passes_sanity_check())
103 if(spec_tag ==
GENERALIZED_TIME && t_spec.size() != 13 && t_spec.size() != 15)
106 if(spec_tag ==
UTC_TIME && t_spec.size() != 11 && t_spec.size() != 13)
109 if(t_spec[t_spec.size()-1] !=
'Z')
112 const size_t YEAR_SIZE = (spec_tag ==
UTC_TIME) ? 2 : 4;
114 std::vector<std::string> params;
117 for(
size_t j = 0; j != YEAR_SIZE; ++j)
118 current += t_spec[j];
119 params.push_back(current);
122 for(
size_t j = YEAR_SIZE; j != t_spec.size() - 1; ++j)
124 current += t_spec[j];
125 if(current.size() == 2)
127 params.push_back(current);
137 second = (params.size() == 6) ?
to_u32bit(params[5]) : 0;
142 if(year >= 50) year += 1900;
146 if(!passes_sanity_check())
190 if(year < 1950 || year >= 2050)
192 " cannot be encoded as a UTCTime");
193 u32bit asn1year = (year >= 2000) ? (year - 2000) : (year - 1900);
219 throw Invalid_State(
"X509_Time::readable_string: No time set");
221 std::string readable;
227 readable +=
to_string(second, 2) +
" UTC";
234 bool X509_Time::passes_sanity_check()
const
236 if(year < 1950 || year > 2100)
238 if(month == 0 || month > 12)
240 if(day == 0 || day > 31)
242 if(hour >= 24 || minute > 60 || second > 60)
255 const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0;
257 if(year < other.year)
return EARLIER;
258 if(year > other.year)
return LATER;
259 if(month < other.month)
return EARLIER;
260 if(month > other.month)
return LATER;
261 if(day < other.day)
return EARLIER;
262 if(day > other.day)
return LATER;
263 if(hour < other.hour)
return EARLIER;
264 if(hour > other.hour)
return LATER;
265 if(minute < other.minute)
return EARLIER;
266 if(minute > other.minute)
return LATER;
267 if(second < other.second)
return EARLIER;
268 if(second > other.second)
return LATER;
277 {
return (t1.
cmp(t2) == 0); }
279 {
return (t1.
cmp(t2) != 0); }
282 {
return (t1.
cmp(t2) <= 0); }
284 {
return (t1.
cmp(t2) >= 0); }
287 {
return (t1.
cmp(t2) < 0); }
289 {
return (t1.
cmp(t2) > 0); }
void decode_from(class BER_Decoder &)
bool operator!=(const OctetString &s1, const OctetString &s2)
bool BOTAN_DLL operator>=(const X509_Time &, const X509_Time &)
bool operator==(const OctetString &s1, const OctetString &s2)
void encode_into(class DER_Encoder &) const
std::string as_string() const
std::invalid_argument Invalid_Argument
std::string to_string(const BER_Object &obj)
calendar_point calendar_value(u64bit a_time_t)
unsigned long long u64bit
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
bool BOTAN_DLL operator>(const X509_Time &, const X509_Time &)
s32bit cmp(const X509_Time &) const
BER_Object get_next_object()
void set_to(const std::string &)
bool BOTAN_DLL operator<(const X509_Time &, const X509_Time &)
std::string to_string(u64bit n, size_t min_len)
std::string readable_string() const
bool BOTAN_DLL operator<=(const X509_Time &, const X509_Time &)
u32bit to_u32bit(const std::string &number)
DER_Encoder & add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const byte rep[], size_t length)