Botan: Botan::EAC_Time Class Reference

Botan 1.10.16

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

`#include <eac_asn_obj.h>`

Inheritance diagram for Botan::EAC_Time:

## 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 (u64bit, ASN1_Tag t=ASN1_Tag(0))
| EAC_Time (const std::string &, ASN1_Tag=ASN1_Tag(0))
| EAC_Time (u32bit year, u32bit month, u32bit day, ASN1_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 21 of file eac_asn_obj.h.

## Constructor & Destructor Documentation

## ◆ EAC_Time() [1/3]

Botan::EAC_Time::EAC_Time | ( | u64bit | timer,
|  | ASN1_Tag | t = `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.

54 : tag(t)
55 {
56 calendar_point cal = calendar_value(timer);
57
58 year = cal.year;
59 month = cal.month;
60 day = cal.day;
61 }
Botan::calendar_value
calendar_point calendar_value(u64bit a_time_t)
Definition: time.cpp:81

## ◆ EAC_Time() [2/3]

Botan::EAC_Time::EAC_Time | ( | const std::string & | t_spec,
|  | ASN1_Tag | t = `ASN1_Tag(0)`
| ) |  |

Definition at line 66 of file asn1_eac_tm.cpp.

References set_to().

66 : tag(t)
67 {
68 set_to(t_spec);
69 }
Botan::EAC_Time::set_to
void set_to(const std::string &str)
Definition: asn1_eac_tm.cpp:81

## ◆ EAC_Time() [3/3]

Botan::EAC_Time::EAC_Time | ( | u32bit | year,
|  | u32bit | month,
|  | u32bit | day,
|  | ASN1_Tag | t = `ASN1_Tag(0)`
| ) |  |

Definition at line 73 of file asn1_eac_tm.cpp.

73 :
74 year(y), month(m), day(d), tag(t)
75 {
76 }

## ◆ ~EAC_Time()

virtual Botan::EAC_Time::~EAC_Time | ( |  | ) |
| inlinevirtual

Definition at line 96 of file eac_asn_obj.h.

96 {}

## Member Function Documentation

## ◆ add_months()

void Botan::EAC_Time::add_months | ( | u32bit | months | ) |

Add the specified number of months to this.

Parameters

  months | the number of months to add

Definition at line 190 of file asn1_eac_tm.cpp.

191 {
192 year += months/12;
193 month += months % 12;
194 if(month > 12)
195 {
196 year += 1;
197 month -= 12;
198 }
199 }

## ◆ add_years()

void Botan::EAC_Time::add_years | ( | u32bit | years | ) |

Add the specified number of years to this.

Parameters

  years | the number of years to add

Definition at line 186 of file asn1_eac_tm.cpp.

187 {
188 year += years;
189 }

## ◆ as_string()

std::string Botan::EAC_Time::as_string | ( |  | ) | const

Get a this objects value as a string.

Returns
  date string

Definition at line 130 of file asn1_eac_tm.cpp.

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

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 }
Botan::EAC_Time::time_is_set
bool time_is_set() const
Definition: asn1_eac_tm.cpp:146
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42

## ◆ cmp()

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 205 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>=().

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 }
Botan::s32bit
signed int s32bit
Definition: types.h:37
Botan::EAC_Time::time_is_set
bool time_is_set() const
Definition: asn1_eac_tm.cpp:146

## ◆ decode_from()

void Botan::EAC_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 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 }
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::u32bit
unsigned int u32bit
Definition: types.h:32

## ◆ encode_into()

void Botan::EAC_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 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 }
Botan::APPLICATION
Definition: asn1_int.h:21

## ◆ get_day()

u32bit Botan::EAC_Time::get_day | ( |  | ) | const

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 }

## ◆ get_month()

u32bit Botan::EAC_Time::get_month | ( |  | ) | const

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 }

## ◆ get_year()

u32bit Botan::EAC_Time::get_year | ( |  | ) | const

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 }

## ◆ readable_string()

std::string Botan::EAC_Time::readable_string | ( |  | ) | const

Get a this objects value as a readable formatted string.

Returns
  date string

Definition at line 154 of file asn1_eac_tm.cpp.

References 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 }
Botan::EAC_Time::time_is_set
bool time_is_set() const
Definition: asn1_eac_tm.cpp:146
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42

## ◆ set_to()

void Botan::EAC_Time::set_to | ( | const std::string & | str | ) |

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

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

Referenced by 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 }
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::Charset::is_digit
bool is_digit(char c)
Definition: charset.cpp:128
Botan::to_u32bit
u32bit to_u32bit(const std::string &number)
Definition: parsing.cpp:18
Botan::u32bit
unsigned int u32bit
Definition: types.h:32

## ◆ time_is_set()

bool Botan::EAC_Time::time_is_set | ( |  | ) | const

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 as_string(), cmp(), and readable_string().

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

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

- src/cert/cvc/eac_asn_obj.h
- src/cert/cvc/asn1_eac_tm.cpp