Botan  1.11.15
Public Member Functions
Botan::EAC_Time Class Reference

#include <eac_asn_obj.h>

Inheritance diagram for Botan::EAC_Time:
Botan::ASN1_Object Botan::ASN1_Ced Botan::ASN1_Cex

List of all members.

Public Member Functions

void add_months (u32bit months)
void add_years (u32bit years)
std::string as_string () const
s32bit cmp (const EAC_Time &other) const
void decode_from (class BER_Decoder &)
 EAC_Time (const std::chrono::system_clock::time_point &time, ASN1_Tag tag=ASN1_Tag(0))
 EAC_Time (const std::string &yyyy_mm_dd, ASN1_Tag tag=ASN1_Tag(0))
 EAC_Time (u32bit year, u32bit month, u32bit day, ASN1_Tag tag=ASN1_Tag(0))
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
virtual ~EAC_Time ()

Detailed Description

This class represents CVC EAC Time objects. It only models year, month and day. Only limited sanity checks of the inputted date value are performed.

Definition at line 22 of file eac_asn_obj.h.


Constructor & Destructor Documentation

Botan::EAC_Time::EAC_Time ( const std::chrono::system_clock::time_point &  time,
ASN1_Tag  tag = ASN1_Tag(0) 
)

Definition at line 54 of file asn1_eac_tm.cpp.

References Botan::calendar_value(), Botan::calendar_point::day, Botan::calendar_point::month, and Botan::calendar_point::year.

                               : tag(t)
   {
   calendar_point cal = calendar_value(time);

   year   = cal.year;
   month  = cal.month;
   day    = cal.day;
   }
Botan::EAC_Time::EAC_Time ( const std::string &  yyyy_mm_dd,
ASN1_Tag  tag = ASN1_Tag(0) 
)

Definition at line 67 of file asn1_eac_tm.cpp.

References set_to().

                                                      : tag(t)
   {
   set_to(t_spec);
   }
Botan::EAC_Time::EAC_Time ( u32bit  year,
u32bit  month,
u32bit  day,
ASN1_Tag  tag = ASN1_Tag(0) 
)

Definition at line 75 of file asn1_eac_tm.cpp.

                                                           :
   year(y), month(m), day(d), tag(t)
   {
   }
virtual Botan::EAC_Time::~EAC_Time ( ) [inline, virtual]

Definition at line 100 of file eac_asn_obj.h.

{}

Member Function Documentation

Add the specified number of months to this.

Parameters:
monthsthe number of months to add

Definition at line 186 of file asn1_eac_tm.cpp.

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

   {
   year += months/12;
   month += months % 12;
   if(month > 12)
      {
      year += 1;
      month -= 12;
      }
   }

Add the specified number of years to this.

Parameters:
yearsthe number of years to add

Definition at line 181 of file asn1_eac_tm.cpp.

   {
   year += years;
   }
std::string Botan::EAC_Time::as_string ( ) const

Get a this objects value as a string.

Returns:
date string

Definition at line 132 of file asn1_eac_tm.cpp.

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

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

   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::as_string: No time set");

   return std::to_string(year * 10000 + month * 100 + day);
   }
s32bit Botan::EAC_Time::cmp ( const EAC_Time other) const

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 200 of file asn1_eac_tm.cpp.

References time_is_set().

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

   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::cmp: No time set");

   const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0;

   if(year < other.year)     return EARLIER;
   if(year > other.year)     return LATER;
   if(month < other.month)   return EARLIER;
   if(month > other.month)   return LATER;
   if(day < other.day)       return EARLIER;
   if(day > other.day)       return LATER;

   return SAME_TIME;
   }
void Botan::EAC_Time::decode_from ( class BER_Decoder from) [virtual]

Decode whatever this object is from from

Parameters:
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 253 of file asn1_eac_tm.cpp.

References Botan::BER_Decoder::get_next_object(), Botan::BER_Object::type_tag, and Botan::BER_Object::value.

   {
   BER_Object obj = source.get_next_object();

   if(obj.type_tag != this->tag)
      throw BER_Decoding_Error("Tag mismatch when decoding");

   if(obj.value.size() != 6)
      {
      throw Decoding_Error("EAC_Time decoding failed");
      }

   try
      {
      u32bit tmp_year = dec_two_digit(obj.value[0], obj.value[1]);
      u32bit tmp_mon = dec_two_digit(obj.value[2], obj.value[3]);
      u32bit tmp_day = dec_two_digit(obj.value[4], obj.value[5]);
      year = tmp_year + 2000;
      month = tmp_mon;
      day = tmp_day;
      }
   catch (Invalid_Argument)
      {
      throw Decoding_Error("EAC_Time decoding failed");
      }

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

Encode whatever this object is into to

Parameters:
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 123 of file asn1_eac_tm.cpp.

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

   {
   der.add_object(tag, APPLICATION,
                  encoded_eac_time());
   }
u32bit Botan::EAC_Time::get_day ( ) const [inline]

Get the day value of this objects.

Returns:
day value

Definition at line 89 of file eac_asn_obj.h.

{ return day; }
u32bit Botan::EAC_Time::get_month ( ) const [inline]

Get the month value of this objects.

Returns:
month value

Definition at line 83 of file eac_asn_obj.h.

{ return month; }
u32bit Botan::EAC_Time::get_year ( ) const [inline]

Get the year value of this objects.

Returns:
year value

Definition at line 77 of file eac_asn_obj.h.

{ return year; }
std::string Botan::EAC_Time::readable_string ( ) const

Get a this objects value as a readable formatted string.

Returns:
date string

Definition at line 151 of file asn1_eac_tm.cpp.

References time_is_set().

   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::readable_string: No time set");

   std::string output(11, 0);

   std::sprintf(&output[0], "%04d/%02d/%02d", year, month, day);

   return output;
   }
void Botan::EAC_Time::set_to ( const std::string &  str)

Set this' value by a string value.

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

Definition at line 83 of file asn1_eac_tm.cpp.

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

Referenced by EAC_Time().

   {
   if(time_str == "")
      {
      year = month = day = 0;
      return;
      }

   std::vector<std::string> params;
   std::string current;

   for(u32bit j = 0; j != time_str.size(); ++j)
      {
      if(Charset::is_digit(time_str[j]))
         current += time_str[j];
      else
         {
         if(current != "")
            params.push_back(current);
         current.clear();
         }
      }
   if(current != "")
      params.push_back(current);

   if(params.size() != 3)
      throw Invalid_Argument("Invalid time specification " + time_str);

   year   = to_u32bit(params[0]);
   month  = to_u32bit(params[1]);
   day    = to_u32bit(params[2]);

   if(!passes_sanity_check())
      throw Invalid_Argument("Invalid time specification " + time_str);
   }

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

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

Definition at line 143 of file asn1_eac_tm.cpp.

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

   {
   return (year != 0);
   }

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