/src/botan/build/include/botan/asn1_time.h
Line | Count | Source |
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 | 59.4k | 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 | | /// Return time since epoch |
53 | | uint64_t time_since_epoch() const; |
54 | | |
55 | | private: |
56 | | void set_to(const std::string& t_spec, ASN1_Tag); |
57 | | bool passes_sanity_check() const; |
58 | | |
59 | | uint32_t m_year = 0; |
60 | | uint32_t m_month = 0; |
61 | | uint32_t m_day = 0; |
62 | | uint32_t m_hour = 0; |
63 | | uint32_t m_minute = 0; |
64 | | uint32_t m_second = 0; |
65 | | ASN1_Tag m_tag = NO_OBJECT; |
66 | | }; |
67 | | |
68 | | /* |
69 | | * Comparison Operations |
70 | | */ |
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 | | bool BOTAN_PUBLIC_API(2,0) operator>=(const X509_Time&, const X509_Time&); |
75 | | bool BOTAN_PUBLIC_API(2,0) operator<(const X509_Time&, const X509_Time&); |
76 | | bool BOTAN_PUBLIC_API(2,0) operator>(const X509_Time&, const X509_Time&); |
77 | | |
78 | | typedef X509_Time ASN1_Time; |
79 | | |
80 | | } |
81 | | |
82 | | #endif |