1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://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 /////////////////////////////////////////////////////////////////////////////// 16 #ifndef TINK_EXAMPLES_UTIL_UTIL_H_ 17 #define TINK_EXAMPLES_UTIL_UTIL_H_ 18 19 #include <memory> 20 #include <string> 21 22 #include "tink/keyset_handle.h" 23 #include "tink/util/status.h" 24 #include "tink/util/statusor.h" 25 26 namespace tink_cc_examples { 27 28 // Reads a keyset from the given file `filename` which is expected to contain a 29 // JSON-formatted keyset. 30 crypto::tink::util::StatusOr<std::unique_ptr<crypto::tink::KeysetHandle>> 31 ReadJsonCleartextKeyset(const std::string& filename); 32 33 // Writes `keyset_handle` to the file `filename` formatted with JSON in 34 // cleartext. 35 crypto::tink::util::Status WriteJsonCleartextKeyset( 36 const std::string& filename, 37 const crypto::tink::KeysetHandle& keyset_handle); 38 39 // Reads `filename` and returns the read content as a string, or an error status 40 // if the file does not exist. 41 crypto::tink::util::StatusOr<std::string> ReadFile(const std::string& filename); 42 43 // Writes the given `data_to_write` to the specified file `filename`. 44 crypto::tink::util::Status WriteToFile(const std::string& data_to_write, 45 const std::string& filename); 46 47 } // namespace tink_cc_examples 48 49 #endif // TINK_EXAMPLES_UTIL_UTIL_H_ 50