Botan::ASN1_Ced Class Reference

#include <eac_asn_obj.h>

Inheritance diagram for Botan::ASN1_Ced:

Botan::EAC_Time Botan::ASN1_Object

List of all members.

Public Member Functions

void add_months (u32bit months)
void add_years (u32bit years)
std::string as_string () const
 ASN1_Ced (EAC_Time const &other)
 ASN1_Ced (u64bit time)
 ASN1_Ced (std::string const &str="")
s32bit cmp (const EAC_Time &other) const
void decode_from (class BER_Decoder &)
void encode_into (class DER_Encoder &) const
u32bit get_day () const
u32bit get_month () const
u32bit get_year () const
std::string readable_string () const
void set_to (const std::string &str)
bool time_is_set () const


Detailed Description

This class represents CVC CEDs. Only limited sanity checks of the inputted date value are performed.

Definition at line 108 of file eac_asn_obj.h.


Constructor & Destructor Documentation

Botan::ASN1_Ced::ASN1_Ced ( std::string const &  str = ""  ) 

Construct a CED from a string value.

Parameters:
str a string in the format "yyyy mm dd", e.g. "2007 08 01"

Definition at line 309 of file asn1_eac_tm.cpp.

00310    : EAC_Time(str, ASN1_Tag(37))
00311    {}

Botan::ASN1_Ced::ASN1_Ced ( u64bit  time  ) 

Construct a CED from a timer value.

Parameters:
time the number of seconds elapsed midnight, 1st January 1970 GMT (or 7pm, 31st December 1969 EST) up to the desired date

Definition at line 313 of file asn1_eac_tm.cpp.

00314    : EAC_Time(val, ASN1_Tag(37))
00315    {}

Botan::ASN1_Ced::ASN1_Ced ( EAC_Time const &  other  ) 

Copy constructor (for general EAC_Time objects).

Parameters:
other the object to copy from

Definition at line 317 of file asn1_eac_tm.cpp.

00318    : EAC_Time(other.get_year(), other.get_month(), other.get_day(), ASN1_Tag(37))
00319    {}


Member Function Documentation

void Botan::EAC_Time::add_months ( u32bit  months  )  [inherited]

Add the specified number of months to this.

Parameters:
months the number of months to add

Definition at line 193 of file asn1_eac_tm.cpp.

Referenced by Botan::DE_EAC::create_cvca(), and Botan::DE_EAC::sign_request().

00194    {
00195    year += months/12;
00196    month += months % 12;
00197    if(month > 12)
00198       {
00199       year += 1;
00200       month -= 12;
00201       }
00202    }

void Botan::EAC_Time::add_years ( u32bit  years  )  [inherited]

Add the specified number of years to this.

Parameters:
years the number of years to add

Definition at line 189 of file asn1_eac_tm.cpp.

00190    {
00191    year += years;
00192    }

std::string Botan::EAC_Time::as_string (  )  const [inherited]

Get a this objects value as a string.

Returns:
date string

Definition at line 133 of file asn1_eac_tm.cpp.

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

Referenced by Botan::DE_EAC::link_cvca().

00134    {
00135    if (time_is_set() == false)
00136       throw Invalid_State("EAC_Time::as_string: No time set");
00137 
00138    std::string asn1rep;
00139    asn1rep = to_string(year, 2);
00140 
00141    asn1rep += to_string(month, 2) + to_string(day, 2);
00142 
00143    return asn1rep;
00144    }

s32bit Botan::EAC_Time::cmp ( const EAC_Time other  )  const [inherited]

Compare this to another EAC_Time object.

Returns:
-1 if this object's date is earlier than other, +1 in the opposite case, and 0 if both dates are equal.

Definition at line 208 of file asn1_eac_tm.cpp.

References Botan::EAC_Time::day, Botan::EAC_Time::month, Botan::EAC_Time::time_is_set(), and Botan::EAC_Time::year.

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

00209    {
00210    if (time_is_set() == false)
00211       throw Invalid_State("EAC_Time::cmp: No time set");
00212 
00213    const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0;
00214 
00215    if (year < other.year)     return EARLIER;
00216    if (year > other.year)     return LATER;
00217    if (month < other.month)   return EARLIER;
00218    if (month > other.month)   return LATER;
00219    if (day < other.day)       return EARLIER;
00220    if (day > other.day)       return LATER;
00221 
00222    return SAME_TIME;
00223    }

void Botan::EAC_Time::decode_from ( class BER_Decoder from  )  [virtual, inherited]

Decode whatever this object is from from

Parameters:
from the BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 256 of file asn1_eac_tm.cpp.

References Botan::BER_Decoder::get_next_object(), Botan::MemoryRegion< T >::size(), Botan::BER_Object::type_tag, and Botan::BER_Object::value.

00257    {
00258    BER_Object obj = source.get_next_object();
00259 
00260    if(obj.type_tag != this->tag)
00261       throw BER_Decoding_Error("Tag mismatch when decoding");
00262 
00263    if(obj.value.size() != 6)
00264       {
00265       throw Decoding_Error("EAC_Time decoding failed");
00266       }
00267 
00268    try
00269       {
00270       u32bit tmp_year = dec_two_digit(obj.value[0], obj.value[1]);
00271       u32bit tmp_mon = dec_two_digit(obj.value[2], obj.value[3]);
00272       u32bit tmp_day = dec_two_digit(obj.value[4], obj.value[5]);
00273       year = tmp_year + 2000;
00274       month = tmp_mon;
00275       day = tmp_day;
00276       }
00277    catch (Invalid_Argument)
00278       {
00279       throw Decoding_Error("EAC_Time decoding failed");
00280       }
00281 
00282    }

void Botan::EAC_Time::encode_into ( class DER_Encoder to  )  const [virtual, inherited]

Encode whatever this object is into to

Parameters:
to the DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 124 of file asn1_eac_tm.cpp.

References Botan::DER_Encoder::add_object(), and Botan::APPLICATION.

00125    {
00126    der.add_object(tag, APPLICATION,
00127                   encoded_eac_time());
00128    }

u32bit Botan::EAC_Time::get_day (  )  const [inherited]

Get the day value of this objects.

Returns:
day value

Definition at line 292 of file asn1_eac_tm.cpp.

00293    {
00294    return day;
00295    }

u32bit Botan::EAC_Time::get_month (  )  const [inherited]

Get the month value of this objects.

Returns:
month value

Definition at line 288 of file asn1_eac_tm.cpp.

00289    {
00290    return month;
00291    }

u32bit Botan::EAC_Time::get_year (  )  const [inherited]

Get the year value of this objects.

Returns:
year value

Definition at line 284 of file asn1_eac_tm.cpp.

00285    {
00286    return year;
00287    }

std::string Botan::EAC_Time::readable_string (  )  const [inherited]

Get a this objects value as a readable formatted string.

Returns:
date string

Definition at line 157 of file asn1_eac_tm.cpp.

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

00158    {
00159    if (time_is_set() == false)
00160       throw Invalid_State("EAC_Time::readable_string: No time set");
00161 
00162    std::string readable;
00163    readable += to_string(year,     2) + "/";
00164    readable += to_string(month,    2) + "/";
00165    readable += to_string(day,      2) + " ";
00166 
00167    return readable;
00168    }

void Botan::EAC_Time::set_to ( const std::string &  str  )  [inherited]

Set this' value by a string value.

Parameters:
str a string in the format "yyyy mm dd", e.g. "2007 08 01"

Definition at line 84 of file asn1_eac_tm.cpp.

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

Referenced by Botan::EAC_Time::EAC_Time().

00085    {
00086    if (time_str == "")
00087       {
00088       year = month = day = 0;
00089       return;
00090       }
00091 
00092    std::vector<std::string> params;
00093    std::string current;
00094 
00095    for (u32bit j = 0; j != time_str.size(); ++j)
00096       {
00097       if (Charset::is_digit(time_str[j]))
00098          current += time_str[j];
00099       else
00100          {
00101          if (current != "")
00102             params.push_back(current);
00103          current.clear();
00104          }
00105       }
00106    if (current != "")
00107       params.push_back(current);
00108 
00109    if (params.size() != 3)
00110       throw Invalid_Argument("Invalid time specification " + time_str);
00111 
00112    year   = to_u32bit(params[0]);
00113    month  = to_u32bit(params[1]);
00114    day    = to_u32bit(params[2]);
00115 
00116    if (!passes_sanity_check())
00117       throw Invalid_Argument("Invalid time specification " + time_str);
00118    }

bool Botan::EAC_Time::time_is_set (  )  const [inherited]

Find out whether this object's values have been set.

Returns:
true if this object's internal values are set

Definition at line 149 of file asn1_eac_tm.cpp.

Referenced by Botan::EAC_Time::as_string(), Botan::EAC_Time::cmp(), and Botan::EAC_Time::readable_string().

00150    {
00151    return (year != 0);
00152    }


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

Generated on Tue Jun 29 08:56:41 2010 for Botan by  doxygen 1.5.8