Botan::X509_Time Class Reference

#include <asn1_obj.h>

Inheritance diagram for Botan::X509_Time:

Botan::ASN1_Object

List of all members.

Public Member Functions

std::string as_string () const
s32bit cmp (const X509_Time &) const
void decode_from (class BER_Decoder &)
void encode_into (class DER_Encoder &) const
std::string readable_string () const
void set_to (const std::string &, ASN1_Tag)
void set_to (const std::string &)
bool time_is_set () const
 X509_Time (const std::string &, ASN1_Tag)
 X509_Time (const std::string &="")
 X509_Time (u64bit)


Detailed Description

X.509 Time

Definition at line 40 of file asn1_obj.h.


Constructor & Destructor Documentation

Botan::X509_Time::X509_Time ( u64bit  timer  ) 

Definition at line 28 of file asn1_tm.cpp.

References Botan::calendar_value(), Botan::calendar_point::day, Botan::GENERALIZED_TIME, Botan::calendar_point::hour, Botan::calendar_point::minutes, Botan::calendar_point::month, Botan::calendar_point::seconds, Botan::UTC_TIME, and Botan::calendar_point::year.

00029    {
00030    calendar_point cal = calendar_value(timer);
00031 
00032    year   = cal.year;
00033    month  = cal.month;
00034    day    = cal.day;
00035    hour   = cal.hour;
00036    minute = cal.minutes;
00037    second = cal.seconds;
00038 
00039    if(year >= 2050)
00040       tag = GENERALIZED_TIME;
00041    else
00042       tag = UTC_TIME;
00043    }

Botan::X509_Time::X509_Time ( const std::string &  time_str = ""  ) 

Definition at line 20 of file asn1_tm.cpp.

References set_to().

00021    {
00022    set_to(time_str);
00023    }

Botan::X509_Time::X509_Time ( const std::string &  t_spec,
ASN1_Tag  t 
)

Definition at line 48 of file asn1_tm.cpp.

References set_to().

00048                                                         : tag(t)
00049    {
00050    set_to(t_spec, tag);
00051    }


Member Function Documentation

std::string Botan::X509_Time::as_string (  )  const

Definition at line 177 of file asn1_tm.cpp.

References Botan::GENERALIZED_TIME, readable_string(), time_is_set(), and Botan::to_string().

Referenced by encode_into().

00178    {
00179    if(time_is_set() == false)
00180       throw Invalid_State("X509_Time::as_string: No time set");
00181 
00182    std::string asn1rep;
00183    if(tag == GENERALIZED_TIME)
00184       asn1rep = to_string(year, 4);
00185    else
00186       {
00187       if(year < 1950 || year >= 2050)
00188          throw Encoding_Error("X509_Time: The time " + readable_string() +
00189                               " cannot be encoded as a UTCTime");
00190       u32bit asn1year = (year >= 2000) ? (year - 2000) : (year - 1900);
00191       asn1rep = to_string(asn1year, 2);
00192       }
00193    asn1rep += to_string(month, 2) + to_string(day, 2);
00194    asn1rep += to_string(hour, 2) + to_string(minute, 2) + to_string(second, 2);
00195    asn1rep += "Z";
00196    return asn1rep;
00197    }

s32bit Botan::X509_Time::cmp ( const X509_Time other  )  const

Definition at line 244 of file asn1_tm.cpp.

References day, hour, minute, month, second, time_is_set(), and year.

Referenced by Botan::operator!=(), Botan::operator<(), Botan::operator<=(), Botan::operator==(), and Botan::operator>=().

00245    {
00246    if(time_is_set() == false)
00247       throw Invalid_State("X509_Time::cmp: No time set");
00248 
00249    const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0;
00250 
00251    if(year < other.year)     return EARLIER;
00252    if(year > other.year)     return LATER;
00253    if(month < other.month)   return EARLIER;
00254    if(month > other.month)   return LATER;
00255    if(day < other.day)       return EARLIER;
00256    if(day > other.day)       return LATER;
00257    if(hour < other.hour)     return EARLIER;
00258    if(hour > other.hour)     return LATER;
00259    if(minute < other.minute) return EARLIER;
00260    if(minute > other.minute) return LATER;
00261    if(second < other.second) return EARLIER;
00262    if(second > other.second) return LATER;
00263 
00264    return SAME_TIME;
00265    }

void Botan::X509_Time::decode_from ( class BER_Decoder from  )  [virtual]

Decode whatever this object is from from

Parameters:
from the BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 166 of file asn1_tm.cpp.

References Botan::BER_Decoder::get_next_object(), Botan::LATIN1_CHARSET, Botan::LOCAL_CHARSET, set_to(), Botan::ASN1::to_string(), Botan::Charset::transcode(), and Botan::BER_Object::type_tag.

00167    {
00168    BER_Object ber_time = source.get_next_object();
00169    set_to(Charset::transcode(ASN1::to_string(ber_time),
00170                              LATIN1_CHARSET, LOCAL_CHARSET),
00171           ber_time.type_tag);
00172    }

void Botan::X509_Time::encode_into ( class DER_Encoder to  )  const [virtual]

Encode whatever this object is into to

Parameters:
to the DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 154 of file asn1_tm.cpp.

References Botan::DER_Encoder::add_object(), as_string(), Botan::GENERALIZED_TIME, Botan::LATIN1_CHARSET, Botan::LOCAL_CHARSET, Botan::Charset::transcode(), Botan::UNIVERSAL, and Botan::UTC_TIME.

00155    {
00156    if(tag != GENERALIZED_TIME && tag != UTC_TIME)
00157       throw Invalid_Argument("X509_Time: Bad encoding tag");
00158    der.add_object(tag, UNIVERSAL,
00159                   Charset::transcode(as_string(),
00160                                      LOCAL_CHARSET, LATIN1_CHARSET));
00161    }

std::string Botan::X509_Time::readable_string (  )  const

Definition at line 210 of file asn1_tm.cpp.

References time_is_set(), and Botan::to_string().

Referenced by as_string().

00211    {
00212    if(time_is_set() == false)
00213       throw Invalid_State("X509_Time::readable_string: No time set");
00214 
00215    std::string readable;
00216    readable += to_string(year,   4) + "/";
00217    readable += to_string(month    ) + "/";
00218    readable += to_string(day      ) + " ";
00219    readable += to_string(hour     ) + ":";
00220    readable += to_string(minute, 2) + ":";
00221    readable += to_string(second, 2) + " UTC";
00222    return readable;
00223    }

void Botan::X509_Time::set_to ( const std::string &  t_spec,
ASN1_Tag  tag 
)

Definition at line 103 of file asn1_tm.cpp.

References Botan::GENERALIZED_TIME, Botan::to_string(), Botan::to_u32bit(), and Botan::UTC_TIME.

00104    {
00105    if(tag != GENERALIZED_TIME && tag != UTC_TIME)
00106       throw Invalid_Argument("X509_Time: Invalid tag " + to_string(tag));
00107    if(tag == GENERALIZED_TIME && t_spec.size() != 13 && t_spec.size() != 15)
00108       throw Invalid_Argument("Invalid GeneralizedTime: " + t_spec);
00109    if(tag == UTC_TIME && t_spec.size() != 11 && t_spec.size() != 13)
00110       throw Invalid_Argument("Invalid UTCTime: " + t_spec);
00111    if(t_spec[t_spec.size()-1] != 'Z')
00112       throw Invalid_Argument("Invalid time encoding: " + t_spec);
00113 
00114    const u32bit YEAR_SIZE = (tag == UTC_TIME) ? 2 : 4;
00115 
00116    std::vector<std::string> params;
00117    std::string current;
00118 
00119    for(u32bit j = 0; j != YEAR_SIZE; ++j)
00120       current += t_spec[j];
00121    params.push_back(current);
00122    current.clear();
00123 
00124    for(u32bit j = YEAR_SIZE; j != t_spec.size() - 1; ++j)
00125       {
00126       current += t_spec[j];
00127       if(current.size() == 2)
00128          {
00129          params.push_back(current);
00130          current.clear();
00131          }
00132       }
00133 
00134    year   = to_u32bit(params[0]);
00135    month  = to_u32bit(params[1]);
00136    day    = to_u32bit(params[2]);
00137    hour   = to_u32bit(params[3]);
00138    minute = to_u32bit(params[4]);
00139    second = (params.size() == 6) ? to_u32bit(params[5]) : 0;
00140 
00141    if(tag == UTC_TIME)
00142       {
00143       if(year >= 50) year += 1900;
00144       else           year += 2000;
00145       }
00146 
00147    if(!passes_sanity_check())
00148       throw Invalid_Argument("Invalid time specification " + t_spec);
00149    }

void Botan::X509_Time::set_to ( const std::string &  time_str  ) 

Definition at line 56 of file asn1_tm.cpp.

References Botan::GENERALIZED_TIME, Botan::Charset::is_digit(), Botan::to_u32bit(), and Botan::UTC_TIME.

Referenced by decode_from(), and X509_Time().

00057    {
00058    if(time_str == "")
00059       {
00060       year = month = day = hour = minute = second = 0;
00061       return;
00062       }
00063 
00064    std::vector<std::string> params;
00065    std::string current;
00066 
00067    for(u32bit j = 0; j != time_str.size(); ++j)
00068       {
00069       if(Charset::is_digit(time_str[j]))
00070          current += time_str[j];
00071       else
00072          {
00073          if(current != "")
00074             params.push_back(current);
00075          current.clear();
00076          }
00077       }
00078    if(current != "")
00079       params.push_back(current);
00080 
00081    if(params.size() < 3 || params.size() > 6)
00082       throw Invalid_Argument("Invalid time specification " + time_str);
00083 
00084    year   = to_u32bit(params[0]);
00085    month  = to_u32bit(params[1]);
00086    day    = to_u32bit(params[2]);
00087    hour   = (params.size() >= 4) ? to_u32bit(params[3]) : 0;
00088    minute = (params.size() >= 5) ? to_u32bit(params[4]) : 0;
00089    second = (params.size() == 6) ? to_u32bit(params[5]) : 0;
00090 
00091    if(year >= 2050)
00092       tag = GENERALIZED_TIME;
00093    else
00094       tag = UTC_TIME;
00095 
00096    if(!passes_sanity_check())
00097       throw Invalid_Argument("Invalid time specification " + time_str);
00098    }

bool Botan::X509_Time::time_is_set (  )  const

Definition at line 202 of file asn1_tm.cpp.

Referenced by as_string(), cmp(), and readable_string().

00203    {
00204    return (year != 0);
00205    }


The documentation for this class was generated from the following files:

Generated on Fri Aug 13 16:21:01 2010 for Botan by  doxygen 1.5.8