Botan  1.10.9
Public Member Functions | List of all members
Botan::ASN1_Cex Class Reference

#include <eac_asn_obj.h>

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

Public Member Functions

void add_months (u32bit months)
 
void add_years (u32bit years)
 
std::string as_string () const
 
 ASN1_Cex (std::string const &str="")
 
 ASN1_Cex (u64bit time)
 
 ASN1_Cex (EAC_Time const &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 139 of file eac_asn_obj.h.

Constructor & Destructor Documentation

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

Construct a CED from a string value.

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

Definition at line 328 of file asn1_eac_tm.cpp.

328  :
329  EAC_Time(str, ASN1_Tag(36))
330  {}
EAC_Time(u64bit, ASN1_Tag t=ASN1_Tag(0))
Definition: asn1_eac_tm.cpp:54
ASN1_Tag
Definition: asn1_int.h:19
Botan::ASN1_Cex::ASN1_Cex ( u64bit  time)

Construct a CED from a timer value.

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

Definition at line 332 of file asn1_eac_tm.cpp.

332  :
333  EAC_Time(val, ASN1_Tag(36))
334  {}
EAC_Time(u64bit, ASN1_Tag t=ASN1_Tag(0))
Definition: asn1_eac_tm.cpp:54
ASN1_Tag
Definition: asn1_int.h:19
Botan::ASN1_Cex::ASN1_Cex ( EAC_Time const &  other)

Copy constructor (for general EAC_Time objects).

Parameters
otherthe object to copy from

Definition at line 336 of file asn1_eac_tm.cpp.

336  :
337  EAC_Time(other.get_year(),
338  other.get_month(),
339  other.get_day(),
340  ASN1_Tag(36))
341  {}
EAC_Time(u64bit, ASN1_Tag t=ASN1_Tag(0))
Definition: asn1_eac_tm.cpp:54
ASN1_Tag
Definition: asn1_int.h:19

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

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

191  {
192  year += months/12;
193  month += months % 12;
194  if(month > 12)
195  {
196  year += 1;
197  month -= 12;
198  }
199  }
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 186 of file asn1_eac_tm.cpp.

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

Get a this objects value as a string.

Returns
date string

Definition at line 130 of file asn1_eac_tm.cpp.

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

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

131  {
132  if (time_is_set() == false)
133  throw Invalid_State("EAC_Time::as_string: No time set");
134 
135  std::string asn1rep;
136  asn1rep = to_string(year, 2);
137 
138  asn1rep += to_string(month, 2) + to_string(day, 2);
139 
140  return asn1rep;
141  }
bool time_is_set() const
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
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 205 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>=().

206  {
207  if (time_is_set() == false)
208  throw Invalid_State("EAC_Time::cmp: No time set");
209 
210  const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0;
211 
212  if (year < other.year) return EARLIER;
213  if (year > other.year) return LATER;
214  if (month < other.month) return EARLIER;
215  if (month > other.month) return LATER;
216  if (day < other.day) return EARLIER;
217  if (day > other.day) return LATER;
218 
219  return SAME_TIME;
220  }
bool time_is_set() const
signed int s32bit
Definition: types.h:37
void Botan::EAC_Time::decode_from ( class BER_Decoder from)
virtualinherited

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 258 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.

259  {
260  BER_Object obj = source.get_next_object();
261 
262  if(obj.type_tag != this->tag)
263  throw BER_Decoding_Error("Tag mismatch when decoding");
264 
265  if(obj.value.size() != 6)
266  {
267  throw Decoding_Error("EAC_Time decoding failed");
268  }
269 
270  try
271  {
272  u32bit tmp_year = dec_two_digit(obj.value[0], obj.value[1]);
273  u32bit tmp_mon = dec_two_digit(obj.value[2], obj.value[3]);
274  u32bit tmp_day = dec_two_digit(obj.value[4], obj.value[5]);
275  year = tmp_year + 2000;
276  month = tmp_mon;
277  day = tmp_day;
278  }
279  catch (Invalid_Argument)
280  {
281  throw Decoding_Error("EAC_Time decoding failed");
282  }
283 
284  }
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
unsigned int u32bit
Definition: types.h:32
void Botan::EAC_Time::encode_into ( class DER_Encoder to) const
virtualinherited

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 121 of file asn1_eac_tm.cpp.

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

122  {
123  der.add_object(tag, APPLICATION,
124  encoded_eac_time());
125  }
u32bit Botan::EAC_Time::get_day ( ) const
inherited

Get the day value of this objects.

Returns
day value

Definition at line 296 of file asn1_eac_tm.cpp.

297  {
298  return day;
299  }
u32bit Botan::EAC_Time::get_month ( ) const
inherited

Get the month value of this objects.

Returns
month value

Definition at line 291 of file asn1_eac_tm.cpp.

292  {
293  return month;
294  }
u32bit Botan::EAC_Time::get_year ( ) const
inherited

Get the year value of this objects.

Returns
year value

Definition at line 286 of file asn1_eac_tm.cpp.

287  {
288  return year;
289  }
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 154 of file asn1_eac_tm.cpp.

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

155  {
156  if (time_is_set() == false)
157  throw Invalid_State("EAC_Time::readable_string: No time set");
158 
159  std::string readable;
160  readable += to_string(year, 2) + "/";
161  readable += to_string(month, 2) + "/";
162  readable += to_string(day, 2) + " ";
163 
164  return readable;
165  }
bool time_is_set() const
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
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 81 of file asn1_eac_tm.cpp.

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

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

82  {
83  if (time_str == "")
84  {
85  year = month = day = 0;
86  return;
87  }
88 
89  std::vector<std::string> params;
90  std::string current;
91 
92  for (u32bit j = 0; j != time_str.size(); ++j)
93  {
94  if (Charset::is_digit(time_str[j]))
95  current += time_str[j];
96  else
97  {
98  if (current != "")
99  params.push_back(current);
100  current.clear();
101  }
102  }
103  if (current != "")
104  params.push_back(current);
105 
106  if (params.size() != 3)
107  throw Invalid_Argument("Invalid time specification " + time_str);
108 
109  year = to_u32bit(params[0]);
110  month = to_u32bit(params[1]);
111  day = to_u32bit(params[2]);
112 
113  if (!passes_sanity_check())
114  throw Invalid_Argument("Invalid time specification " + time_str);
115  }
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
bool is_digit(char c)
Definition: charset.cpp:128
u32bit to_u32bit(const std::string &number)
Definition: parsing.cpp:18
unsigned int u32bit
Definition: types.h:32
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 146 of file asn1_eac_tm.cpp.

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

147  {
148  return (year != 0);
149  }

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