1*e7b1675dSTing-Kang Chang // Copyright 2020 Google LLC 2*e7b1675dSTing-Kang Chang // 3*e7b1675dSTing-Kang Chang // Licensed under the Apache License, Version 2.0 (the "License"); 4*e7b1675dSTing-Kang Chang // you may not use this file except in compliance with the License. 5*e7b1675dSTing-Kang Chang // You may obtain a copy of the License at 6*e7b1675dSTing-Kang Chang // 7*e7b1675dSTing-Kang Chang // http://www.apache.org/licenses/LICENSE-2.0 8*e7b1675dSTing-Kang Chang // 9*e7b1675dSTing-Kang Chang // Unless required by applicable law or agreed to in writing, software 10*e7b1675dSTing-Kang Chang // distributed under the License is distributed on an "AS IS" BASIS, 11*e7b1675dSTing-Kang Chang // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*e7b1675dSTing-Kang Chang // See the License for the specific language governing permissions and 13*e7b1675dSTing-Kang Chang // limitations under the License. 14*e7b1675dSTing-Kang Chang // 15*e7b1675dSTing-Kang Chang /////////////////////////////////////////////////////////////////////////////// 16*e7b1675dSTing-Kang Chang 17*e7b1675dSTing-Kang Chang #ifndef TINK_TESTING_KEYSET_IMPL_H_ 18*e7b1675dSTing-Kang Chang #define TINK_TESTING_KEYSET_IMPL_H_ 19*e7b1675dSTing-Kang Chang 20*e7b1675dSTing-Kang Chang #include <grpcpp/grpcpp.h> 21*e7b1675dSTing-Kang Chang #include <grpcpp/server_context.h> 22*e7b1675dSTing-Kang Chang #include <grpcpp/support/status.h> 23*e7b1675dSTing-Kang Chang 24*e7b1675dSTing-Kang Chang #include <string> 25*e7b1675dSTing-Kang Chang 26*e7b1675dSTing-Kang Chang #include "absl/container/flat_hash_map.h" 27*e7b1675dSTing-Kang Chang #include "proto/tink.pb.h" 28*e7b1675dSTing-Kang Chang #include "proto/testing_api.grpc.pb.h" 29*e7b1675dSTing-Kang Chang 30*e7b1675dSTing-Kang Chang namespace tink_testing_api { 31*e7b1675dSTing-Kang Chang 32*e7b1675dSTing-Kang Chang // A Keyset Service. 33*e7b1675dSTing-Kang Chang class KeysetImpl final : public Keyset::Service { 34*e7b1675dSTing-Kang Chang public: 35*e7b1675dSTing-Kang Chang // Returns the key template for the given template name. 36*e7b1675dSTing-Kang Chang grpc::Status GetTemplate(grpc::ServerContext* context, 37*e7b1675dSTing-Kang Chang const KeysetTemplateRequest* request, 38*e7b1675dSTing-Kang Chang KeysetTemplateResponse* response) override; 39*e7b1675dSTing-Kang Chang 40*e7b1675dSTing-Kang Chang // Generates a new keyset with one key from a template. 41*e7b1675dSTing-Kang Chang grpc::Status Generate(grpc::ServerContext* context, 42*e7b1675dSTing-Kang Chang const KeysetGenerateRequest* request, 43*e7b1675dSTing-Kang Chang KeysetGenerateResponse* response) override; 44*e7b1675dSTing-Kang Chang 45*e7b1675dSTing-Kang Chang // Returns a public keyset for a given private keyset. 46*e7b1675dSTing-Kang Chang grpc::Status Public(grpc::ServerContext* context, 47*e7b1675dSTing-Kang Chang const KeysetPublicRequest* request, 48*e7b1675dSTing-Kang Chang KeysetPublicResponse* response) override; 49*e7b1675dSTing-Kang Chang 50*e7b1675dSTing-Kang Chang // Converts a keyset from binary to JSON format. 51*e7b1675dSTing-Kang Chang grpc::Status ToJson(grpc::ServerContext* context, 52*e7b1675dSTing-Kang Chang const KeysetToJsonRequest* request, 53*e7b1675dSTing-Kang Chang KeysetToJsonResponse* response) override; 54*e7b1675dSTing-Kang Chang 55*e7b1675dSTing-Kang Chang // Converts a keyset from JSON to binary format. 56*e7b1675dSTing-Kang Chang grpc::Status FromJson(grpc::ServerContext* context, 57*e7b1675dSTing-Kang Chang const KeysetFromJsonRequest* request, 58*e7b1675dSTing-Kang Chang KeysetFromJsonResponse* response) override; 59*e7b1675dSTing-Kang Chang 60*e7b1675dSTing-Kang Chang // Writes an encrypted keyset. 61*e7b1675dSTing-Kang Chang grpc::Status WriteEncrypted(grpc::ServerContext* context, 62*e7b1675dSTing-Kang Chang const KeysetWriteEncryptedRequest* request, 63*e7b1675dSTing-Kang Chang KeysetWriteEncryptedResponse* response) override; 64*e7b1675dSTing-Kang Chang 65*e7b1675dSTing-Kang Chang // Reads an encrypted keyset. 66*e7b1675dSTing-Kang Chang grpc::Status ReadEncrypted(grpc::ServerContext* context, 67*e7b1675dSTing-Kang Chang const KeysetReadEncryptedRequest* request, 68*e7b1675dSTing-Kang Chang KeysetReadEncryptedResponse* response) override; 69*e7b1675dSTing-Kang Chang KeysetImpl(); 70*e7b1675dSTing-Kang Chang 71*e7b1675dSTing-Kang Chang private: 72*e7b1675dSTing-Kang Chang absl::flat_hash_map<std::string, google::crypto::tink::KeyTemplate> 73*e7b1675dSTing-Kang Chang key_templates_; 74*e7b1675dSTing-Kang Chang }; 75*e7b1675dSTing-Kang Chang 76*e7b1675dSTing-Kang Chang } // namespace tink_testing_api 77*e7b1675dSTing-Kang Chang 78*e7b1675dSTing-Kang Chang #endif // TINK_TESTING_KEYSET_IMPL_H_ 79