| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef BSSL_DER_ENCODE_VALUES_H_ |
| 16 | #define BSSL_DER_ENCODE_VALUES_H_ |
| 17 |
| 18 | #include <stddef.h> |
| 19 | #include <stdint.h> |
| 20 |
| 21 | #include <openssl/base.h> |
| 22 |
| 23 | BSSL_NAMESPACE_BEGIN |
| 24 | namespace der { |
| 25 |
| 26 | struct GeneralizedTime; |
| 27 |
| 28 | // Encodes |posix_time|, a posix time in seconds, to DER |generalized_time|, for |
| 29 | // comparing against other GeneralizedTime objects, returning true on success or |
| 30 | // false if |posix_time| is outside of the range from year 0000 to 9999. |
| 31 | OPENSSL_EXPORT bool EncodePosixTimeAsGeneralizedTime( |
| 32 | int64_t posix_time, GeneralizedTime *generalized_time); |
| 33 |
| 34 | // Converts a GeneralizedTime struct to a posix time in seconds in |result|, |
| 35 | // returning true on success or false if |generalized| was invalid or cannot be |
| 36 | // represented as a posix time in the range from the year 0000 to 9999. |
| 37 | OPENSSL_EXPORT bool GeneralizedTimeToPosixTime( |
| 38 | const der::GeneralizedTime &generalized, int64_t *result); |
| 39 |
| 40 | static const size_t kGeneralizedTimeLength = 15; |
| 41 |
| 42 | // Encodes |time| to |out| as a DER GeneralizedTime value. Returns true on |
| 43 | // success and false on error. |
| 44 | OPENSSL_EXPORT bool EncodeGeneralizedTime(const GeneralizedTime &time, |
| 45 | uint8_t out[kGeneralizedTimeLength]); |
| 46 |
| 47 | static const size_t kUTCTimeLength = 13; |
| 48 |
| 49 | // Encodes |time| to |out| as a DER UTCTime value. Returns true on success and |
| 50 | // false on error. |
| 51 | OPENSSL_EXPORT bool EncodeUTCTime(const GeneralizedTime &time, |
| 52 | uint8_t out[kUTCTimeLength]); |
| 53 |
| 54 | } // namespace der |
| 55 | BSSL_NAMESPACE_END |
| 56 |
| 57 | #endif // BSSL_DER_ENCODE_VALUES_H_ |
| 58 |