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 net { 19 20 struct GeneralizedTime; 21 22 // Encodes |time|, a UTC-based time, to DER |generalized_time|, for comparing 23 // against other GeneralizedTime objects. Returns true on success or false if 24 // the time is not representable as a Generalized time.The millisecond component 25 // of |time| is discarded. 26 NET_EXPORT bool EncodeTimeAsGeneralizedTime( 27 const base::Time& time, 28 bssl::der::GeneralizedTime* generalized_time); 29 30 // Converts a GeneralizedTime struct to a base::Time, returning true on success 31 // or false if |generalized| was invalid. 32 NET_EXPORT bool GeneralizedTimeToTime( 33 const bssl::der::GeneralizedTime& generalized, 34 base::Time* result); 35 36 } // namespace net 37 38 #endif // NET_CERT_TIME_CONVERSIONS_H_ 39