Coverage Report

Created: 2026-05-16 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/build/include/public/botan/asn1_time.h
Line
Count
Source
1
/*
2
* (C) 1999-2007,2018,2020,2026 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#ifndef BOTAN_ASN1_TIME_TYPE_H_
8
#define BOTAN_ASN1_TIME_TYPE_H_
9
10
#include <botan/asn1_obj.h>
11
#include <chrono>
12
13
namespace Botan {
14
15
/**
16
* Time (GeneralizedTime/UniversalTime)
17
*/
18
class BOTAN_PUBLIC_API(2, 0) ASN1_Time final : public ASN1_Object {
19
   public:
20
      /// DER encode a ASN1_Time
21
      void encode_into(DER_Encoder& to) const override;
22
23
      // Decode a BER encoded ASN1_Time
24
      void decode_from(BER_Decoder& from) override;
25
26
      /// Return an internal string representation of the time
27
      std::string to_string() const;
28
29
      /// Returns a human friendly string representation of no particular formatting
30
      std::string readable_string() const;
31
32
      /// Return if the time has been set somehow
33
      bool time_is_set() const;
34
35
      ///  Compare this time against another
36
      int32_t cmp(const ASN1_Time& other) const;
37
38
      /// Create an invalid ASN1_Time
39
77.8k
      ASN1_Time() = default;
40
41
      /// Create a ASN1_Time from a time point
42
      explicit ASN1_Time(const std::chrono::system_clock::time_point& time);
43
44
      /// Create an ASN1_Time from seconds since epoch
45
      static ASN1_Time from_seconds_since_epoch(uint64_t seconds);
46
47
      /// Create an ASN1_Time from string
48
      BOTAN_FUTURE_EXPLICIT ASN1_Time(std::string_view t_spec);
49
50
      /// Create an ASN1_Time from string and a specified tagging (Utc or Generalized)
51
      ASN1_Time(std::string_view t_spec, ASN1_Type tag);
52
53
      /// Returns a STL timepoint object
54
      std::chrono::system_clock::time_point to_std_timepoint() const;
55
56
      /// Return time since epoch
57
      uint64_t time_since_epoch() const;
58
59
   private:
60
      void set_to(std::string_view t_spec, ASN1_Type type);
61
      bool passes_sanity_check() const;
62
63
      uint32_t m_year = 0;
64
      uint32_t m_month = 0;
65
      uint32_t m_day = 0;
66
      uint32_t m_hour = 0;
67
      uint32_t m_minute = 0;
68
      uint32_t m_second = 0;
69
      ASN1_Type m_tag = ASN1_Type::NoObject;
70
};
71
72
/*
73
* Comparison Operations
74
*/
75
BOTAN_PUBLIC_API(2, 0) bool operator==(const ASN1_Time& x, const ASN1_Time& y);
76
BOTAN_PUBLIC_API(2, 0) bool operator!=(const ASN1_Time& x, const ASN1_Time& y);
77
BOTAN_PUBLIC_API(2, 0) bool operator<=(const ASN1_Time& x, const ASN1_Time& y);
78
BOTAN_PUBLIC_API(2, 0) bool operator>=(const ASN1_Time& x, const ASN1_Time& y);
79
BOTAN_PUBLIC_API(2, 0) bool operator<(const ASN1_Time& x, const ASN1_Time& y);
80
BOTAN_PUBLIC_API(2, 0) bool operator>(const ASN1_Time& x, const ASN1_Time& y);
81
82
}  // namespace Botan
83
84
#endif