| // 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_BINDINGS_INPUT_HASHER_H_ | |
| #define THIRD_PARTY_CREDENTIO_BINDINGS_INPUT_HASHER_H_ | |
| #include <stdint.h> | |
| #include <memory> | |
| #include <string> | |
| #include "absl/base/nullability.h" | |
| #include "absl/status/status.h" | |
| #include "absl/status/statusor.h" | |
| #include "absl/strings/string_view.h" | |
| #include "crypto/algorithms.h" | |
| #include "crypto/hash.h" | |
| #include "riegeli/bytes/reader.h" | |
| namespace credentio { | |
| // A simple hasher for C2PA hash computing. | |
| class InputHasher { | |
| public: | |
| virtual ~InputHasher() = default; | |
| // Reads `length` bytes from `input` starting at `offset` and updates the | |
| // hash. | |
| virtual absl::Status Update(riegeli::Reader& input, uint64_t offset, | |
| uint64_t length) = 0; | |
| // Updates the hash with `data`. | |
| virtual void Update(absl::string_view data) = 0; | |
| // Returns the hash digest. | |
| virtual std::string Digest() = 0; | |
| static absl::StatusOr<std::unique_ptr<InputHasher> absl_nonnull> Create( | |
| absl::string_view alg); | |
| static absl::StatusOr<std::unique_ptr<InputHasher> absl_nonnull> Create( | |
| HashAlgorithm alg); | |
| static absl::StatusOr<std::unique_ptr<InputHasher>> Create( | |
| std::unique_ptr<Hasher> absl_nonnull hasher); | |
| }; | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_BINDINGS_INPUT_HASHER_H_ |