1 // Copyright 2021 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 17 #ifndef TINK_HYBRID_INTERNAL_HPKE_PUBLIC_KEY_MANAGER_H_ 18 #define TINK_HYBRID_INTERNAL_HPKE_PUBLIC_KEY_MANAGER_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "absl/memory/memory.h" 24 #include "absl/strings/str_cat.h" 25 #include "tink/core/key_type_manager.h" 26 #include "tink/hybrid/internal/hpke_encrypt.h" 27 #include "tink/hybrid_encrypt.h" 28 #include "tink/key_manager.h" 29 #include "tink/util/constants.h" 30 #include "tink/util/errors.h" 31 #include "tink/util/protobuf_helper.h" 32 #include "tink/util/status.h" 33 #include "tink/util/statusor.h" 34 #include "proto/hpke.pb.h" 35 #include "proto/tink.pb.h" 36 37 namespace crypto { 38 namespace tink { 39 namespace internal { 40 41 class HpkePublicKeyManager 42 : public KeyTypeManager<google::crypto::tink::HpkePublicKey, void, 43 List<HybridEncrypt>> { 44 public: 45 class HybridEncryptFactory : public PrimitiveFactory<HybridEncrypt> { Create(const google::crypto::tink::HpkePublicKey & public_key)46 crypto::tink::util::StatusOr<std::unique_ptr<HybridEncrypt>> Create( 47 const google::crypto::tink::HpkePublicKey& public_key) const override { 48 return HpkeEncrypt::New(public_key); 49 } 50 }; 51 HpkePublicKeyManager()52 HpkePublicKeyManager() 53 : KeyTypeManager(absl::make_unique<HybridEncryptFactory>()) {} 54 get_version()55 uint32_t get_version() const override { return 0; } 56 key_material_type()57 google::crypto::tink::KeyData::KeyMaterialType key_material_type() 58 const override { 59 return google::crypto::tink::KeyData::ASYMMETRIC_PUBLIC; 60 } 61 get_key_type()62 const std::string& get_key_type() const override { return key_type_; } 63 64 crypto::tink::util::Status ValidateKey( 65 const google::crypto::tink::HpkePublicKey& key) const override; 66 67 private: 68 const std::string key_type_ = absl::StrCat( 69 kTypeGoogleapisCom, google::crypto::tink::HpkePublicKey().GetTypeName()); 70 }; 71 72 } // namespace internal 73 } // namespace tink 74 } // namespace crypto 75 76 #endif // TINK_HYBRID_INTERNAL_HPKE_PUBLIC_KEY_MANAGER_H_ 77