Botan  1.11.15
Public Member Functions
Botan::ASN1_Cex Class Reference

#include <eac_asn_obj.h>

Inheritance diagram for Botan::ASN1_Cex:
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_Cex (const std::string &str="")
 ASN1_Cex (const std::chrono::system_clock::time_point &time)
 ASN1_Cex (const EAC_Time &other)
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 CEXs. Only limited sanity checks of the inputted date value are performed.

Definition at line 143 of file eac_asn_obj.h.


Constructor & Destructor Documentation

Botan::ASN1_Cex::ASN1_Cex ( const std::string &  str = "") [inline]

Construct a CEX from a string value.

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

Definition at line 151 of file eac_asn_obj.h.

                                          :
         EAC_Time(str, ASN1_Tag(36)) {}
Botan::ASN1_Cex::ASN1_Cex ( const std::chrono::system_clock::time_point &  time) [inline]

Definition at line 154 of file eac_asn_obj.h.

                                                            :
         EAC_Time(time, ASN1_Tag(36)) {}
Botan::ASN1_Cex::ASN1_Cex ( const EAC_Time other) [inline]

Definition at line 157 of file eac_asn_obj.h.

                                      :
         EAC_Time(other.get_year(), other.get_month(), other.get_day(),
                  ASN1_Tag(36))
         {}

Member Function Documentation

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

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;
      }
   }
void Botan::EAC_Time::add_years ( u32bit  years) [inherited]

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 [inherited]

Get a this objects value as a string.

Returns:
date string

Definition at line 132 of file asn1_eac_tm.cpp.

References Botan::EAC_Time::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 [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 200 of file asn1_eac_tm.cpp.

References Botan::EAC_Time::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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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 [inherited]

Get a this objects value as a readable formatted string.

Returns:
date string

Definition at line 151 of file asn1_eac_tm.cpp.

References Botan::EAC_Time::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) [inherited]

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 Botan::EAC_Time::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);
   }
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 143 of file asn1_eac_tm.cpp.

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

   {
   return (year != 0);
   }

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