• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stddef.h>
9 #include <stdint.h>
10 
11 #include <openssl/base.h>
12 
13 BSSL_NAMESPACE_BEGIN
14 namespace 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, GeneralizedTime *generalized_time);
23 
24 // Converts a GeneralizedTime struct to a posix time in seconds in |result|,
25 // returning true on success or false if |generalized| was invalid or cannot be
26 // represented as a posix time in the range from the year 0000 to 9999.
27 OPENSSL_EXPORT bool GeneralizedTimeToPosixTime(
28     const der::GeneralizedTime &generalized, int64_t *result);
29 
30 static const size_t kGeneralizedTimeLength = 15;
31 
32 // Encodes |time| to |out| as a DER GeneralizedTime value. Returns true on
33 // success and false on error.
34 OPENSSL_EXPORT bool EncodeGeneralizedTime(const GeneralizedTime &time,
35                                           uint8_t out[kGeneralizedTimeLength]);
36 
37 static const size_t kUTCTimeLength = 13;
38 
39 // Encodes |time| to |out| as a DER UTCTime value. Returns true on success and
40 // false on error.
41 OPENSSL_EXPORT bool EncodeUTCTime(const GeneralizedTime &time,
42                                   uint8_t out[kUTCTimeLength]);
43 
44 }  // namespace der
45 BSSL_NAMESPACE_END
46 
47 #endif  // BSSL_DER_ENCODE_VALUES_H_
48