1 // Copyright 2016 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 BSSL_DER_ENCODE_VALUES_H_ 6 #define BSSL_DER_ENCODE_VALUES_H_ 7 8 #include "fillins/openssl_util.h" 9 #include <stddef.h> 10 #include <stdint.h> 11 12 13 14 namespace bssl::der { 15 16 struct GeneralizedTime; 17 18 // Encodes |posix_time|, a posix time in seconds, to DER |generalized_time|, for 19 // comparing against other GeneralizedTime objects, returning true on success or 20 // false if |posix_time| is outside of the range from year 0000 to 9999. 21 OPENSSL_EXPORT bool EncodePosixTimeAsGeneralizedTime( 22 int64_t posix_time, 23 GeneralizedTime* generalized_time); 24 25 // Converts a GeneralizedTime struct to a posix time in seconds in |result|, 26 // returning true on success or false if |generalized| was invalid or cannot be 27 // represented as a posix time in the range from the year 0000 to 9999. 28 OPENSSL_EXPORT bool GeneralizedTimeToPosixTime( 29 const der::GeneralizedTime& generalized, 30 int64_t* result); 31 32 static const size_t kGeneralizedTimeLength = 15; 33 34 // Encodes |time| to |out| as a DER GeneralizedTime value. Returns true on 35 // success and false on error. 36 OPENSSL_EXPORT bool EncodeGeneralizedTime(const GeneralizedTime& time, 37 uint8_t out[kGeneralizedTimeLength]); 38 39 static const size_t kUTCTimeLength = 13; 40 41 // Encodes |time| to |out| as a DER UTCTime value. Returns true on success and 42 // false on error. 43 OPENSSL_EXPORT bool EncodeUTCTime(const GeneralizedTime& time, 44 uint8_t out[kUTCTimeLength]); 45 46 } // namespace bssl::der 47 48 #endif // BSSL_DER_ENCODE_VALUES_H_ 49