| // Copyright 2017 Google Inc. |
| // |
| // 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 |
| // |
| // http://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 TOOLS_TESTING_CC_CLI_UTIL_H_ |
| #define TOOLS_TESTING_CC_CLI_UTIL_H_ |
| |
| #include <iostream> |
| #include <fstream> |
| |
| #include "tink/keyset_handle.h" |
| |
| // Helper function for CLI applications. |
| class CliUtil { |
| public: |
| // Returns a BinaryKeysetReader that reads from the specified file. |
| // In case of errors writes a log message and aborts. |
| static std::unique_ptr<crypto::tink::KeysetReader> GetBinaryKeysetReader( |
| const std::string& filename); |
| |
| // Returns a JsonKeysetReader that reads from the specified file. |
| // In case of errors writes a log message and aborts. |
| static std::unique_ptr<crypto::tink::KeysetReader> GetJsonKeysetReader( |
| const std::string& filename); |
| |
| // Returns a BinaryKeysetWriter that writes from the specified file. |
| // In case of errors writes a log message and aborts. |
| static std::unique_ptr<crypto::tink::KeysetWriter> GetBinaryKeysetWriter( |
| const std::string& filename); |
| |
| // Returns a JsonKeysetWriter that writes from the specified file. |
| // In case of errors writes a log message and aborts. |
| static std::unique_ptr<crypto::tink::KeysetWriter> GetJsonKeysetWriter( |
| const std::string& filename); |
| |
| // Reads a keyset from the specified file. |
| // In case of errors writes a log message and aborts. |
| static std::unique_ptr<crypto::tink::KeysetHandle> ReadKeyset( |
| const std::string& filename); |
| |
| // Initializes Tink registry. |
| // In case of errors writes a log message and aborts. |
| static void InitTink(); |
| |
| // Reads the specified file and returns the contents as a std::string. |
| // In case of errors writes a log message and aborts. |
| static std::string Read(const std::string& filename); |
| |
| // Writes the given 'output' to the specified file. |
| // In case of errors writes a log message and aborts. |
| static void Write(const std::string& output, const std::string& filename); |
| }; |
| |
| #endif // TOOLS_TESTING_CC_CLI_UTIL_H_ |