Botan  2.7.0
Crypto and TLS for C++11
asn1_time.h
Go to the documentation of this file.
1 /*
2 * ASN.1 Time Representation
3 * (C) 1999-2007,2012 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_ASN1_TIME_H_
9 #define BOTAN_ASN1_TIME_H_
10 
11 #include <botan/asn1_obj.h>
12 #include <chrono>
13 
14 namespace Botan {
15 
16 /**
17 * X.509 Time
18 */
19 class BOTAN_PUBLIC_API(2,0) X509_Time final : public ASN1_Object
20  {
21  public:
22  /// DER encode a X509_Time
23  void encode_into(DER_Encoder&) const override;
24 
25  // Decode a BER encoded X509_Time
26  void decode_from(BER_Decoder&) override;
27 
28  /// Return an internal string representation of the time
29  std::string to_string() const;
30 
31  /// Returns a human friendly string replesentation of no particular formatting
32  std::string readable_string() const;
33 
34  /// Return if the time has been set somehow
35  bool time_is_set() const;
36 
37  /// Compare this time against another
38  int32_t cmp(const X509_Time& other) const;
39 
40  /// Create an invalid X509_Time
41  X509_Time() = default;
42 
43  /// Create a X509_Time from a time point
44  explicit X509_Time(const std::chrono::system_clock::time_point& time);
45 
46  /// Create an X509_Time from string
47  X509_Time(const std::string& t_spec, ASN1_Tag tag);
48 
49  /// Returns a STL timepoint object
50  std::chrono::system_clock::time_point to_std_timepoint() const;
51 
52  private:
53  void set_to(const std::string& t_spec, ASN1_Tag);
54  bool passes_sanity_check() const;
55 
56  uint32_t m_year = 0;
57  uint32_t m_month = 0;
58  uint32_t m_day = 0;
59  uint32_t m_hour = 0;
60  uint32_t m_minute = 0;
61  uint32_t m_second = 0;
62  ASN1_Tag m_tag = NO_OBJECT;
63  };
64 
65 /*
66 * Comparison Operations
67 */
68 bool BOTAN_PUBLIC_API(2,0) operator==(const X509_Time&, const X509_Time&);
69 bool BOTAN_PUBLIC_API(2,0) operator!=(const X509_Time&, const X509_Time&);
70 bool BOTAN_PUBLIC_API(2,0) operator<=(const X509_Time&, const X509_Time&);
71 bool BOTAN_PUBLIC_API(2,0) operator>=(const X509_Time&, const X509_Time&);
72 bool BOTAN_PUBLIC_API(2,0) operator<(const X509_Time&, const X509_Time&);
73 bool BOTAN_PUBLIC_API(2,0) operator>(const X509_Time&, const X509_Time&);
74 
76 
77 }
78 
79 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
ASN1_Tag
Definition: asn1_obj.h:22
Definition: alg_id.cpp:13
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25