1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_CERT_TIME_CONVERSIONS_H_ 6 #define NET_CERT_TIME_CONVERSIONS_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include "net/base/net_export.h" 12 #include "third_party/boringssl/src/pki/encode_values.h" 13 14 namespace base { 15 class Time; 16 } 17 18 namespace bssl { 19 namespace der { 20 struct GeneralizedTime; 21 } // namespace der 22 } // namespace bssl 23 24 namespace net { 25 26 // Encodes |time|, a UTC-based time, to DER |generalized_time|, for comparing 27 // against other GeneralizedTime objects. Returns true on success or false if 28 // the time is not representable as a Generalized time.The millisecond component 29 // of |time| is discarded. 30 NET_EXPORT bool EncodeTimeAsGeneralizedTime( 31 const base::Time& time, 32 bssl::der::GeneralizedTime* generalized_time); 33 34 // Converts a GeneralizedTime struct to a base::Time, returning true on success 35 // or false if |generalized| was invalid. 36 NET_EXPORT bool GeneralizedTimeToTime( 37 const bssl::der::GeneralizedTime& generalized, 38 base::Time* result); 39 40 } // namespace net 41 42 #endif // NET_CERT_TIME_CONVERSIONS_H_ 43