Botan  1.10.9
eac_asn_obj.h
Go to the documentation of this file.
1 /*
2 * EAC ASN.1 Objects
3 * (C) 2007-2008 FlexSecure GmbH
4 * 2008-2010 Jack Lloyd
5 *
6 * Distributed under the terms of the Botan license
7 */
8 
9 #ifndef BOTAN_EAC_ASN1_OBJ_H__
10 #define BOTAN_EAC_ASN1_OBJ_H__
11 
12 #include <botan/asn1_obj.h>
13 
14 namespace Botan {
15 
16 /**
17 * This class represents CVC EAC Time objects.
18 * It only models year, month and day. Only limited sanity checks of
19 * the inputted date value are performed.
20 */
21 class BOTAN_DLL EAC_Time : public ASN1_Object
22  {
23  public:
24  void encode_into(class DER_Encoder&) const;
25  void decode_from(class BER_Decoder&);
26 
27  /**
28  * Get a this objects value as a string.
29  * @return date string
30  */
31  std::string as_string() const;
32 
33  /**
34  * Get a this objects value as a readable formatted string.
35  * @return date string
36  */
37  std::string readable_string() const;
38 
39  /**
40  * Find out whether this object's values have been set.
41  * @return true if this object's internal values are set
42  */
43  bool time_is_set() const;
44 
45  /**
46  * Compare this to another EAC_Time object.
47  * @return -1 if this object's date is earlier than
48  * other, +1 in the opposite case, and 0 if both dates are
49  * equal.
50  */
51  s32bit cmp(const EAC_Time& other) const;
52 
53  /**
54  * Set this' value by a string value.
55  * @param str a string in the format "yyyy mm dd",
56  * e.g. "2007 08 01"
57  */
58  void set_to(const std::string& str);
59  //void set_to(const std::string&, ASN1_Tag);
60 
61  /**
62  * Add the specified number of years to this.
63  * @param years the number of years to add
64  */
65  void add_years(u32bit years);
66 
67  /**
68  * Add the specified number of months to this.
69  * @param months the number of months to add
70  */
71  void add_months(u32bit months);
72 
73  /**
74  * Get the year value of this objects.
75  * @return year value
76  */
77  u32bit get_year() const;
78 
79  /**
80  * Get the month value of this objects.
81  * @return month value
82  */
83  u32bit get_month() const;
84 
85  /**
86  * Get the day value of this objects.
87  * @return day value
88  */
89  u32bit get_day() const;
90 
92  //EAC_Time(const std::string& = "");
93  EAC_Time(const std::string&, ASN1_Tag = ASN1_Tag(0));
94  EAC_Time(u32bit year, u32bit month, u32bit day, ASN1_Tag = ASN1_Tag(0));
95 
96  virtual ~EAC_Time() {}
97  private:
98  SecureVector<byte> encoded_eac_time() const;
99  bool passes_sanity_check() const;
100  u32bit year, month, day;
101  ASN1_Tag tag;
102  };
103 
104 /**
105 * This class represents CVC CEDs. Only limited sanity checks of
106 * the inputted date value are performed.
107 */
108 class BOTAN_DLL ASN1_Ced : public EAC_Time
109  {
110  public:
111  /**
112  * Construct a CED from a string value.
113  * @param str a string in the format "yyyy mm dd",
114  * e.g. "2007 08 01"
115  */
116  ASN1_Ced(std::string const& str = "");
117 
118  /**
119  * Construct a CED from a timer value.
120  * @param time the number of seconds elapsed midnight, 1st
121  * January 1970 GMT (or 7pm, 31st December 1969 EST) up to the
122  * desired date
123  */
124  ASN1_Ced(u64bit time);
125 
126  /**
127  * Copy constructor (for general EAC_Time objects).
128  * @param other the object to copy from
129  */
130  ASN1_Ced(EAC_Time const& other);
131  //ASN1_Ced(ASN1_Cex const& cex);
132  };
133 
134 
135 /**
136 * This class represents CVC CEXs. Only limited sanity checks of
137 * the inputted date value are performed.
138 */
139 class BOTAN_DLL ASN1_Cex : public EAC_Time
140  {
141  public:
142  /**
143  * Construct a CED from a string value.
144  * @param str a string in the format "yyyy mm dd",
145  * e.g. "2007 08 01"
146  */
147  ASN1_Cex(std::string const& str="");
148 
149  /**
150  * Construct a CED from a timer value.
151  * @param time the number of seconds elapsed
152  * midnight, 1st
153  * January 1970 GMT (or 7pm, 31st December 1969 EST)
154  * up to the desired date
155  */
156  ASN1_Cex(u64bit time);
157 
158  /**
159  * Copy constructor (for general EAC_Time objects).
160  * @param other the object to copy from
161  */
162  ASN1_Cex(EAC_Time const& other);
163  //ASN1_Cex(ASN1_Ced const& ced);
164  };
165 
166 /**
167 * Base class for car/chr of cv certificates.
168 */
169 class BOTAN_DLL ASN1_EAC_String: public ASN1_Object
170  {
171  public:
172  void encode_into(class DER_Encoder&) const;
173  void decode_from(class BER_Decoder&);
174 
175  /**
176  * Get this objects string value.
177  * @return string value
178  */
179  std::string value() const;
180 
181  /**
182  * Get this objects string value.
183  * @return string value in iso8859 encoding
184  */
185  std::string iso_8859() const;
186 
187  ASN1_Tag tagging() const;
188  ASN1_EAC_String(const std::string& str, ASN1_Tag the_tag);
189 
190  virtual ~ASN1_EAC_String() {}
191  protected:
192  bool sanity_check() const;
193  private:
194  std::string iso_8859_str;
195  ASN1_Tag tag;
196  };
197 
198 /**
199 * This class represents CARs of CVCs. (String tagged with 2)
200 */
201 class BOTAN_DLL ASN1_Car : public ASN1_EAC_String
202  {
203  public:
204  /**
205  * Create a CAR with the specified content.
206  * @param str the CAR value
207  */
208  ASN1_Car(std::string const& str = "");
209  };
210 
211 /**
212 * This class represents CHRs of CVCs (tag 32)
213 */
214 class BOTAN_DLL ASN1_Chr : public ASN1_EAC_String
215  {
216  public:
217  /**
218  * Create a CHR with the specified content.
219  * @param str the CHR value
220  */
221  ASN1_Chr(std::string const& str = "");
222  };
223 
224 /*
225 * Comparison Operations
226 */
227 bool BOTAN_DLL operator==(const EAC_Time&, const EAC_Time&);
228 bool BOTAN_DLL operator!=(const EAC_Time&, const EAC_Time&);
229 bool BOTAN_DLL operator<=(const EAC_Time&, const EAC_Time&);
230 bool BOTAN_DLL operator>=(const EAC_Time&, const EAC_Time&);
231 bool BOTAN_DLL operator>(const EAC_Time&, const EAC_Time&);
232 bool BOTAN_DLL operator<(const EAC_Time&, const EAC_Time&);
233 
234 bool BOTAN_DLL operator==(const ASN1_EAC_String&, const ASN1_EAC_String&);
235 inline bool operator!=(const ASN1_EAC_String& lhs, const ASN1_EAC_String& rhs)
236  {
237  return !(lhs == rhs);
238  }
239 
240 }
241 
242 #endif
bool operator!=(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:106
bool BOTAN_DLL operator>=(const X509_Time &, const X509_Time &)
Definition: asn1_tm.cpp:283
bool operator==(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:98
signed int s32bit
Definition: types.h:37
unsigned long long u64bit
Definition: types.h:49
virtual ~ASN1_EAC_String()
Definition: eac_asn_obj.h:190
bool BOTAN_DLL operator>(const X509_Time &, const X509_Time &)
Definition: asn1_tm.cpp:288
ASN1_Tag
Definition: asn1_int.h:19
bool BOTAN_DLL operator<(const X509_Time &, const X509_Time &)
Definition: asn1_tm.cpp:286
virtual ~EAC_Time()
Definition: eac_asn_obj.h:96
bool BOTAN_DLL operator<=(const X509_Time &, const X509_Time &)
Definition: asn1_tm.cpp:281
unsigned int u32bit
Definition: types.h:32