encode_values.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_DER_ENCODE_VALUES_H_
  5. #define NET_DER_ENCODE_VALUES_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include "net/base/net_export.h"
  9. namespace base {
  10. class Time;
  11. }
  12. namespace net::der {
  13. struct GeneralizedTime;
  14. // Encodes |time|, a UTC-based time, to DER |generalized_time|, for comparing
  15. // against other GeneralizedTime objects.
  16. NET_EXPORT bool EncodeTimeAsGeneralizedTime(const base::Time& time,
  17. GeneralizedTime* generalized_time);
  18. // Converts a GeneralizedTime struct to a base::Time, returning true on success
  19. // or false if |generalized| was invalid or cannot be represented by
  20. // base::Time.
  21. NET_EXPORT bool GeneralizedTimeToTime(const der::GeneralizedTime& generalized,
  22. base::Time* result);
  23. static const size_t kGeneralizedTimeLength = 15;
  24. // Encodes |time| to |out| as a DER GeneralizedTime value. Returns true on
  25. // success and false on error.
  26. NET_EXPORT bool EncodeGeneralizedTime(const GeneralizedTime& time,
  27. uint8_t out[kGeneralizedTimeLength]);
  28. static const size_t kUTCTimeLength = 13;
  29. // Encodes |time| to |out| as a DER UTCTime value. Returns true on success and
  30. // false on error.
  31. NET_EXPORT bool EncodeUTCTime(const GeneralizedTime& time,
  32. uint8_t out[kUTCTimeLength]);
  33. } // namespace net::der
  34. #endif // NET_DER_ENCODE_VALUES_H_