| // Copyright 2026 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| // |
| |
| #ifndef THIRD_PARTY_CREDENTIO_TSP_TIMESTAMP_PARSING_H_ |
| #define THIRD_PARTY_CREDENTIO_TSP_TIMESTAMP_PARSING_H_ |
| |
| #include <string> |
| |
| #include "absl/status/status.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/string_view.h" |
| #include "absl/time/time.h" |
| #include "crypto/algorithms.h" |
| #include "openssl/base.h" |
| |
| namespace credentio { |
| |
| // Pulls the CMS timestamp token out of TimeStampResp and checks the response's |
| // status. See RFC 3161 section 2.4.2. |
| // `timestamp_resp` must be the full DER SEQUENCE, including the header bytes. |
| // Any TSA status codes other than "granted" or "grantedWithMods" in the |
| // response's `status` field will result in INVALID_ARGUMENT (as will any DER |
| // parsing errors). |
| absl::StatusOr<absl::string_view> ParseTimestampResp( |
| absl::string_view timestamp_resp); |
| |
| // Extracts the `messageImprint`, `genTime`, and `nonce` values from a `TSTInfo` |
| // DER sequence, defined by RFC 3161. The array backing `cbs` will not be |
| // modified. All errors can be treated as `timestamp.malformed`. If the TSTInfo |
| // does not contain a `nonce` value, the provided `nonce` string will be left |
| // empty. |
| absl::Status ParseTstInfo(CBS cbs, absl::Time* time, |
| std::string* message_imprint_hash, |
| HashAlgorithm* hash_algorithm, std::string* nonce); |
| |
| } // namespace credentio |
| |
| #endif // THIRD_PARTY_CREDENTIO_TSP_TIMESTAMP_PARSING_H_ |